Skip to content

Commit

Permalink
add CLIENT_FILEPATH environment variable support
Browse files Browse the repository at this point in the history
This environment variable can be set to customize destination of
.ovpn file to generate.

If defined, it should contain the full path of the file to generate.
  • Loading branch information
Toilal committed Jan 19, 2022
1 parent 47cea09 commit fa44927
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions openvpn-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1093,26 +1093,28 @@ function newClient() {
echo "Client $CLIENT added."
fi
# Home directory of the user, where the client configuration will be written
if [ -e "/home/${CLIENT}" ]; then
# if $1 is a user name
homeDir="/home/${CLIENT}"
CLIENT_OWNER="$CLIENT"
elif [ "${SUDO_USER}" ]; then
# if not, use SUDO_USER
if [ "${SUDO_USER}" == "root" ]; then
# If running sudo as root
homeDir="/root"
if [[ -z "$CLIENT_FILEPATH" ]]; then
# Home directory of the user, where the client configuration will be written
if [ -e "/home/${CLIENT}" ]; then
# if $1 is a user name
homeDir="/home/${CLIENT}"
CLIENT_OWNER="$CLIENT"
elif [ "${SUDO_USER}" ]; then
# if not, use SUDO_USER
if [ "${SUDO_USER}" == "root" ]; then
# If running sudo as root
homeDir="/root"
else
homeDir="/home/${SUDO_USER}"
fi
CLIENT_OWNER="$SUDO_USER"
else
homeDir="/home/${SUDO_USER}"
# if not SUDO_USER, use /root
homeDir="/root"
fi
CLIENT_OWNER="$SUDO_USER"
else
# if not SUDO_USER, use /root
homeDir="/root"
fi
CLIENT_FILEPATH="$homeDir/$CLIENT.ovpn"
CLIENT_FILEPATH="$homeDir/$CLIENT.ovpn"
fi
# Determine if we use tls-auth or tls-crypt
if grep -qs "^tls-crypt" /etc/openvpn/server.conf; then
Expand Down

0 comments on commit fa44927

Please sign in to comment.