From 1c899a94d7e01ab9cdbf7778f80e200a5a401321 Mon Sep 17 00:00:00 2001 From: lgromero Date: Mon, 1 Jul 2024 12:46:07 +0200 Subject: [PATCH] refs #477 Adds nginx setup function --- installer/ogboot_installer.py | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/installer/ogboot_installer.py b/installer/ogboot_installer.py index 3fcf5e6..546317e 100755 --- a/installer/ogboot_installer.py +++ b/installer/ogboot_installer.py @@ -843,6 +843,41 @@ def get_network_interfaces(): print(get_network_interfaces()) #exit (0) +def setup_nginx(): + try: + # Obtener la IP del servidor + ip_address_server = subprocess.check_output(["ifconfig", "ens160"]).decode().split("\n")[1].split()[1] + + # Leer y modificar la plantilla de configuración de nginx + template_path = os.path.join(WORKDIR, "ogboot/etc/nginxServer.conf.tmpl") + with open(template_path, 'r') as nginx_file: + nginx_content = nginx_file.read() + + nginx_content = nginx_content.replace("__SERVERIP__", ip_address_server) + + # Ruta de destino para la configuración de nginx + nginx_output = "/etc/nginx/sites-available/ogboot.conf" + with open(nginx_output, 'w') as nginx_file: + nginx_file.write(nginx_content) + + logger.info("Nginx configuration file created successfully.") + + # Crear el enlace simbólico en sites-enabled + subprocess.run(["sudo", "ln", "-sf", nginx_output, "/etc/nginx/sites-enabled/ogboot.conf"]) + + logger.info("Symbolic link for nginx configuration created successfully.") + + # Reiniciar el servicio de samba + subprocess.run(["sudo", "systemctl", "restart", "smbd.service"]) + + logger.info("Samba service restarted successfully.") + except subprocess.CalledProcessError as e: + logger.error(f"Subprocess error: {e}") + exit(1) + except OSError as e: + logger.error(f"OS error: {e}") + exit(1) + ############################################################################### ###:::::::::::::::::::::::::::::::: MAIN :::::::::::::::::::::::::::::::::::### ############################################################################### @@ -933,6 +968,10 @@ copyClientFiles() if subprocess.run(["echo", "$?"]).returncode != 0: logger.error("Error creating client structure") +logger.info("Setup nginx") +setup_nginx() +if subprocess.run(["echo", "$?"]).returncode != 0: + logger.error("Error setup nginx") logger.info("Configuring ogCore") openGnsysConfigure()