-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpnmakers.sh
executable file
·56 lines (43 loc) · 1011 Bytes
/
vpnmakers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
MY_PATH="`dirname \"$0\"`"
source $MY_PATH/.config
## Return PID of running openconnect
get_PID () {
PID=$(ps -a | grep openconnect | awk '{$1=$1};1' | cut -d' ' -f1)
if [ -z "$PID" ]; then
PID=0
fi
}
## Print the status of VPN
print_status () {
get_PID
if [ "$PID" == 0 ]; then
echo 'disconnected'
else
echo 'connected'
fi
}
## Check arguments.
if [ $# -gt 1 ]; then
echo "wrong usage."
echo "sudo ./vpnmakers.sh --> for connection"
echo "sudo ./vpnmakers.sh -d --> for disconnet"
echo "sudo ./vpnmakers.sh -s --> to see status"
fi
## Connection
if [ $# -eq 0 ]; then
get_PID
if [ "$PID" == 0 ]; then
{ echo $PASSWORD; echo 'yes';} | sudo openconnect --user=$USERNAME -b \
--passwd-on-stdin $SERVER &> /dev/zero
fi
## Disconnection
elif [ $1 == '-d' ]; then
get_PID
if [ "$PID" != 0 ]; then
sudo kill $PID
fi
fi
## Finally Show Status
sleep 1
print_status