Skip to content

Commit

Permalink
Fix home dir detection when using sudo as root
Browse files Browse the repository at this point in the history
Close #780
  • Loading branch information
angristan committed Mar 10, 2021
1 parent d1de5c6 commit e965518
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions openvpn-install.sh
Expand Up @@ -1084,12 +1084,20 @@ function newClient() {
echo "Client $CLIENT added."
fi
# Home directory of the user, where the client configuration (.ovpn) will be written
if [ -e "/home/$CLIENT" ]; then # if $1 is a user name
homeDir="/home/$CLIENT"
elif [ "${SUDO_USER}" ]; then # if not, use SUDO_USER
homeDir="/home/${SUDO_USER}"
else # if not SUDO_USER, use /root
# Home directory of the user, where the client configuration will be written
if [ -e "/home/${CLIENT_NAME}" ]; then
# if $1 is a user name
homeDir="/home/${CLIENT_NAME}"
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
else
# if not SUDO_USER, use /root
homeDir="/root"
fi
Expand Down

0 comments on commit e965518

Please sign in to comment.