Skip to content

Commit ff2c224

Browse files
committed
Auto auth using username and password in openvpn/run.sh
1 parent ca770e7 commit ff2c224

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

images/openvpn/run.sh

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,32 @@ echo $gw
1010

1111
ls -la
1212

13-
MERGED_CONFIG=merged.config.ovpn
13+
# Enable compatability layer with Alpine
14+
MERGED_CONFIG_FILE=merged.config.ovpn
1415

15-
cat <<EOF > $MERGED_CONFIG
16+
cat <<EOF > $MERGED_CONFIG_FILE
1617
script-security 2
1718
up /etc/openvpn/up.sh
1819
down /etc/openvpn/down.sh
1920
EOF
2021

21-
cat "${OPENVPN_CONFIG_FILE}" >> $MERGED_CONFIG
22+
cat "${OPENVPN_CONFIG_FILE}" >> $MERGED_CONFIG_FILE
2223

23-
openvpn --config "/opt/openvpn/${MERGED_CONFIG}"
24+
# Auth using username and password
25+
VPN_AUTH_FILE=vpn.auth
26+
# Create credentials file
27+
cat <<EOF > $VPN_AUTH_FILE
28+
${OPENVPN_USERNAME}
29+
${OPENVPN_PASSWORD}
30+
EOF
31+
32+
# Add `auth-user-pass $VPN_AUTH_FILE` to the merged config
33+
if grep -q auth-user-pass $MERGED_CONFIG_FILE; then
34+
# if has string started with `auth-user-pass`
35+
sed -i "s/^auth-user-pass.*/auth-user-pass ${VPN_AUTH_FILE}/" $MERGED_CONFIG_FILE
36+
elif [ -n "${OPENVPN_USERNAME}" ]; then
37+
# If not empty username
38+
echo "auth-user-pass ${VPN_AUTH_FILE}" >> $MERGED_CONFIG_FILE
39+
fi
40+
41+
openvpn --config "/opt/openvpn/${MERGED_CONFIG_FILE}"

0 commit comments

Comments
 (0)