From d798128e2c5302fde81ce911f1e4cfa800c1692f Mon Sep 17 00:00:00 2001 From: jay Date: Sun, 7 May 2023 10:19:41 +0800 Subject: [PATCH] update --- home/bin/executable_wgvpn | 88 ++++++++++++++++++++++++++++++ home/dot_config/hypr/hyprland.conf | 1 - home/dot_config/waybar/config | 8 +-- home/dot_zprofile.tmpl | 1 + home/dot_zsh/30_alias.zsh | 4 +- 5 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 home/bin/executable_wgvpn diff --git a/home/bin/executable_wgvpn b/home/bin/executable_wgvpn new file mode 100644 index 0000000..0f62c9c --- /dev/null +++ b/home/bin/executable_wgvpn @@ -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 [-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 : diff --git a/home/dot_config/hypr/hyprland.conf b/home/dot_config/hypr/hyprland.conf index e90deec..43ac7b2 100644 --- a/home/dot_config/hypr/hyprland.conf +++ b/home/dot_config/hypr/hyprland.conf @@ -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 diff --git a/home/dot_config/waybar/config b/home/dot_config/waybar/config index b96e36c..f637a43 100644 --- a/home/dot_config/waybar/config +++ b/home/dot_config/waybar/config @@ -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": ["", "", "", "", ""] diff --git a/home/dot_zprofile.tmpl b/home/dot_zprofile.tmpl index 606174c..02a707b 100644 --- a/home/dot_zprofile.tmpl +++ b/home/dot_zprofile.tmpl @@ -1,3 +1,4 @@ +# vim: set ft=zsh : # `$HOME/bin/start-agent` SSH_ENV="$HOME/.ssh/agent-environment" diff --git a/home/dot_zsh/30_alias.zsh b/home/dot_zsh/30_alias.zsh index b2e3c46..8a353f8 100644 --- a/home/dot_zsh/30_alias.zsh +++ b/home/dot_zsh/30_alias.zsh @@ -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"