64 lines
1.3 KiB
Bash
Executable File
64 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
stty -echoctl # hide ^C
|
|
|
|
set +H # disable history expansion, to enable the use of exclamation mark in the password
|
|
# set +o histexpand
|
|
|
|
|
|
# add tap device if it doesn't exists
|
|
if [ ! -d /sys/class/net/tap0 ] ; then
|
|
ip tuntap add mode tap tap0
|
|
fi
|
|
|
|
# TODO: check if /sys/class/net/tap0/operstate says "up" and quit?
|
|
|
|
CONFIGDIR=/app/config/
|
|
CONFIGFILE="${CONFIGDIR}/barracudavpn.conf"
|
|
|
|
mkdir -p "${CONFIGDIR}"
|
|
|
|
if [ -z "${VPN_PASSWORD}" ]; then
|
|
echo "You need to specify the password (VPN_PASSWORD env variable)"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "${LIC_FILE}" ]; then
|
|
echo "You need to specify the path to the license file (LIC_FILE env variable)"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -r "${LIC_FILE}" ]; then
|
|
echo "The license file is not readable"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "${SERVER}" ]; then
|
|
echo "You need to specify the server (SERVER env variable)"
|
|
exit 1
|
|
fi
|
|
|
|
export SERVERPORT=${SERVERPORT:-691}
|
|
|
|
# generate new config file
|
|
envsubst < /app/barracudavpn.conf.tpl > "${CONFIGFILE}"
|
|
|
|
stop_vpn() {
|
|
echo Closing VPN connection
|
|
/app/barracudavpn --config "${CONFIGDIR}" --stop
|
|
sleep 2
|
|
exit
|
|
}
|
|
|
|
start_vpn() {
|
|
echo Opening VPN connection
|
|
/app/barracudavpn --config "${CONFIGDIR}" --start --keypwd "${VPN_PASSWORD}" --serverpwd "${VPN_PASSWORD}"
|
|
}
|
|
|
|
trap 'stop_vpn' INT TERM
|
|
|
|
start_vpn
|
|
while : ; do
|
|
sleep 1m
|
|
done
|