mirror of
https://github.com/angristan/openvpn-install.git
synced 2025-12-18 17:57:03 +01:00
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
This commit is contained in:
@@ -1549,7 +1549,7 @@ verb 3" >>/etc/openvpn/server/client-template.txt
|
|||||||
# Helper function to get the home directory for storing client configs
|
# Helper function to get the home directory for storing client configs
|
||||||
function getHomeDir() {
|
function getHomeDir() {
|
||||||
local client="$1"
|
local client="$1"
|
||||||
if [ -e "/home/${client}" ]; then
|
if [ -d "/home/${client}" ]; then
|
||||||
echo "/home/${client}"
|
echo "/home/${client}"
|
||||||
elif [ "${SUDO_USER}" ]; then
|
elif [ "${SUDO_USER}" ]; then
|
||||||
if [ "${SUDO_USER}" == "root" ]; then
|
if [ "${SUDO_USER}" == "root" ]; then
|
||||||
@@ -1589,7 +1589,7 @@ function setClientConfigPermissions() {
|
|||||||
# Helper function to write client config file with proper path and permissions
|
# Helper function to write client config file with proper path and permissions
|
||||||
# Usage: writeClientConfig <client_name>
|
# Usage: writeClientConfig <client_name>
|
||||||
# Uses CLIENT_FILEPATH env var if set, otherwise defaults to home directory
|
# 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() {
|
function writeClientConfig() {
|
||||||
local client="$1"
|
local client="$1"
|
||||||
local clientFilePath
|
local clientFilePath
|
||||||
@@ -1601,7 +1601,7 @@ function writeClientConfig() {
|
|||||||
local parentDir
|
local parentDir
|
||||||
parentDir=$(dirname "$clientFilePath")
|
parentDir=$(dirname "$clientFilePath")
|
||||||
if [[ ! -d "$parentDir" ]]; then
|
if [[ ! -d "$parentDir" ]]; then
|
||||||
run_cmd "Creating directory $parentDir" mkdir -p "$parentDir"
|
run_cmd_fatal "Creating directory $parentDir" mkdir -p "$parentDir"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
local homeDir
|
local homeDir
|
||||||
|
|||||||
Reference in New Issue
Block a user