diff --git a/installer/ogboot_installer.py b/installer/ogboot_installer.py index ff7cb9b..d5d3cd4 100755 --- a/installer/ogboot_installer.py +++ b/installer/ogboot_installer.py @@ -168,33 +168,42 @@ def get_missing_packages(): return faltantes def install_packages(missing, log_packages_file="/tmp/installed_packages.log"): - if not missing: - logger.info("All packages are already installed.") - return - - logger.info("Upgrading the system...") - original_debian_frontend = os.environ.get('DEBIAN_FRONTEND') - - try: - os.environ['DEBIAN_FRONTEND'] = 'noninteractive' - subprocess.run(["sudo", "apt-get", "update"], check=True) - subprocess.run( - ["sudo", "apt-get", "install", "--allow-change-held-packages", "-y", "--no-install-recommends"] + missing, - check=True - ) - - with open(log_packages_file, "a") as log: - for package in missing: - logger.info(f"{package} installed correctly.") - log.write(package + "\n") - - logger.info("All missing packages have been installed.") - - finally: - if original_debian_frontend is not None: - os.environ['DEBIAN_FRONTEND'] = original_debian_frontend - else: - del os.environ['DEBIAN_FRONTEND'] + if not missing: + logger.info("All packages are already installed.") + return + + logger.info("Upgrading the system...") + original_debian_frontend = os.environ.get('DEBIAN_FRONTEND') + + try: + os.environ['DEBIAN_FRONTEND'] = 'noninteractive' + subprocess.run(["sudo", "apt-get", "update"], check=True) + subprocess.run( + ["sudo", "apt-get", "install", "--allow-change-held-packages", "-y", "--no-install-recommends"] + missing, + check=True + ) + + with open(log_packages_file, "a") as log: + for package in missing: + logger.info(f"{package} installed correctly.") + log.write(package + "\n") + + logger.info("All missing packages have been installed.") + + # Check PHP version and install corresponding php-fpm package + php_version = subprocess.check_output(["php", "-v"]).decode("utf-8") + if "PHP 8.1" in php_version: + subprocess.run(["sudo", "apt-get", "install", "-y", "php8.1-fpm"], check=True) + elif "PHP 8.3" in php_version: + subprocess.run(["sudo", "apt-get", "install", "-y", "php8.3-fpm"], check=True) + else: + logger.warning("PHP version not supported.") + + finally: + if original_debian_frontend is not None: + os.environ['DEBIAN_FRONTEND'] = original_debian_frontend + else: + del os.environ['DEBIAN_FRONTEND'] def autoConfigure(): global OSDISTRIB, OSVERSION @@ -386,18 +395,25 @@ def get_ogboot_uid_gid(): # Añadir líneas al fstab def add_fstab_entries(uid, gid): - try: - fstab_entries = [ - f'/opt/ogboot/lib/oglive.iso /tmp/opt/ogboot/lib/ogLive iso9660 loop,ro,users,uid={uid},gid={gid} 0 0\n', - f'/var/lib/tftpboot/ogLive/ogclient.sqfs /tmp/ogclient_mount squashfs loop,ro,user 0 0\n' - ] - - with open('/etc/fstab', 'a') as fstab: - fstab.writelines(fstab_entries) - logger.info("Entradas añadidas a /etc/fstab correctamente.") - - except IOError: - raise Exception("Error al escribir en /etc/fstab.") + try: + fstab_entries = [ + f'/opt/ogboot/lib/oglive.iso /tmp/opt/ogboot/lib/ogLive iso9660 loop,ro,users,uid={uid},gid={gid},noauto 0 0\n', + f'/var/lib/tftpboot/ogLive/ogclient.sqfs /tmp/ogclient_mount squashfs loop,ro,user,noauto 0 0\n' + ] + + with open('/etc/fstab', 'r') as fstab: + existing_entries = fstab.readlines() + + # Check if the entries already exist in /etc/fstab + if all(entry.strip() not in existing_entries for entry in fstab_entries): + with open('/etc/fstab', 'a') as fstab: + fstab.writelines(fstab_entries) + logger.info("Entradas añadidas a /etc/fstab correctamente.") + else: + logger.info("Las entradas ya existen en /etc/fstab. No se añadieron nuevamente.") + + except IOError: + raise Exception("Error al escribir en /etc/fstab.") # Añadir el usuario ogboot al grupo disk def add_user_to_disk_group(): @@ -800,7 +816,7 @@ def get_php_fpm_version(): exit(1) def modify_php_fpm_config(): - php_version = "8.2" # Establecemos la versión de PHP a 8.2 + php_version = get_php_fpm_version() # Establecemos la versión de PHP a 8.2 php_fpm_conf_path = f"/etc/php/{php_version}/fpm/pool.d/www.conf" new_fpm_conf_path = f"/etc/php/{php_version}/fpm/pool.d/ogboot.conf" socket_path = f"/run/php/php{php_version}-fpm-ogboot.sock"