This commit is contained in:
jay 2023-05-07 10:19:41 +08:00
parent 26df51eb9d
commit d798128e2c
5 changed files with 96 additions and 6 deletions

88
home/bin/executable_wgvpn Normal file
View File

@ -0,0 +1,88 @@
#!/bin/bash
# 檢查是否為 root user如果不是則使用 sudo 切換
if [[ $EUID -ne 0 ]]; then
exec sudo "$0" "$@"
exit
fi
# WireGuard 設定檔案資料夾
wg_conf_folder="/etc/wireguard/"
# 列出所有可使用的設定檔案
function list_conf_files() {
echo "可用的 WireGuard 設定檔案:"
ls -1 $wg_conf_folder | grep ".conf$"
}
# 連線到指定的 VPN
function connect() {
local intf=$1
# 切斷其他已連線的 VPN
if [[ $1 == "--disconnect-others" ]] || [[ $1 == "-d" ]] ; then
wg-quick down "$(wg show | grep "interface:" | awk '{print $2}')"
intf=$2
fi
# 確認設定檔案是否存在
if [[ ! -f "$wg_conf_folder/$intf.conf" ]]; then
echo "找不到 $wg_conf_folder/$intf.conf"
exit
fi
# 連線 VPN
wg-quick up "$wg_conf_folder/$intf.conf"
echo "已連線到 $intf"
}
# 斷開指定的 VPN若未指定則斷開所有 VPN
function disconnect() {
if [[ -n "$1" ]]; then
wg-quick down "$1"
echo "已斷開 $1"
else
wg-quick down "$(wg show | grep "interface:" | awk '{print $2}')"
echo "已斷開所有 VPN"
fi
}
# 列出已連線的 VPN
function list_connections() {
echo "已連線的 VPN"
wg show | grep "interface:" | awk '{print $2}'
}
# 判斷參數是否為空
if [[ -z $1 ]]; then
echo "使用方式:"
echo " $0 list - 列出所有可使用的設定檔案"
echo " $0 connect <config> [-d|--disconnect-others] - 連線到指定的 VPN"
echo " $0 disconnect [interface] - 斷開指定的 VPN若未指定則斷開所有 VPN"
echo " $0 list-connections - 列出已連線的 VPN"
exit
fi
case "$1" in
list)
list_conf_files
;;
connect)
if [[ -n $2 ]]; then
connect "$2" "$3"
else
echo "請輸入要連線的 VPN 設定檔案名稱"
fi
;;
disconnect)
disconnect "$2"
;;
list-connections)
list_connections
;;
*)
echo "無效的參數:$1"
exit
;;
esac
# vim: set ft=sh :

View File

@ -244,7 +244,6 @@ submap=reset
# set workspace default to monitor
workspace = eDP-1, 1
workspace = HDMI-A-1, 2
workspace = DP-1, 2
wsbind = 1, eDP-1
wsbind = 2, HDMI-A-1

View File

@ -101,10 +101,10 @@
"warning": 30,
"critical": 15
},
"format": "{icon} {capacity}%",
"format-charging": " {capacity}%",
"format-plugged": " {capacity}%",
"format-alt": "{icon} {time}",
"format": "{icon} {capacity}%",
"format-charging": " {capacity}%",
"format-plugged": " {capacity}%",
"format-alt": "{icon} {time}",
// "format-good": "", // An empty format will hide the module
// "format-full": "",
"format-icons": ["", "", "", "", ""]

View File

@ -1,3 +1,4 @@
# vim: set ft=zsh :
# `$HOME/bin/start-agent`
SSH_ENV="$HOME/.ssh/agent-environment"

View File

@ -7,5 +7,7 @@ alias ls="ls --color=auto"
alias wgup="sudo wg-quick up"
alias wgdown="sudo wg-quick down"
alias wgc="wgvpn connect"
alias wgd="wgvpn disconnect"
alias lg="lazygit"
alias vm-system="virt-viewer -c qemu:///system"