diff --git a/installer/config.json b/installer/config.json index 7b97d1b..98971a7 100644 --- a/installer/config.json +++ b/installer/config.json @@ -4,6 +4,6 @@ "ogCore_Dir": "/opt/opengnsys", "ogBoot_Dir": "/opt/ogboot", "ogBoot_GitRepo": "ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git", - "ogBootSambaUser": "ogboot", + "ogBootSambaUser": "opengnsys", "ogBootSambaPass": "og" } diff --git a/installer/ogboot_installer.py b/installer/ogboot_installer.py index ab0f783..62716df 100755 --- a/installer/ogboot_installer.py +++ b/installer/ogboot_installer.py @@ -404,25 +404,25 @@ def testPxe(): def run_command(command): result = subprocess.run(command, shell=True, text=True, capture_output=True) if result.returncode != 0: - print(f"Error executing command: {command}") - print(result.stderr) + logger.error(f"Error executing command: {command}") + logger.error(result.stderr) exit(1) - print(result.stdout) + #logger.info(result.stdout) def tftpConfigure(): global TFTPSERV, INETDSERV, TFTPCFGDIR # Update the package list #print("Updating package list...") - run_command("sudo apt update") +##################### run_command("sudo apt update") - run_command("sudo DEBIAN_FRONTEND=noninteractive apt install -y build-essential") +##################### run_command("sudo DEBIAN_FRONTEND=noninteractive apt install -y build-essential") # Install tftpd-hpa in non-interactive mode - print("Installing tftpd-hpa...") - run_command("sudo DEBIAN_FRONTEND=noninteractive apt install -y tftpd-hpa") +##################### logger.info("Installing tftpd-hpa...") +##################### run_command("sudo DEBIAN_FRONTEND=noninteractive apt install -y tftpd-hpa") # Configure tftpd-hpa - print("Configuring tftpd-hpa...") + logger.info("Configuring tftpd-hpa...") tftpd_config = """ # /etc/default/tftpd-hpa @@ -437,17 +437,17 @@ TFTP_OPTIONS="--secure" run_command("sudo mv /tmp/tftpd-hpa /etc/default/tftpd-hpa") # Create and set permissions for the TFTP directory - print("Creating and setting permissions for the TFTP directory...") - run_command("sudo mkdir -p /var/lib/tftpboot") - run_command("sudo chown -R tftp:tftp /var/lib/tftpboot") - run_command("sudo chmod -R 775 /var/lib/tftpboot") +##################### logger.info("\t2-Creating and setting permissions for the TFTP directory...") +##################### run_command("sudo mkdir -p /var/lib/tftpboot") +##################### run_command("sudo chown -R tftp:tftp /var/lib/tftpboot") +##################### run_command("sudo chmod -R 775 /var/lib/tftpboot") # Restart the tftpd-hpa service - print("Restarting tftpd-hpa service...") + logger.info("Restarting tftpd-hpa service...") run_command("sudo systemctl restart tftpd-hpa") # Check the status of the tftpd-hpa service - print("Checking tftpd-hpa service status...") + logger.info("Checking tftpd-hpa service status...") run_command("sudo systemctl status tftpd-hpa") # if TFTPSERV: # logger.info(f"TFTPSERV is configured: {TFTPSERV}") @@ -471,17 +471,17 @@ TFTP_OPTIONS="--secure" #subprocess.run(["systemctl", "enable", f"{service}.service"], check=True) # subprocess.run(["systemctl", "start", f"{service}.service"], check=True) #Crear directorio /var/lib/tftpboot - if not os.path.exists(TFTPCFGDIR): - os.makedirs(TFTPCFGDIR, mode=0o775, exist_ok=True) + if os.path.exists(TFTPCFGDIR): + ############## os.makedirs(TFTPCFGDIR, mode=0o775, exist_ok=True) subprocess.run(["chown", "-R", "tftp:ogboot", TFTPCFGDIR]) - logger.info(f"Directory {TFTPCFGDIR} created.") + logger.info(f"{TFTPCFGDIR} directory permissions modified correctly.") else: - logger.warning(f"Directory {TFTPCFGDIR} exist.") + logger.warning(f"\t1-{TFTPCFGDIR} directory not exist.") symlink_target = f"{INSTALL_OGBOOT_TARGET}/tftpboot" logger.info(f"Creating symbolic link from {TFTPCFGDIR} to {symlink_target}") if not os.path.exists(symlink_target): os.symlink(TFTPCFGDIR, symlink_target) - os.lchown(symlink_target, pwd.getpwnam("ogboot").pw_uid, pwd.getpwnam("ogboot").pw_gid) + os.lchown(symlink_target, pwd.getpwnam("tftp").pw_uid, pwd.getpwnam("ogboot").pw_gid) else: logger.warning(f"The symbolic link already exists: {symlink_target}") #Descargar oglive @@ -494,9 +494,18 @@ TFTP_OPTIONS="--secure" capture_output=True, text=True ) - logger.info(f"oglivecli install output: {result.stdout}") + logger.info("Successful download") + symlink_target_ogLive = f"{INSTALL_OGBOOT_TARGET}/tftpboot/ogLive" + symlink_target_ogclient = f"{INSTALL_OGBOOT_TARGET}/tftpboot/ogclient" + if os.path.exists(symlink_target_ogLive): + subprocess.run(["sudo", "chown", "-R", f"tftp:ogboot", f"{INSTALL_OGBOOT_TARGET}/tftpboot"], check=True) + os.lchown(symlink_target_ogLive, pwd.getpwnam("tftp").pw_uid, pwd.getpwnam("ogboot").pw_gid) + os.lchown(symlink_target_ogclient, pwd.getpwnam("tftp").pw_uid, pwd.getpwnam("ogboot").pw_gid) + logger.info(f"Changing properties for {symlink_target_ogLive} and {symlink_target_ogclient}") + else: + logger.error(f"{symlink_target_ogLive} link does not exists.") except subprocess.CalledProcessError as e: - logger.error(f"Failed to install ogLive client: {e.stderr}") + logger.error(f"Failed to install ogLive client: {e}") logger.error("Continuing with the installation...") #---------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------- @@ -691,7 +700,7 @@ def get_ip_address(interface): ip_address = line.strip().split()[1].split('/')[0] return ip_address except subprocess.CalledProcessError as e: - print(f"Error get address IP: {e}") + logger.error(f"Error get address IP: {e}") return None def generate_ipxe_script(): @@ -722,6 +731,14 @@ def generate_ipxe_script(): default_ipxe_file.write(default_ipxe_content) logger.info("ipxe files created correctly.") +def user_exists(user): + try: + result = subprocess.run(["sudo", "pdbedit", "-L", "-u", user], capture_output=True, text=True) + return user in result.stdout + except subprocess.CalledProcessError as e: + logger.error(f"Error checking if user exists: {e}") + return False + def smbConfigure(): global SAMBACFGDIR, SAMBASERV, OPENGNSYS_CLIENT_PASSWD, OPENGNSYS_CLIENT_USER, PYTHON_VERSION #logger.info(f"{smbConfigure.__name__}(): Configuring Samba service.") @@ -749,6 +766,29 @@ def smbConfigure(): logger.error(f"Failed to start {service} service.") return 1 # Ejecutar el comando smbpasswd para agregar el usuario de Samba + try: + if user_exists(OPENGNSYS_CLIENT_USER): + logger.info(f"{OPENGNSYS_CLIENT_USER} user exists. Changing password...") + subprocess.run( + ["sudo", "smbpasswd", OPENGNSYS_CLIENT_USER], + input=f"{OPENGNSYS_CLIENT_PASSWD}\n{OPENGNSYS_CLIENT_PASSWD}\n", + text=True, + check=True + ) + else: + logger.info(f"{OPENGNSYS_CLIENT_USER} user does not exist. Registering user...") + subprocess.run( + ["sudo", "smbpasswd", "-a", OPENGNSYS_CLIENT_USER], + input=f"{OPENGNSYS_CLIENT_PASSWD}\n{OPENGNSYS_CLIENT_PASSWD}\n", + text=True, + check=True + ) + logger.info("Add/Modify user: Operation completed successfully.") + except subprocess.CalledProcessError as e: + logger.error(f"Error adding/modifying user: {e}") + return 0 + +''' try: process_add = subprocess.run( ["sudo", "smbpasswd", "-a", OPENGNSYS_CLIENT_USER], @@ -759,8 +799,7 @@ def smbConfigure(): logger.info(f"The password for the user {OPENGNSYS_CLIENT_USER} has been set correctly.") except subprocess.CalledProcessError as e: logger.error(f"Error setting password: {e}") - return 0 - +''' def setup_nginx(): global DEFAULTDEV, WORKDIR try: @@ -906,7 +945,7 @@ def install_oglive_daemon(): ###:::::::::::::::::::::::::::::::: MAIN :::::::::::::::::::::::::::::::::::### ############################################################################### -logger.info(f"Starting installation of ogBoot.") +logger.info(f":::::::::::::::::::::::: Starting ogBoot installation ::::::::::::::::::::::::") logger.info("environment variables") logger.info(f"OGCORE_IP:{OGCORE_IP}") @@ -951,12 +990,12 @@ else: if not os.path.exists(f"{WORKDIR}/ogboot"): if not os.path.exists(WORKDIR): os.makedirs(WORKDIR, mode=0o775, exist_ok=True) - logger.info(f"Dir {WORKDIR}/ogboot created") + logger.info(f"{WORKDIR}/ogboot directory created") logger.info(f"ogBoot directory not found, create a symbolic link to the directory where the code is located {WORKDIR} To {os.path.dirname(PROGRAM_DIR)}") os.symlink(os.path.dirname(PROGRAM_DIR), f"{WORKDIR}/ogboot") logger.info("Creating ogBoot project.") -og_core_create_user("ogboot") +og_core_create_user(OPENGNSYS_CLIENT_USER) logger.info("Creating directories.") og_boot_create_dirs() @@ -970,7 +1009,7 @@ og_boot_symfony_install() logger.info("Installing Composer.") og_boot_composer_install() -logger.info("Configuring TFTP service.") +logger.info("Configuring tftpd-hpa service.") tftpConfigure() logger.info("Configuring IPXE services")