Scripts to make it easier to use MullvadVPN on Gentoo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.0 KiB

#! /bin/sh
#
# SPDX-License-Identifier: BlueOak-1.0.0
#
# Copyright (c) 2021 Gavin D. Howard.
#
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
printf 'usage: %s <command> [<country_code>]\n' "$0"
printf ' valid commands are: connect, disconnect, reconnect, switch\n'
exit 1
fi
cmd="$1"
shift
COUNTRY_FILE="%%COUNTRY_FILE%%"
if [ "$#" -eq 1 ]; then
country="$1"
shift
printf '%s\n' "$country" > "$COUNTRY_FILE"
elif [ ! -f "$COUNTRY_FILE" ]; then
printf 'us\n' > "$COUNTRY_FILE"
fi
connect=0
disconnect=0
case "$cmd" in
connect) connect=1 ;;
disconnect) disconnect=1 ;;
reconnect) connect=1; disconnect=1 ;;
switch) connect=1; disconnect=1 ;;
*) printf 'Invalid command: %s\n' "$cmd"; exit 2 ;;
esac
conn=$(doas wg show interfaces)
if [ "$conn" != "" ]; then
running=1
else
running=0
fi
if [ "$running" -ne 0 ]; then
if [ "$connect" -ne 0 ] || [ "$disconnect" -ne 0 ]; then
"%%SUPERUSER_CMD%%" wg-quick down "$conn"
sleep 1
fi
fi
if [ "$connect" -ne 0 ]; then
backgrounder "%%SUPERUSER_CMD%%" "%%INSTALL_DIR%%/vpn" > /dev/null 2> /dev/null
fi