Skip to content
This repository was archived by the owner on Jun 15, 2021. It is now read-only.

Commit 539b53f

Browse files
committed
simplify openvpn install and setup process
1 parent 9b18b3c commit 539b53f

File tree

3 files changed

+14
-28
lines changed

3 files changed

+14
-28
lines changed

Dockerfile

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,23 @@ RUN \
1717
iptables \
1818
net-tools \
1919
rsync && \
20-
echo "**** install openvpn-as ****" && \
20+
echo "**** download openvpn-as ****" && \
2121
if [ -z ${OPENVPNAS_VERSION+x} ]; then \
2222
OPENVPNAS_VERSION=$(curl -w "%{url_effective}" -ILsS -o /dev/null \
2323
https://openvpn.net/downloads/openvpn-as-latest-ubuntu16.amd_64.deb \
2424
| awk -F '(openvpn-as-|-Ubuntu16)' '{print $2}'); \
2525
fi && \
26+
mkdir /openvpn && \
2627
curl -o \
27-
/tmp/openvpn.deb -L \
28+
/openvpn/openvpn.deb -L \
2829
"https://swupdate.openvpn.org/as/openvpn-as-${OPENVPNAS_VERSION}-Ubuntu16.amd_64.deb" && \
29-
dpkg -i /tmp/openvpn.deb && \
3030
echo "**** ensure home folder for abc user set to /config ****" && \
3131
usermod -d /config abc && \
3232
echo "**** create admin user and set default password for it ****" && \
3333
useradd -s /sbin/nologin admin && \
3434
echo "admin:password" | chpasswd && \
35-
echo "**** configure openvpn-as ****" && \
36-
find /usr/local/openvpn_as/scripts -type f -print0 | \
37-
xargs -0 sed -i 's#/usr/local/openvpn_as#/config#g' && \
38-
find /usr/local/openvpn_as/bin -type f -print0 | \
39-
xargs -0 sed -i 's#/usr/local/openvpn_as#/config#g' && \
40-
sed -i \
41-
-e 's#=openvpn_as#=abc#g' \
42-
-e 's#~/tmp#/openvpn/tmp#g' \
43-
-e 's#~/sock#/openvpn/sock#g' \
44-
/usr/local/openvpn_as/etc/as_templ.conf && \
45-
echo "**** cleanup ****" && \
46-
apt-get clean && \
4735
rm -rf \
48-
/tmp/* \
49-
/usr/local/openvpn_as/etc/db/* \
50-
/usr/local/openvpn_as/etc/sock \
51-
/usr/local/openvpn_as/etc/tmp \
52-
/usr/local/openvpn_as/tmp \
53-
/var/lib/apt/lists/* \
54-
/var/tmp/*
36+
/tmp/*
5537

5638
# add local files
5739
COPY /root /

root/etc/cont-init.d/30-config

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ if [ ! -c /dev/net/tun ]; then
99
fi
1010

1111
# copy config or update
12-
if [ ! -f /config/bin/ovpn-init ]; then
13-
cp -pr /usr/local/openvpn_as/* /config/
14-
else
15-
rsync -rlptD --exclude="/etc/as.conf" --exclude="/etc/config.json" --exclude="/tmp" /usr/local/openvpn_as/ /config/
12+
if [ -f /openvpn/openvpn.deb ]; then
13+
echo "installing openvpn"
14+
rm -rf /usr/local/openvpn_as
15+
ln -s /config /usr/local/openvpn_as
16+
dpkg -i /openvpn/openvpn.deb
17+
rm /openvpn/openvpn.deb
18+
apt-get clean
19+
rm -rf /tmp
1620
fi
1721

1822
# clear old sock files

root/etc/cont-init.d/40-openvpn-init

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ else
99
CONFINPUT=$NOASCONFIG$ASCONFIG
1010
fi
1111

12-
if [[ $(find /config/etc/db -type f | wc -l) -eq 0 || ! -f "/config/etc/as.conf" ]]; then
12+
if [[ $(find /config/etc/db -type f | wc -l) -eq 0 || ! -f "/config/etc/as.conf" || (-f "/config/etc/as.conf" && $(cat /config/etc/as.conf | grep "vpn.server.user=openvpn_as")) ]]; then
1313
# shellcheck disable=SC2059
14-
printf "${CONFINPUT}" | /config/bin/ovpn-init
14+
printf "${CONFINPUT}" | /usr/local/openvpn_as/bin/ovpn-init
1515
fi
1616

1717
chown -R abc:abc \

0 commit comments

Comments
 (0)