Browse Source

Add scripts

Signed-off-by: Gavin Howard <gavin@yzena.com>
master
Gavin Howard 6 months ago
parent
commit
c84bcab02f
Signed by: gavin GPG Key ID: C08038BDF280D33E
  1. 10
      vpn.sh
  2. 41
      vpnctl.sh

10
vpn.sh

@ -0,0 +1,10 @@
#! /bin/bash
#
# SPDX-License-Identifier: BlueOak-1.0.0
#
# Copyright (c) 2021 Gavin D. Howard.
#
conn=$(cat "%%CONN_FILE%%")
exec openvpn --config "%%CONFIG_DIR%%/$conn.ovpn" --auth-user-pass "%%CREDS_FILE%%" > /dev/null

41
vpnctl.sh

@ -0,0 +1,41 @@
#! /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> [<connection_name>]\n' "$0"
printf ' valid commands are: connect, disconnect, switch\n'
exit 1
fi
cmd="$1"
shift
CONN_FILE="%%CONN_FILE%%"
if [ "$#" -eq 1 ]; then
conn="$1"
shift
printf '%s\n' "$conn" > "$CONN_FILE"
fi
conn="$CONN_FILE"
connect=0
disconnect=0
case "$cmd" in
connect) connect=1 ;;
disconnect) disconnect=1 ;;
switch) connect=1; disconnect=1 ;;
*) printf 'Invalid command: %s\n' "$cmd"; exit 2;;
esac
if [ "$disconnect" -ne 0 ]; then
"%%SUPERUSER_CMD%%" pkill --signal SIGINT openvpn
fi
backgrounder "%%SUPERUSER_CMD%%" "%%INSTALL_DIR%%/vpn"
Loading…
Cancel
Save