docker-vpn/start.tmpl

42 lines
1.5 KiB
Cheetah
Raw Normal View History

2021-11-28 02:53:29 +01:00
#!/usr/bin/env sh
INSTALLATION_NAME='{INSTALLATION_NAME}'
TAG='{TAG}'
DEPENDENCIES='sed awk shuf dirname docker'
2021-11-28 02:53:29 +01:00
conf_file="/etc/$INSTALLATION_NAME.conf"
2021-11-28 02:53:29 +01:00
for cmd in $DEPENDENCIES; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "$INSTALLATION_NAME: no such command '$cmd'" >&2
exit 1
fi
done
2021-11-28 02:53:29 +01:00
## Read the target configuration file name
# Can mention multiple files in one line seperated by space.
# Setting the variable multiple times is the same as
# when all values were set on one line delimited by a space.
# The final configuration file is drawn randomly from the
# resulting set of file.
ovpn_configuration_file="$(sed -n '/^[^#]/ s/OVPN_CONFIGURATION_FILE[^=]*=//p' "$conf_file" | tr ' ' '\n')"
ovpn_configuration_file="$(echo "$ovpn_configuration_file" | shuf -n1)"
ovpn_configuration_file="$(echo "$ovpn_configuration_file" | awk '{if (substr($0, 1, 1) != "/") {print "/etc/openvpn/client/"$0} else {print $0}}')"
ovpn_configuration_file_parent_dir="$(dirname "$ovpn_configuration_file")"
echo "ovpn_configuration_file=$ovpn_configuration_file"
if ! stat "$ovpn_configuration_file"; then
exit 1
fi
2021-11-28 02:53:29 +01:00
docker run -it --cap-add NET_ADMIN \
-v /etc/passwd:/etc/passwd \
-v "$ovpn_configuration_file_parent_dir:$ovpn_configuration_file_parent_dir" \
2021-11-28 02:53:29 +01:00
-v "$HOME:$HOME" \
2022-03-24 01:32:10 +01:00
-v "$PWD:/data/" \
2021-11-28 02:53:29 +01:00
-e OVPN_USER="$USER" \
-e OVPN_HOME="$HOME" \
2022-03-24 01:32:10 +01:00
-e OVPN_WORKDIR="/data/" \
-e OVPN_CONFIGURATION_FILE="$ovpn_configuration_file" \
2021-11-28 02:53:29 +01:00
"$TAG" sh