11#!/usr/bin/with-contenv bash
22
3- # make folders
3+ # make folders
44mkdir -p /openvpn{/pid,/sock,/tmp} /dev/net /config/log /config/etc/tmp
55
66# create tun device
@@ -9,15 +9,19 @@ if [ ! -c /dev/net/tun ]; then
99fi
1010
1111shopt -s extglob
12- # install or update openvpn-as
13- if [ -f /openvpn/openvpn.deb ]; then
12+ # install or update openvpn-as
13+ if [ -f /version.txt ]; then
14+ OPENVPNAS_VERSION=$(cat /version.txt)
1415 rm -rf /usr/local/openvpn_as
1516 ln -s /config /usr/local/openvpn_as
1617 if [ ! -f /config/etc/as.conf ]; then
1718 echo "installing openvpn-as for the first time"
18- dpkg -i /openvpn/openvpn-clients.deb
19- dpkg -i /openvpn/openvpn.deb
20- rm /openvpn/openvpn.deb
19+ apt-get update && \
20+ apt-get install -y \
21+ openvpn-as=$OPENVPNAS_VERSION
22+ echo "Stopping openvpn-as now; will start again later after configuring"
23+ kill `cat /var/run/openvpnas.pid`
24+ rm /version.txt
2125 sed -i \
2226 -e 's#=openvpn_as#=abc#g' \
2327 -e 's#~/tmp#/openvpn/tmp#g' \
@@ -37,9 +41,12 @@ if [ -f /openvpn/openvpn.deb ]; then
3741 cp /config/etc/as.conf /config/backup/as.conf
3842 cd /config || exit
3943 rm -rf !("backup"|"log")
40- dpkg -i /openvpn/openvpn-clients.deb
41- dpkg -i /openvpn/openvpn.deb
42- rm /openvpn/openvpn.deb
44+ apt-get update && \
45+ apt-get install -y \
46+ openvpn-as=$OPENVPNAS_VERSION
47+ echo "Stopping openvpn-as now; will start again later after configuring"
48+ kill `cat /var/run/openvpnas.pid`
49+ rm /version.txt
4350 sed -i \
4451 -e 's#=openvpn_as#=abc#g' \
4552 -e 's#~/tmp#/openvpn/tmp#g' \
@@ -61,15 +68,15 @@ if [ -f /openvpn/openvpn.deb ]; then
6168fi
6269shopt -u extglob
6370
64- # clear old sock files
71+ # clear old sock files
6572for file in /openvpn/sock/*
6673 do
6774 if [ -e "$file" ]; then
6875 rm -rf "$file"
6976 fi
7077 done
7178
72- # clear old pid files
79+ # clear old pid files
7380for file in /openvpn/pid/*
7481 do
7582 if [ -e "$file" ]; then
@@ -78,6 +85,6 @@ for file in /openvpn/pid/*
7885 done
7986
8087
81- # permissions
88+ # permissions
8289chown abc:abc /config/log /config/etc/tmp
8390chmod -R 755 /openvpn
0 commit comments