aboutsummaryrefslogtreecommitdiff
path: root/wireguard-install.sh
diff options
context:
space:
mode:
authorStanislas <stanislas.lange@pm.me>2021-03-10 22:14:50 +0100
committerGitHub <noreply@github.com>2021-03-10 22:14:50 +0100
commit9fae7ad587d47960e565ca55d5da50a4c2460f3b (patch)
tree223f7801230883ff0cc37991aafb493109b7500b /wireguard-install.sh
parent21b5e56eea117ae0c509591a5fa1c9d79b37f383 (diff)
Fix HOME_DIR check (#194)
Fix #189
Diffstat (limited to 'wireguard-install.sh')
-rw-r--r--wireguard-install.sh16
1 files 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