updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / netcfg-openconnect / openconnect
blobe608405ea54bc56623c8d520693d4541fb48507a
1 #!/bin/bash
3 . /usr/lib/network/network
5 openconnect_up() {
6 local CMD_FLAGS PID_FILE AUTH_GROUP PASSWORD URL USER VPNC_SCRIPT
8 load_profile "$1"
10 if [[ -z $URL ]]; then
11 report_fail "No url specified in profile"
12 exit 1
15 VPNC_SCRIPT=${VPNC_SCRIPT:-/etc/vpnc/vpnc-script}
16 if [[ ! -e $VPNC_SCRIPT ]]; then
17 report_fail "vpnc script does not exists: $VPNC_SCRIPT"
18 exit 1
21 PASSWORD=${PASSWORD:-""}
22 [[ -n $USER ]] && CMD_FLAGS+=" --user=$USER"
23 [[ -n $PASSWORD ]] && CMD_FLAGS+=" --passwd-on-stdin"
24 [[ -n $AUTH_GROUP ]] && CMD_FLAGS+=" --authgroup=$AUTH_GROUP"
26 PID_FILE="/run/openconnect-$1.pid"
28 /usr/sbin/openconnect --background --quiet --script "$VPNC_SCRIPT" $CMD_FLAGS "$URL" <<<"$PASSWORD"
30 if [[ $? -ne 0 ]]; then
31 report_fail "openconnect connection failed"
32 exit 1
35 /usr/bin/pgrep -n ^openconnect$ > "$PID_FILE"
38 openconnect_down() {
39 local CMD_FLAGS PID_FILE AUTH_GROUP PASSWORD URL USER VPNC_SCRIPT
41 load_profile "$1"
42 PID_FILE="/run/openconnect-$1.pid"
44 kill -- $(<$PID_FILE)
45 rm -- "$PID_FILE"
48 openconnect_$1 "$2"
49 exit $?
51 # vim: ft=sh ts=4 et sw=4: