refs #1016 build ipxe in a tempdir

pull/5/head
Natalia Serrano 2024-10-22 11:18:32 +00:00
parent d89320ea09
commit dd44a43ec2
1 changed files with 44 additions and 46 deletions

View File

@ -7,6 +7,7 @@
##################################################################################
import platform, os, sys, subprocess, datetime, shutil, pwd, glob, logging, distro, re, json
import tempfile
ipxe_repo_url = "https://github.com/ipxe/ipxe.git"
oglive_iso_url = "https://ognproject.evlt.uma.es/trac/downloads/ogLive-focal-5.13.0-27-beta-amd64-r20210706.5b4bf5f.iso"
@ -26,7 +27,6 @@ OGCORE_IP = config["ogCore_ServerIP"]
INSTALL_OGBOOT_TARGET = config["ogBoot_Dir"]
OPENGNSYS_CLIENT_USER = config["ogBootSambaUser"]
OPENGNSYS_CLIENT_PASSWD = config["ogBootSambaPass"]
IPXE_DIR = "/tmp/ogboot_ipxe"
DEFAULTDEV = ""
DEVICE = []
@ -482,57 +482,53 @@ def tzConfigure():
file.write(f"# OpenGnsys Server timezone.\nTZ=\"{TZ}\"\n")
def install_ipxe():
clone_dir = "/tmp/ogboot_ipxe"
if os.path.exists (f"{INSTALL_OGBOOT_TARGET}/tftpboot/undionly.kpxe"):
logger.info ('iPXE already present--not compiling again')
return
return True
# Clonar el repositorio desde Gitea
logger.info(f"Clonando el repositorio {ipxe_repo_url}")
if subprocess.call(["git", "-c", "http.sslVerify=false", "clone", ipxe_repo_url, clone_dir]) == 0:
logger.info("Repositorio clonado correctamente.")
else:
logger.error(f"ERROR\tNo se pudo clonar el repositorio {ipxe_repo_url}.")
exit(1)
with tempfile.TemporaryDirectory() as clone_dir:
logger.info(f"Clonando el repositorio {ipxe_repo_url}")
if subprocess.call(["git", "-c", "http.sslVerify=false", "clone", ipxe_repo_url, clone_dir]) == 0:
logger.info("Repositorio clonado correctamente.")
else:
logger.error(f"ERROR\tNo se pudo clonar el repositorio {ipxe_repo_url}.")
return False
# Ejecutar el comando make en el directorio src
#logger.info(f"Ejecutando make en {IPXE_DIR}/src")
os.chdir(f"{IPXE_DIR}/src")
#if subprocess.run(["make", "-s", "-j", "4"], capture_output=True).returncode == 0:
# logger.info(f"Directorio {IPXE_DIR}/src correctamente compilado.")
#else:
# logger.error(f"ERROR\tNo se pudo compilar el directorio {IPXE_DIR}/src.")
# exit(1)
# Ejecutar el comando make en el directorio src
#logger.info(f"Ejecutando make en {clone_dir}/src")
os.chdir(f"{clone_dir}/src")
#if subprocess.run(["make", "-s", "-j", "4"], capture_output=True).returncode == 0:
# logger.info(f"Directorio {clone_dir}/src correctamente compilado.")
#else:
# logger.error(f"ERROR\tNo se pudo compilar el directorio {clone_dir}/src.")
# return False
logger.info("Generando make de undionly.kpxe:")
if subprocess.run(["make", "-s", "bin/undionly.kpxe", f"EMBED={INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"], capture_output=True).returncode == 0:
logger.info("Boot file mounted correctly.")
else:
logger.error("Failed to mount boot file.")
exit(1)
logger.info("Copiando undionly.kpxe con usuario ogboot:")
subprocess.call(["cp", "bin/undionly.kpxe", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
subprocess.call(["chown", "ogboot:ogboot", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
logger.info("Generando make de undionly.kpxe:")
if subprocess.run(["make", "-s", "bin/undionly.kpxe", f"EMBED={INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"], capture_output=True).returncode == 0:
logger.info("Boot file mounted correctly.")
else:
logger.error("Failed to mount boot file.")
return False
logger.info("Copiando undionly.kpxe con usuario ogboot:")
subprocess.call(["cp", "bin/undionly.kpxe", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
subprocess.call(["chown", "ogboot:ogboot", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
logger.info("Generando make de ipxe.efi:")
if subprocess.run(["make", "-s", "bin-x86_64-efi/ipxe.efi", f"EMBED={INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"], capture_output=True).returncode == 0:
logger.info("Properly constructed EFI file.")
else:
logger.error("Could not build EFI file.")
exit(1)
subprocess.call(["cp", "bin-x86_64-efi/ipxe.efi", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
subprocess.call(["chown", "-R", "tftp:ogboot", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
subprocess.run(["chmod", "-R", "775", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
os.makedirs(f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates", exist_ok=True)
subprocess.call(["chown", "-R", "tftp:ogboot", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
subprocess.call(["chmod", "-R", "775", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
subprocess.call(["cp", f"{REPO_DIR}/tftpboot/ipxe_scripts/templates/pxe_default", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
subprocess.call(["rm", "-rf", clone_dir])
logger.info("Generando make de ipxe.efi:")
if subprocess.run(["make", "-s", "bin-x86_64-efi/ipxe.efi", f"EMBED={INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"], capture_output=True).returncode == 0:
logger.info("Properly constructed EFI file.")
else:
logger.error("Could not build EFI file.")
return False
subprocess.call(["cp", "bin-x86_64-efi/ipxe.efi", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
subprocess.call(["chown", "-R", "tftp:ogboot", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
subprocess.run(["chmod", "-R", "775", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
os.makedirs(f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates", exist_ok=True)
subprocess.call(["chown", "-R", "tftp:ogboot", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
subprocess.call(["chmod", "-R", "775", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
subprocess.call(["cp", f"{REPO_DIR}/tftpboot/ipxe_scripts/templates/pxe_default", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
return True
def get_ip_address(interface):
try:
@ -847,9 +843,11 @@ except Exception as e:
try:
logger.info("Installing iPXE")
install_ipxe()
if not install_ipxe():
logger.error(f"Error installing iPXE: {e}")
exit(1)
except Exception as e:
logger.error(f"Error setting up NFS system: {e}")
logger.error(f"Error installing iPXE: {e}")
exit(1)
try: