From 9fae7ad587d47960e565ca55d5da50a4c2460f3b Mon Sep 17 00:00:00 2001 From: Stanislas Date: Wed, 10 Mar 2021 22:14:50 +0100 Subject: [PATCH] Fix HOME_DIR check (#194) Fix #189 --- wireguard-install.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/wireguard-install.sh b/wireguard-install.sh index 746dd5f..ebd4af0 100644 --- a/wireguard-install.sh +++ b/wireguard-install.sh @@ -275,11 +275,19 @@ function newClient() { CLIENT_PRE_SHARED_KEY=$(wg genpsk) # Home directory of the user, where the client configuration will be written - if [ -e "/home/${CLIENT_NAME}" ]; then # if $1 is a user name + if [ -e "/home/${CLIENT_NAME}" ]; then + # if $1 is a user name HOME_DIR="/home/${CLIENT_NAME}" - elif [ "${SUDO_USER}" ]; then # if not, use SUDO_USER - HOME_DIR="/home/${SUDO_USER}" - else # if not SUDO_USER, use /root + elif [ "${SUDO_USER}" ]; then + # if not, use SUDO_USER + if [ "${SUDO_USER}" == "root" ]; then + # If running sudo as root + HOME_DIR="/root" + else + HOME_DIR="/home/${SUDO_USER}" + fi + else + # if not SUDO_USER, use /root HOME_DIR="/root" fi