From 1dbccabe4eeb5c75baa942a16c906f48d78ce3f8 Mon Sep 17 00:00:00 2001 From: lgromero Date: Thu, 6 Feb 2025 12:53:22 +0100 Subject: [PATCH] refs #1468 changes home of the opengnsys user --- installer/ogdhcp_installer.sh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/installer/ogdhcp_installer.sh b/installer/ogdhcp_installer.sh index 0a5ea89..c178cf2 100755 --- a/installer/ogdhcp_installer.sh +++ b/installer/ogdhcp_installer.sh @@ -147,14 +147,27 @@ function createDirs() { return 1 fi - # Crear usuario ficticio. + # Verificar si el usuario OPENGNSYS_CLIENT_USER existe if id -u "$OPENGNSYS_CLIENT_USER" &>/dev/null; then - echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENT_USER\" is already created" + # Salida de getent passwd -> opengnsys:x:1001:1001::/opt/opengnsys:/bin/sh + CURRENT_HOME=$(getent passwd "$OPENGNSYS_CLIENT_USER" | cut -d: -f6) + echoAndLog "${FUNCNAME[0]}(): user \"$OPENGNSYS_CLIENT_USER\" already exists with home \"$CURRENT_HOME\"" + + # Si el home no es correcto, cambiarlo + if [ "$CURRENT_HOME" != "/opt/opengnsys" ]; then + echoAndLog "${FUNCNAME[0]}(): updating home directory for \"$OPENGNSYS_CLIENT_USER\" to \"/opt/opengnsys\"" + usermod -d "/opt/opengnsys" -m "$OPENGNSYS_CLIENT_USER" + if [ $? -ne 0 ]; then + errorAndLog "${FUNCNAME[0]}(): error updating home for \"$OPENGNSYS_CLIENT_USER\"" + return 1 + fi + fi else - echoAndLog "${FUNCNAME}(): creating OpenGnsys user" - useradd "$OPENGNSYS_CLIENT_USER" 2>/dev/null + # Crear usuario si no existe + echoAndLog "${FUNCNAME[0]}(): creating OpenGnsys user \"$OPENGNSYS_CLIENT_USER\"" + useradd --create-home -d "/opt/opengnsys" --shell "/bin/bash" "$OPENGNSYS_CLIENT_USER" if [ $? -ne 0 ]; then - errorAndLog "${FUNCNAME}(): error creating OpenGnsys user" + errorAndLog "${FUNCNAME[0]}(): error creating user \"$OPENGNSYS_CLIENT_USER\"" return 1 fi fi @@ -162,13 +175,13 @@ function createDirs() { # Mover el fichero de registro de instalación al directorio de logs. echoAndLog "${FUNCNAME}(): moving installation log file" mv "$LOG_FILE" "$path_opengnsys_base/var/log" && LOG_FILE="$OGLOGFILE" - chmod 777 "$LOG_FILE" - sudo chmod -R 777 "$path_opengnsys_base/etc" + chmod 644 "$LOG_FILE" + chmod -R 644 "$path_opengnsys_base/etc" # Mover el fichero de registro de instalación al directorio de logs. echoAndLog "${FUNCNAME}(): moving installation log file" touch "$path_opengnsys_base/var/log/dev.log" - chmod 777 "$path_opengnsys_base/var/log/dev.log" + chmod 644 "$path_opengnsys_base/var/log/dev.log" echoAndLog "${FUNCNAME}(): directory paths created" return 0