-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocvpn-debian.sh
49 lines (37 loc) · 1.04 KB
/
ocvpn-debian.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
#!/bin/bash
### pre-alpha version for openconnect client installer in Debian
### bash ocvpn-debian.sh ADDRESS USERNAME PASSWORD
### bash ocvpn-debian.sh 219.2.2.2:443 user1 pass1
### bash ocvpn-debian.sh https://vp.example.com user1 pass1
###### Main
ADDRESS=""
USERNAME=""
PASSWORD=""
ADDRESS=$1
USERNAME=$2
PASSWORD=$3
if [[ $PASSWORD == "" ]] ; then
echo "run:\n bash ocvpn-debian.sh server-address username password"
exit
fi
apt update
apt dist-upgrade -y
apt install openconnect -y
cat > /etc/systemd/system/ocvpn.service << "EOF"
[Unit]
Description=Connect to my VPN
After=network.target
[Service]
Type=simple
ExecStart=/bin/sh -c 'echo password | openconnect -u username --passwd-on-stdin address'
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
sed -i "s~password~$PASSWORD~" /etc/systemd/system/ocvpn.service
sed -i "s~username~$USERNAME~" /etc/systemd/system/ocvpn.service
sed -i "s~address~$ADDRESS~" /etc/systemd/system/ocvpn.service
systemctl daemon-reload
systemctl enable ocvpn
systemctl start ocvpn
systemctl status ocvpn