Add vpn switching script

This commit is contained in:
Tanguy Herbron 2021-01-14 14:47:29 +01:00
parent 8da657ef09
commit d7106d28d1
2 changed files with 34 additions and 0 deletions

32
.config/halia-switch.sh Executable file
View File

@ -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

2
.zshrc
View File

@ -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