Created
December 1, 2018 16:14
-
-
Save ukos-git/ec92a241b750985f7ac0f299a237c33a to your computer and use it in GitHub Desktop.
connect to vpn of university wuerzburg, germany (add credentials to separate conf file)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#set -e | |
# script to connect to uni wuerzburg vpn | |
# https://www.rz.uni-wuerzburg.de/dienste/it_sicherheit/vpn/ | |
# | |
# cisco password found by Chunguang Liang | |
# http://drliang.blogspot.de/2013/02/how-to-connect-vpn-of-uni-wuerzburg-via.html | |
LOG_FILE="/var/local/log/vpn-uniwue.log" | |
PID_FILE="/var/run/vpnc.pid" # default | |
SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
CONF_FILE="${SCRIPT_ROOT}/vpn-uniwue.conf" | |
# structure of the conf file should be | |
# | |
# IPSec gateway 132.187.1.5 | |
# IPSec ID Login | |
# IPSec secret 9dae7aa6ccfde46148d93351c7ab6861 | |
# Xauth username sXXXXXXX | |
# Xauth password YYYYYYYY | |
# | |
if (( $EUID != 0 )); then | |
echo "Please run as root" | |
exit 1 | |
fi | |
# check requirec packages | |
if ! command -v vpnc > /dev/null; then | |
echo "installing vpnc via apt-get" | |
sudo apt-get install --assume-yes vpnc | |
fi | |
# create log file | |
if [ ! -e "${LOG_FILE%/*}" ]; then | |
echo "creating ${LOG_FILE%/*}" | |
mkdir -p "${LOG_FILE%/*}" | |
fi | |
touch "$LOG_FILE" | |
# check if vpnc is running and quit it. | |
if [ -e "$PID_FILE" ]; then | |
PID="$(cat $PID_FILE)" | |
echo "Disconnecting ${PID}..." | |
if kill -0 $PID; then | |
kill $PID | |
fi | |
rm -f "$PID_FILE" | |
exit 0 | |
fi | |
# start vpnc | |
vpnc "$CONF_FILE" --pid-file "$PID_FILE" --non-inter &>"$LOG_FILE" | |
if [ ! -e "$PID_FILE" ]; then | |
echo "vpnc PID not found at ${PID_FILE}." 1>&2 | |
cat "$LOG_FILE" 1>&2 | |
rm "$PID_FILE" | |
exit 1 | |
fi | |
echo "connected." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment