74 lines
1.7 KiB
Bash
Executable File
74 lines
1.7 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}${VPN_PASSWORD_FILE}" ]; then
|
|
echo "You need to specify the password (VPN_PASSWORD or VPN_PASSWORD_FILE env variable)"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -z "${VPN_PASSWORD_FILE}" ]; then
|
|
if [ ! -r "${LIC_FILE}" ]; then
|
|
echo "The specified password file (${VPN_PASSWORD_FILE}) is not readable"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
VPN_PASSWORD_FILE_CONTENT=$(cat "${VPN_PASSWORD_FILE}")
|
|
VPN_PASSWORD=${VPN_PASSWORD:-$VPN_PASSWORD_FILE_CONTENT}
|
|
|
|
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 (${LIC_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
|