Refs #202 add config environment file

ogboot_installer
Antonio Guerrero 2024-07-08 20:00:39 +00:00
parent dd629e54f5
commit c7fbea9231
2 changed files with 136 additions and 149 deletions

View File

@ -0,0 +1,9 @@
{
"ogCore_ServerIP": "172.17.8.82",
"ogCore_Server": "opengnsys.es",
"ogCore_Dir": "/opt/opengnsys",
"ogBoot_Dir": "/opt/ogboot",
"ogBoot_GitRepo": "ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git",
"ogBootSambaUser": "ogboot",
"ogBootSambaPass": "og"
}

View File

@ -1,39 +1,28 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
##################################################################################
##### ogBoot installer script ####
##### Developed by: Luis Gerardo Romero García <lromero@qindel.com> ####
##### Antonio Emmanuel Guerrero Silva <aguerrero@qindel.com> ####
##### Last: 2024-07-08 ####
##################################################################################
################################################################################# import platform, os, sys, subprocess, datetime, shutil, pwd, glob, zipfile, urllib.request, logging, distro, re, json
##### ogBoot installer script ########
##### Autor: Antonio Emmanuel Guerrero Silva <aguerrero@qindel.com> ########
#################################################################################
import platform, os, sys, subprocess, datetime, shutil, pwd, glob, zipfile, urllib.request, logging, distro, re
# Reload variables from bashrc
# subprocess.run(['source', '~/.bashrc'], shell=True)
# Leer variables de entorno
#env_ogCore_ServerIP = os.getenv('OGCORE_SERVER_IP') #"172.17.8.82"
#env_ogCore_Server = os.getenv('OGCORE_SERVER') #"opengnsys.es"
#env_ogCore_Dir = os.getenv('OGCORE_DIR') #{INSTALL_OPENGNSYS_TARGET}
#env_ogBoot_Dir = os.getenv('OGBOOT_DIR') #{INSTALL_OGBOOT_TARGET}
#env_ogBoot_GitRepo = os.getenv('OGBOOT_GIT_REPO') #"ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git"
# Constantes, ambiente de desarrollo
env_ogCore_ServerIP = "172.17.8.82"
env_ogCore_Server = "opengnsys.es"
env_ogCore_Dir = "/opt/opengnsys"
env_ogBoot_Dir = "/opt/ogboot"
env_ogBoot_GitRepo = "ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git"
PROGRAM = os.path.splitext(os.path.basename(sys.argv[0]))[0] PROGRAM = os.path.splitext(os.path.basename(sys.argv[0]))[0]
PROGRAM_DIR = os.path.dirname(os.path.realpath(sys.argv[0])) PROGRAM_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
PROGRAM_NAME = os.path.basename(sys.argv[0]) PROGRAM_NAME = os.path.basename(sys.argv[0])
OGCORE_IP = f"{env_ogCore_ServerIP}" with open('config.json', 'r') as f:
OGCORE_SERVER = f"{env_ogCore_Server}" config = json.load(f)
INSTALL_TARGET = f"{env_ogBoot_Dir}"
INSTALL_OPENGNSYS_TARGET = f"{env_ogCore_Dir}" OGCORE_IP = config["ogCore_ServerIP"]
INSTALL_OGBOOT_TARGET = f"{env_ogBoot_Dir}" OGCORE_SERVER = config["ogCore_Server"]
GIT_REPO = f"{env_ogBoot_GitRepo}" INSTALL_OPENGNSYS_TARGET = config["ogCore_Dir"]
INSTALL_OGBOOT_TARGET = config["ogBoot_Dir"]
INSTALL_TARGET = config["ogBoot_Dir"]
GIT_REPO = config["ogBoot_GitRepo"]
OPENGNSYS_CLIENT_USER = config["ogBootSambaUser"]
OPENGNSYS_CLIENT_PASSWD = config["ogBootSambaPass"]
OSDISTRIB = "" OSDISTRIB = ""
OSVERSION = "" OSVERSION = ""
@ -55,8 +44,6 @@ NETBROAD = []
ROUTERIP = [] ROUTERIP = []
BRANCH = sys.argv[1] if len(sys.argv) > 1 else "main" BRANCH = sys.argv[1] if len(sys.argv) > 1 else "main"
INETDSERV = "xinetd" INETDSERV = "xinetd"
OPENGNSYS_CLIENT_PASSWD="og"
OPENGNSYS_CLIENT_USER="opengnsys"
UBUNTU_OS_VERSION = "22" UBUNTU_OS_VERSION = "22"
PYTHON_VERSION = 3 PYTHON_VERSION = 3
@ -73,7 +60,7 @@ subprocess.run(['sudo', 'touch', log_file])
#subprocess.run(['sudo', 'chown', 'ogboot', log_file]) #subprocess.run(['sudo', 'chown', 'ogboot', log_file])
subprocess.run(['sudo', 'chmod', '777', log_file]) subprocess.run(['sudo', 'chmod', '777', log_file])
#Configurar el registro #Configure the log
logging.basicConfig(level=logging.DEBUG, logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)s\t%(message)s', format='%(asctime)s %(levelname)s\t%(message)s',
filename=f'/var/log/{PROGRAM}.log', filename=f'/var/log/{PROGRAM}.log',
@ -133,7 +120,7 @@ def downloadCode(url):
logger.error("Error getting OpenGnsys code from " + url) logger.error("Error getting OpenGnsys code from " + url)
return 1 return 1
subprocess.run(["rm -f opengnsys.zip"], shell=True) subprocess.run(["rm -f opengnsys.zip"], shell=True)
logger.info("downloadCode(): code was downloaded") logger.info("downloadCog_boot_create_dirsode(): code was downloaded")
return 0 return 0
############################################################################### ###############################################################################
@ -162,7 +149,7 @@ def get_missing_packages():
case "18.04": case "18.04":
PACKAGES_TO_INSTALL = ["nano", "wget", "tree"] PACKAGES_TO_INSTALL = ["nano", "wget", "tree"]
case "22.04": case "22.04":
PACKAGES_TO_INSTALL = ["nfs-common", "xorriso", "genisoimage", "syslinux", "liblzma-dev", "nginx", "arp-scan", "automake", "build-essential", "btrfs-progs", "composer", "curl", "ctorrent", "debootstrap", "g++-multilib", "gawk", "gettext", "graphviz", "grub-efi-amd64-signed", "jq", "libapache2-mod-php", "libdbi-dev", "libdbi1", "libev-dev", "libjansson-dev", "liblz4-tool", "libssl-dev", "moreutils", "netpipes", "php", "php-bcmath", "php-cli", "php-curl", "php-fpm", "php-gd", "php-json", "php-ldap", "php-mbstring", "php-mysql", "php8.1-common", "php-pear", "php-xml", "php-zip", "procps", "coreutils", "rsync", "samba", "schroot", "shim-signed", "squashfs-tools", "subversion", "tftpd-hpa", "udpcast", "unzip", "wakeonlan", "wget", "xinetd", "jq", "moreutils", "net-tools", "isolinux", "syslinux"] PACKAGES_TO_INSTALL = ["nfs-common", "xorriso", "genisoimage", "syslinux", "liblzma-dev", "nginx", "arp-scan", "automake", "build-essential", "btrfs-progs", "composer", "curl", "ctorrent", "debootstrap", "g++-multilib", "gawk", "gettext", "graphviz", "grub-efi-amd64-signed", "jq", "libapache2-mod-php", "libdbi-dev", "libdbi1", "libev-dev", "libjansson-dev", "liblz4-tool", "libssl-dev", "moreutils", "netpipes", "php", "php-bcmath", "php-cli", "php-curl", "php-fpm", "php-gd", "php-json", "php-ldap", "php-mbstring", "php-mysql", "php8.1-common", "php-pear", "php-xml", "php-zip", "procps", "coreutils", "rsync", "samba", "samba-common-bin", "schroot", "shim-signed", "squashfs-tools", "subversion", "tftpd-hpa", "udpcast", "unzip", "wakeonlan", "wget", "xinetd", "jq", "moreutils", "net-tools", "isolinux", "syslinux"]
case _: case _:
PACKAGES_TO_INSTALL = ["bash", "nc", "rsync"] PACKAGES_TO_INSTALL = ["bash", "nc", "rsync"]
case "suse": case "suse":
@ -193,7 +180,7 @@ def get_missing_packages():
def install_packages(missing, log_packages_file=f"/tmp/installed_packages.log"): def install_packages(missing, log_packages_file=f"/tmp/installed_packages.log"):
if not missing: if not missing:
logger.warning("All packages are already installed.") logger.info("All packages are already installed.")
return return
logger.info("Upgrading the system...") logger.info("Upgrading the system...")
original_debian_frontend = os.environ.get('DEBIAN_FRONTEND') original_debian_frontend = os.environ.get('DEBIAN_FRONTEND')
@ -295,13 +282,13 @@ def og_boot_create_dirs():
# Crear los directorios necesarios # Crear los directorios necesarios
os.makedirs(INSTALL_OGBOOT_TARGET, mode=0o750, exist_ok=True) os.makedirs(INSTALL_OGBOOT_TARGET, mode=0o750, exist_ok=True)
os.makedirs(os.path.join(INSTALL_OGBOOT_TARGET, "client"), mode=0o750, exist_ok=True) os.makedirs(os.path.join(INSTALL_OGBOOT_TARGET, "client"), mode=0o750, exist_ok=True)
os.makedirs("/opt/ogboot/tftpboot/", mode=0o750, exist_ok=True) # os.makedirs("/opt/ogboot/tftpboot/", mode=0o750, exist_ok=True)
os.makedirs("/opt/ogboot/tftpboot/ipxe_scripts", mode=0o750, exist_ok=True) # os.makedirs("/opt/ogboot/tftpboot/ipxe_scripts", mode=0o750, exist_ok=True)
os.makedirs("/opt/ogboot/tftpboot/ipxe_scripts/templates", mode=0o750, exist_ok=True) # os.makedirs("/opt/ogboot/tftpboot/ipxe_scripts/templates", mode=0o750, exist_ok=True)
# Cambiar el propietario de los directorios # Cambiar el propietario de los directorios
subprocess.run(["sudo", "chown", "-R", "ogboot:ogboot", INSTALL_OGBOOT_TARGET]) subprocess.run(["sudo", "chown", "-R", "ogboot:ogboot", INSTALL_OGBOOT_TARGET])
subprocess.run(["sudo", "chown", "-R", "ogboot:ogboot", "/opt/ogboot/tftpboot/"]) # subprocess.run(["sudo", "chown", "-R", "ogboot:ogboot", "/opt/ogboot/tftpboot/"])
logger.info(f"{INSTALL_OGBOOT_TARGET} directory created successfully.") logger.info(f"{INSTALL_OGBOOT_TARGET} directory created successfully.")
except OSError: except OSError:
@ -533,95 +520,98 @@ def run_command(command):
print(result.stdout) print(result.stdout)
def tftpConfigure(): def tftpConfigure():
global TFTPSERV, INETDSERV, TFTPCFGDIR global TFTPSERV, INETDSERV, TFTPCFGDIR
# Update the package list # Update the package list
#print("Updating 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 # Install tftpd-hpa in non-interactive mode
print("Installing tftpd-hpa...") print("Installing tftpd-hpa...")
run_command("sudo DEBIAN_FRONTEND=noninteractive apt install -y tftpd-hpa") run_command("sudo DEBIAN_FRONTEND=noninteractive apt install -y tftpd-hpa")
# Configure tftpd-hpa # Configure tftpd-hpa
print("Configuring tftpd-hpa...") print("Configuring tftpd-hpa...")
tftpd_config = """ tftpd_config = """
# /etc/default/tftpd-hpa # /etc/default/tftpd-hpa
TFTP_USERNAME="tftp" TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot" TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS="0.0.0.0:69" TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure" TFTP_OPTIONS="--secure"
""" """
with open("/tmp/tftpd-hpa", "w") as config_file: with open("/tmp/tftpd-hpa", "w") as config_file:
config_file.write(tftpd_config) config_file.write(tftpd_config)
run_command("sudo mv /tmp/tftpd-hpa /etc/default/tftpd-hpa") run_command("sudo mv /tmp/tftpd-hpa /etc/default/tftpd-hpa")
# Create and set permissions for the TFTP directory # Create and set permissions for the TFTP directory
print("Creating and setting 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 mkdir -p /var/lib/tftpboot")
run_command("sudo chown -R tftp:tftp /var/lib/tftpboot") run_command("sudo chown -R tftp:tftp /var/lib/tftpboot")
run_command("sudo chmod -R 755 /var/lib/tftpboot") run_command("sudo chmod -R 755 /var/lib/tftpboot")
# Restart the tftpd-hpa service # Restart the tftpd-hpa service
print("Restarting tftpd-hpa service...") print("Restarting tftpd-hpa service...")
run_command("sudo systemctl restart tftpd-hpa") run_command("sudo systemctl restart tftpd-hpa")
# Check the status of the tftpd-hpa service # Check the status of the tftpd-hpa service
print("Checking tftpd-hpa service status...") print("Checking tftpd-hpa service status...")
run_command("sudo systemctl status tftpd-hpa") run_command("sudo systemctl status tftpd-hpa")
# if TFTPSERV: # if TFTPSERV:
# logger.info(f"TFTPSERV is configured: {TFTPSERV}") # logger.info(f"TFTPSERV is configured: {TFTPSERV}")
# inetd_cfg_path = f"{INETDCFGDIR}/{TFTPSERV}" # inetd_cfg_path = f"{INETDCFGDIR}/{TFTPSERV}"
# if os.path.isfile(inetd_cfg_path): # if os.path.isfile(inetd_cfg_path):
# logger.error(f"The inetd configuration file exists: {inetd_cfg_path}") # logger.error(f"The inetd configuration file exists: {inetd_cfg_path}")
# with open(inetd_cfg_path, "r+") as file: # with open(inetd_cfg_path, "r+") as file:
# content = file.read() # content = file.read()
# new_content = content.replace("disable.*", "disable = no") # new_content = content.replace("disable.*", "disable = no")
# file.seek(0) # file.seek(0)
# file.write(new_content) # file.write(new_content)
# file.truncate() # file.truncate()
# logger.info(f"Modified inetd configuration file: {inetd_cfg_path}") # logger.info(f"Modified inetd configuration file: {inetd_cfg_path}")
# else: # else:
# service = TFTPSERV # service = TFTPSERV
# logger.info(f"Enabling and starting the service {service}.service") # logger.info(f"Enabling and starting the service {service}.service")
# subprocess.run(["systemctl", "enable", f"{service}.service"], check=True) # subprocess.run(["systemctl", "enable", f"{service}.service"], check=True)
# subprocess.run(["systemctl", "start", f"{service}.service"], check=True) # subprocess.run(["systemctl", "start", f"{service}.service"], check=True)
# service = INETDSERV # service = INETDSERV
# logger.info(f"Enabling and starting the service {service}.service") # logger.info(f"Enabling and starting the service {service}.service")
#subprocess.run(["systemctl", "enable", f"{service}.service"], check=True) #subprocess.run(["systemctl", "enable", f"{service}.service"], check=True)
# subprocess.run(["systemctl", "start", f"{service}.service"], check=True) # subprocess.run(["systemctl", "start", f"{service}.service"], check=True)
#Crear directorio /var/lib/tftpboot #Crear directorio /var/lib/tftpboot
if not os.path.exists(TFTPCFGDIR): if not os.path.exists(TFTPCFGDIR):
os.makedirs(TFTPCFGDIR, mode=0o750, exist_ok=True) os.makedirs(TFTPCFGDIR, mode=0o750, exist_ok=True)
logger.info(f"Directory {TFTPCFGDIR} created.") logger.info(f"Directory {TFTPCFGDIR} created.")
else: else:
logger.warning(f"Directory {TFTPCFGDIR} exist.") logger.warning(f"Directory {TFTPCFGDIR} exist.")
#Descargar oglive #Descargar oglive
logger.info("Downloading oglive...") logger.info("Downloading oglive...")
#Temporalmente se copia desde ~/oglive #Temporalmente se copia desde ~/oglive
# copiar desde el montaje /mnt/srv/artefactos/ogboot/tftpboot/ # copiar desde el montaje /mnt/srv/artefactos/ogboot/tftpboot/
subprocess.run(["cp", "-r", f"/tmp/tftpboot/ogLive-5.11.0-r20210413", f"{TFTPCFGDIR}/"]) subprocess.run(["cp", "-r", f"/tmp/tftpboot/ogLive-5.11.0-r20210413", f"{TFTPCFGDIR}/"])
# subprocess.run(["cp", "-r", f"/tmp/ipxe/tftpboot/ipxe", f"{TFTPCFGDIR}/"]) # subprocess.run(["cp", "-r", f"/tmp/ipxe/tftpboot/ipxe", f"{TFTPCFGDIR}/"])
#Crear enlace simbólico de oglive-5.11.0-r20210413 a /var/lib/tftpboot/ogLive #Crear enlace simbólico de oglive-5.11.0-r20210413 a /var/lib/tftpboot/ogLive
subprocess.run(["ln", "-s", f"{TFTPCFGDIR}/ogLive-5.11.0-r20210413", f"{TFTPCFGDIR}/ogLive"]) subprocess.run(["ln", "-s", f"{TFTPCFGDIR}/ogLive-5.11.0-r20210413", f"{TFTPCFGDIR}/ogLive"])
#Crear enlace simbólico de /var/lib/tftpboot/ogLive a /var/lib/tftpboot/ogLive/ogclient #Crear enlace simbólico de /var/lib/tftpboot/ogLive a /var/lib/tftpboot/ogLive/ogclient
subprocess.run(["ln", "-s", f"{TFTPCFGDIR}/ogLive", f"{TFTPCFGDIR}/ogclient"]) subprocess.run(["ln", "-s", f"{TFTPCFGDIR}/ogLive", f"{TFTPCFGDIR}/ogclient"])
symlink_target = f"{INSTALL_OGBOOT_TARGET}/tftpboot"
symlink_target = f"{INSTALL_OGBOOT_TARGET}/tftpboot" logger.info(f"Creating symbolic link from {TFTPCFGDIR} to {symlink_target}")
logger.info(f"Creating symbolic link from {TFTPCFGDIR} to {symlink_target}") if not os.path.exists(symlink_target):
if not os.path.exists(symlink_target): os.symlink(TFTPCFGDIR, symlink_target)
os.symlink(TFTPCFGDIR, symlink_target) os.lchown(symlink_target, pwd.getpwnam("ogboot").pw_uid, pwd.getpwnam("ogboot").pw_gid)
os.chown(symlink_target, pwd.getpwnam("ogboot").pw_uid, pwd.getpwnam("ogboot").pw_gid) else:
else: logger.warning(f"The symbolic link already exists: {symlink_target}")
logger.warning(f"The symbolic link already exists: {symlink_target}") #----------------------------------------------------------------------------------------------
#logger.info("Creating symbolic link from /opt/ogboot/tftpboot to /var/lib/tftpboot...") #----------------------------------------------------------------------------------------------
#if os.path.islink(symlink_target): #logger.info("Creating symbolic link from /opt/ogboot/tftpboot to /var/lib/tftpboot...")
# run_command(f"sudo rm -rf {symlink_target}") #if os.path.islink(symlink_target):
#elif os.path.exists(symlink_target): # run_command(f"sudo rm -rf {symlink_target}")
# run_command(f"sudo ln -s {TFTPCFGDIR} {INSTALL_OGBOOT_TARGET}") #elif os.path.exists(symlink_target):
# run_command(f"sudo ln -s {TFTPCFGDIR} {INSTALL_OGBOOT_TARGET}")
#----------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------
def servicesCompilation(): def servicesCompilation():
global WORKDIR global WORKDIR
@ -746,7 +736,7 @@ def openGnsysConfigure():
else: else:
try: try:
os.symlink(f"{INSTALL_TARGET}/client/etc/ogAdmClient-{DEFAULTDEV}.cfg", f"{INSTALL_TARGET}/client/etc/ogAdmClient.cfg") os.symlink(f"{INSTALL_TARGET}/client/etc/ogAdmClient-{DEFAULTDEV}.cfg", f"{INSTALL_TARGET}/client/etc/ogAdmClient.cfg")
print(f"Symbolic link created: {INSTALL_TARGET}/client/etc/ogAdmClient-{DEFAULTDEV}.cfg -> {INSTALL_TARGET}/client/etc/ogAdmClient.cfg") logger.info (f"Symbolic link created: {INSTALL_TARGET}/client/etc/ogAdmClient-{DEFAULTDEV}.cfg -> {INSTALL_TARGET}/client/etc/ogAdmClient.cfg")
except OSError as e: except OSError as e:
logger.error(f"Error creating symbolic link: {e}") logger.error(f"Error creating symbolic link: {e}")
TZ = subprocess.check_output(["timedatectl", "status"]).decode().split("\n")[2].split(":")[1].strip() TZ = subprocess.check_output(["timedatectl", "status"]).decode().split("\n")[2].split(":")[1].strip()
@ -782,13 +772,15 @@ def mount_NFS():
if not os.path.exists("/opt/opengnsys"): if not os.path.exists("/opt/opengnsys"):
os.symlink("/opt/ogboot/", "/opt/opengnsys") os.symlink("/opt/ogboot/", "/opt/opengnsys")
logger.info("Symbolic link created successfully.") logger.info("Symbolic link created successfully.")
#logger.info(f"copy ipxe(2):::::::::::::::::::::::::::: EMBED={INSTALL_OPENGNSYS_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe")
#if subprocess.call(["sudo", "make", "-s", "bin/undionly.kpxe", f"EMBED={INSTALL_OPENGNSYS_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"]) == 0: #if subprocess.call(["sudo", "make", "-s", "bin/undionly.kpxe", f"EMBED={INSTALL_OPENGNSYS_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"]) == 0:
# logger.info("Boot file mounted correctly.") # logger.info("Boot file mounted correctly.")
#else: #else:
# logger.error("Failed to mount boot file.") # logger.error("Failed to mount boot file.")
# exit(1) # exit(1)
logger.info("Copiando undionly.kpxe con usuario ogboot:")
subprocess.call(["sudo", "cp", "bin/undionly.kpxe", f"{INSTALL_OPENGNSYS_TARGET}/tftpboot"]) subprocess.call(["sudo", "cp", "bin/undionly.kpxe", f"{INSTALL_OPENGNSYS_TARGET}/tftpboot"])
subprocess.call(["sudo", "chown", "ogboot:ogboot", f"{INSTALL_OPENGNSYS_TARGET}/tftpboot"])
logger.info("Generando make de ipxe.efi:")
if subprocess.call(["sudo", "make", "-s", "bin-x86_64-efi/ipxe.efi", f"EMBED={INSTALL_OPENGNSYS_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"]) == 0: if subprocess.call(["sudo", "make", "-s", "bin-x86_64-efi/ipxe.efi", f"EMBED={INSTALL_OPENGNSYS_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"]) == 0:
logger.info("Properly constructed EFI file.") logger.info("Properly constructed EFI file.")
else: else:
@ -839,7 +831,9 @@ def smbConfigure():
with open(f"{SAMBACFGDIR}/smb.conf", "a") as file: with open(f"{SAMBACFGDIR}/smb.conf", "a") as file:
file.write(f"include = {SAMBACFGDIR}/smb-ogboot.conf\n") file.write(f"include = {SAMBACFGDIR}/smb-ogboot.conf\n")
service = SAMBASERV service = SAMBASERV
logger.info(f"Enabling {service} service.")
subprocess.run(["systemctl", "enable", f"{service}.service"]) subprocess.run(["systemctl", "enable", f"{service}.service"])
logger.info(f"Restarting {service} service.")
subprocess.run(["systemctl", "restart", f"{service}.service"]) subprocess.run(["systemctl", "restart", f"{service}.service"])
# Comprobar si se ha configurado correctamente Samba # Comprobar si se ha configurado correctamente Samba
if subprocess.run(["systemctl", "is-active", f"{service}.service"]).returncode == 0: if subprocess.run(["systemctl", "is-active", f"{service}.service"]).returncode == 0:
@ -847,22 +841,17 @@ def smbConfigure():
else: else:
logger.error(f"Failed to start {service} service.") logger.error(f"Failed to start {service} service.")
return 1 return 1
# Establecer la contraseña para el usuario opengnsys # Ejecutar el comando smbpasswd para agregar el usuario de Samba
smbpasswd_command = f"(echo {OPENGNSYS_CLIENT_PASSWD}; echo {OPENGNSYS_CLIENT_PASSWD}) | sudo smbpasswd -s -a {OPENGNSYS_CLIENT_USER}" try:
if "Python 3.7" in {PYTHON_VERSION}: process_add = subprocess.run(
result = subprocess.run(smbpasswd_command, shell=True, capture_output=True, text=True) ["sudo", "smbpasswd", "-a", OPENGNSYS_CLIENT_USER],
if result.returncode == 0: input=f"{OPENGNSYS_CLIENT_PASSWD}\n{OPENGNSYS_CLIENT_PASSWD}\n",
logger.info(f"The password for the user {OPENGNSYS_CLIENT_USER} has been set correctly..") text=True,
else: check=True
logger.error(f"Error setting password: {result.stderr}") )
else: logger.info(f"The password for the user {OPENGNSYS_CLIENT_USER} has been set correctly.")
process = subprocess.Popen(smbpasswd_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) except subprocess.CalledProcessError as e:
stdout, stderr = process.communicate() logger.error(f"Error setting password: {e}")
if process.returncode == 0:
logger.info(f"The password for the user {OPENGNSYS_CLIENT_USER} has been set correctly..")
else:
logger.error(f"Error setting password: {stderr}")
logger.info(f"Added Samba configuration.")
return 0 return 0
def setup_nginx(): def setup_nginx():
@ -1056,12 +1045,6 @@ else:
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)}") 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") os.symlink(os.path.dirname(PROGRAM_DIR), f"{WORKDIR}/ogboot")
#logger.info("Creating directories.")
#createDirs(INSTALL_TARGET)
#if os.system("echo $?") != 0:
# logger.error("Error while creating directory paths!")
# exit(1)
logger.info("Creating ogBoot project.") logger.info("Creating ogBoot project.")
og_core_create_user("ogboot") og_core_create_user("ogboot")
@ -1073,12 +1056,12 @@ og_boot_copy_files()
logger.info("Installing Symfony.") logger.info("Installing Symfony.")
og_boot_symfony_install() og_boot_symfony_install()
logger.info("Installing Composer.")
og_boot_composer_install() og_boot_composer_install()
logger.info("Configuring TFTP service.")
#if os.system("echo $?") != 0: tftpConfigure()
# logger.error("Error while creating skeleton directory!")
# exit(1)
logger.info("Configuring IPXE services") logger.info("Configuring IPXE services")
generate_ipxe_script() generate_ipxe_script()
@ -1086,9 +1069,6 @@ generate_ipxe_script()
logger.info("Setting up NFS system") logger.info("Setting up NFS system")
mount_NFS() mount_NFS()
logger.info("Configuring TFTP service.")
tftpConfigure()
logger.info("Compiling OpenGnsys services source code") logger.info("Compiling OpenGnsys services source code")
servicesCompilation() servicesCompilation()
if subprocess.run(["echo", "$?"]).returncode != 0: if subprocess.run(["echo", "$?"]).returncode != 0:
@ -1116,7 +1096,6 @@ modify_php_fpm_config()
if subprocess.run(["echo", "$?"]).returncode != 0: if subprocess.run(["echo", "$?"]).returncode != 0:
logger.error("Error configure php fpm") logger.error("Error configure php fpm")
logger.info("Configure ogboot daemon") logger.info("Configure ogboot daemon")
install_oglive_daemon() install_oglive_daemon()
if subprocess.run(["echo", "$?"]).returncode != 0: if subprocess.run(["echo", "$?"]).returncode != 0:
@ -1125,7 +1104,6 @@ if subprocess.run(["echo", "$?"]).returncode != 0:
logger.info("Configuring ogCore") logger.info("Configuring ogCore")
openGnsysConfigure() openGnsysConfigure()
logger.info("Configuring Samba") logger.info("Configuring Samba")
smbConfigure() smbConfigure()