From f181aff783ccbebfe9449c19c88358df1d9c37f4 Mon Sep 17 00:00:00 2001 From: lgromero Date: Thu, 6 Feb 2025 12:11:06 +0100 Subject: [PATCH] refs #1463 changes home of the opengnsys user --- CHANGELOG | 5 +++++ installer/ogboot_installer.py | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7150122..077880a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,10 @@ # CHANGELOG +## [0.5.10] - 06/02/2025 + +### **Cambios principales** +1. Cambia el home del usuario opengnsys como `/opt/opengnsys` + ## [0.5.9] - 03/02/2025 ### **Cambios principales** diff --git a/installer/ogboot_installer.py b/installer/ogboot_installer.py index eb35053..c729b9d 100755 --- a/installer/ogboot_installer.py +++ b/installer/ogboot_installer.py @@ -207,13 +207,28 @@ opengnsys ALL=(root) NOPASSWD: __OGBOOT_TARGET__/lib/*.iso /mnt except IOError as e: print(f"Failed to write to {sudoers_file}: {e}") + def og_core_create_user(u): try: - pwd.getpwnam(u) - logger.warning(f"User {u} already exists") + user_info = pwd.getpwnam(u) + current_home = user_info.pw_dir + logger.info(f"User {u} already exists with home {current_home}") + + if u == "opengnsys" and current_home != "/opt/opengnsys": + logger.info(f"Updating home directory for user {u} to /opt/opengnsys") + + subprocess.run(["usermod", "-d", "/opt/opengnsys", "-m", u], check=True) + logger.info(f"User {u} home changed successfully to /opt/opengnsys") + else: + logger.info(f"User {u} already has the correct home directory.") + except KeyError: - subprocess.run(["useradd", "--create-home", u, "--shell", "/bin/bash"]) - logger.info(f"User {u} created successfully.") + # El usuario no existe, crearlo con el home correcto, si es opengnsys le ponemos su home_dir como opt/opengnsys + # Si no es opengnsys le creamos el home en /home/ + home_dir = "/opt/opengnsys" if u == "opengnsys" else f"/home/{u}" + logger.info(f"Creating user {u} with home {home_dir}") + subprocess.run(["useradd", "--create-home", "-d", home_dir, "--shell", "/bin/bash", u], check=True) + logger.info(f"User {u} created successfully with home {home_dir}") def og_boot_create_dirs(): if os.path.exists(INSTALL_OGBOOT_TARGET):