From d7106d28d1fa06fcc3b873db2b5b4ca0851b70e4 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Thu, 14 Jan 2021 14:47:29 +0100 Subject: [PATCH] Add vpn switching script --- .config/halia-switch.sh | 32 ++++++++++++++++++++++++++++++++ .zshrc | 2 ++ 2 files changed, 34 insertions(+) create mode 100755 .config/halia-switch.sh diff --git a/.config/halia-switch.sh b/.config/halia-switch.sh new file mode 100755 index 0000000..f78795d --- /dev/null +++ b/.config/halia-switch.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +trap "exit" INT + +printf "Checking for sudo privileges...\n"; +sudo -n true &> /dev/null; + +if [ "$?" -eq "0" ]; then + printf "Running in a session with sudo privileges, continuing\n"; +else + printf "This scripts need sudo privileges to continue\n"; + sudo ls &> /dev/null; +fi + +printf "Checking for current VPN configuration...\n"; +ip addr show halia &> /dev/null; + +if [ "$?" -eq "0" ]; then + printf "Found partial connection, switching...\n"; + printf "Disabling halia partial...\n"; + wg-quick down halia &> /dev/null; + printf "Starting halia-full...\n"; + wg-quick up halia-full &> /dev/null; + printf "Successfully switched to full VPN connection\n"; +else + printf "Found full connection, switching...\n"; + printf "Disabling halia-full...\n"; + wg-quick down halia-full &> /dev/null; + printf "Starting halia partial...\n"; + wg-quick up halia &> /dev/null; + printf "Successfully switched to partial VPN connection\n"; +fi diff --git a/.zshrc b/.zshrc index b360955..a150c57 100644 --- a/.zshrc +++ b/.zshrc @@ -174,6 +174,8 @@ alias tlmgr='/usr/share/texmf-dist/scripts/texlive/tlmgr.pl --usermode' alias gitcommiiiiiiiiiiiiiit='cz' +alias havpn='~/.config/halia-switch.sh' + # The next line updates PATH for the Google Cloud SDK. if [ -f '/home/tanguy/Downloads/tmp/google-cloud-sdk/path.zsh.inc' ]; then . '/home/tanguy/Downloads/tmp/google-cloud-sdk/path.zsh.inc'; fi