From 8d9a568d0fcbdda8c9a656f6d4a25639db601d4f Mon Sep 17 00:00:00 2001 From: Stanislas Lange Date: Sat, 13 Dec 2025 23:13:56 +0100 Subject: [PATCH] fix: address review feedback for CLIENT_FILEPATH handling - Use -d instead of -e in getHomeDir() for consistency with getClientOwner() - Use run_cmd_fatal for mkdir to fail early on permission errors - Fix documentation to clarify global variable side effect --- openvpn-install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openvpn-install.sh b/openvpn-install.sh index 360477c..afbbf4f 100755 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -1549,7 +1549,7 @@ verb 3" >>/etc/openvpn/server/client-template.txt # Helper function to get the home directory for storing client configs function getHomeDir() { local client="$1" - if [ -e "/home/${client}" ]; then + if [ -d "/home/${client}" ]; then echo "/home/${client}" elif [ "${SUDO_USER}" ]; then if [ "${SUDO_USER}" == "root" ]; then @@ -1589,7 +1589,7 @@ function setClientConfigPermissions() { # Helper function to write client config file with proper path and permissions # Usage: writeClientConfig # Uses CLIENT_FILEPATH env var if set, otherwise defaults to home directory -# Returns: sets GENERATED_CONFIG_PATH variable with the final path +# Side effects: sets GENERATED_CONFIG_PATH global variable with the final path function writeClientConfig() { local client="$1" local clientFilePath @@ -1601,7 +1601,7 @@ function writeClientConfig() { local parentDir parentDir=$(dirname "$clientFilePath") if [[ ! -d "$parentDir" ]]; then - run_cmd "Creating directory $parentDir" mkdir -p "$parentDir" + run_cmd_fatal "Creating directory $parentDir" mkdir -p "$parentDir" fi else local homeDir