Browse Source

Switch to Mullvad OpenVPN

Signed-off-by: Gavin Howard <gavin@yzena.com>
master
Gavin Howard 3 months ago
parent
commit
6a45c5fdec
Signed by: gavin GPG Key ID: C08038BDF280D33E
  1. 4
      install.sh
  2. 21
      vpn.sh
  3. 2
      vpn_completions.sh
  4. 29
      vpnctl.sh

4
install.sh

@ -59,11 +59,11 @@ if [ "$super_cmd" = "" ]; then
super_cmd="sudo"
fi
printf 'Directory with Mullvad config files for Wireguard [/etc/wireguard]: '
printf 'Directory with Mullvad config files for OpenVPN [/etc/openvpn]: '
read config_dir
if [ "$config_dir" = "" ]; then
config_dir="/etc/wireguard"
config_dir="/etc/openvpn"
fi
contents=$(cat "$scriptdir/vpn.sh")

21
vpn.sh

@ -9,23 +9,6 @@ set -e
country=$(cat "%%COUNTRY_FILE%%")
opts=$(find "%%CONFIG_DIR%%" -name "mullvad-$country*" | sort)
cd "%%CONFIG_DIR%%"
num=$(find "%%CONFIG_DIR%%" -name "mullvad-$country*" | wc -l)
idx=$(printf 'irand(%s) + 1\n' "$num" | bc)
i=0
for f in $opts; do
if [ "$i" = "$idx" ]; then
conn_file="$f"
break
fi
i=$(printf '%s + 1\n' "$i" | bc)
done
exec wg-quick up "$conn_file" > /dev/null
exec openvpn --config "./mullvad_$country.conf" > /dev/null

2
vpn_completions.sh

@ -10,6 +10,6 @@ _vpn_completions()
if [ "${COMP_CWORD}" -eq 1 ]; then
COMPREPLY=($(compgen -W "connect disconnect switch reconnect" "${COMP_WORDS[1]}"))
elif [ "${COMP_CWORD}" -eq 2 ]; then
COMPREPLY=($(compgen -W "at au be bg br ca ch cz de dk ee es fi fr gb hk hu ie it jp lu lv md mk nl no nz pl pt ro rs se sg us" "${COMP_WORDS[1]}"))
COMPREPLY=($(compgen -W "ae al at au be bg br ca ch cz de dk es fi fr gb gr hk hu ie il it jp lu lv md nl no nz pl ro rs se sg us" "${COMP_WORDS[1]}"))
fi
}

29
vpnctl.sh

@ -35,22 +35,31 @@ case "$cmd" in
*) printf 'Invalid command: %s\n' "$cmd"; exit 2 ;;
esac
conn=$(doas wg show interfaces)
pgrep openvpn
err="$?"
if [ "$conn" != "" ]; then
running=1
else
running=0
fi
if [ "$err" -eq 0 ]; then
if [ "$disconnect" -ne 0 ]; then
"%%SUPERUSER_CMD%%" pkill --signal SIGINT openvpn
sleep 1
fi
country=$(cat "$COUNTRY_FILE")
if [ "$running" -ne 0 ]; then
pgrep -f "mullvad_$country.conf"
err="$?"
if [ "$connect" -ne 0 ] || [ "$disconnect" -ne 0 ]; then
"%%SUPERUSER_CMD%%" wg-quick down "$conn"
if [ "$err" -eq 0 ]; then
# VPN already started.
exit 0
elif [ "$connect" -ne 0 ]; then
# Need to disconnect and reconnect.
"%%SUPERUSER_CMD%%" pkill --signal SIGINT openvpn
sleep 1
fi
fi
if [ "$connect" -ne 0 ]; then
backgrounder "%%SUPERUSER_CMD%%" "%%INSTALL_DIR%%/vpn" > /dev/null 2> /dev/null
backgrounder "%%SUPERUSER_CMD%%" "%%INSTALL_DIR%%/vpn"
fi

Loading…
Cancel
Save