92 lines
3.2 KiB
Python
92 lines
3.2 KiB
Python
import os
|
|
import json
|
|
import subprocess
|
|
import logging
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
PROGRAM_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
config_file = os.path.join(PROGRAM_DIR, 'config.json')
|
|
with open(config_file, 'r') as f:
|
|
config = json.load(f)
|
|
|
|
INSTALL_OGBOOT_TARGET = config["ogBoot_Dir"]
|
|
|
|
|
|
def update_ipxe_boot_files():
|
|
"""
|
|
Actualiza los archivos de arranque iPXE.
|
|
"""
|
|
ipxe_repo_url = "https://github.com/ipxe/ipxe.git"
|
|
install_ogboot_target = INSTALL_OGBOOT_TARGET
|
|
cwd = os.getcwd()
|
|
clone_dir = "/tmp/ipxe_repo"
|
|
|
|
if not os.path.exists(clone_dir):
|
|
os.makedirs(clone_dir)
|
|
logger.info(f"Clonando el repositorio {ipxe_repo_url}")
|
|
clone_cmd = ["git", "-c", "http.sslVerify=false", "clone", ipxe_repo_url, clone_dir]
|
|
|
|
if subprocess.call(clone_cmd) == 0:
|
|
logger.info("Repositorio clonado correctamente.")
|
|
else:
|
|
logger.error(f"ERROR\tNo se pudo clonar el repositorio {ipxe_repo_url}.")
|
|
return False
|
|
else:
|
|
logger.info(f"Usando el repositorio clonado previamente en {clone_dir}")
|
|
|
|
os.chdir(f"{clone_dir}/src")
|
|
|
|
logger.info("Generando make de undionly.kpxe:")
|
|
undionly_cmd = [
|
|
"make", "-s", "bin/undionly.kpxe",
|
|
f"EMBED={install_ogboot_target}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"
|
|
]
|
|
if subprocess.run(undionly_cmd, capture_output=True).returncode == 0:
|
|
logger.info("Boot file undionly.kpxe generado correctamente.")
|
|
else:
|
|
logger.error("ERROR\tNo se pudo generar el archivo undionly.kpxe.")
|
|
return False
|
|
|
|
logger.info("Copiando undionly.kpxe al directorio de destino:")
|
|
dest_undionly = os.path.join(install_ogboot_target, "tftpboot")
|
|
if subprocess.call(["cp", "bin/undionly.kpxe", dest_undionly]) == 0:
|
|
logger.info(f"Archivo undionly.kpxe copiado a {dest_undionly}")
|
|
else:
|
|
logger.error("ERROR\tNo se pudo copiar el archivo undionly.kpxe.")
|
|
return False
|
|
|
|
logger.info("Generando make de ipxe.efi:")
|
|
ipxe_efi_cmd = [
|
|
"make", "-s", "bin-x86_64-efi/ipxe.efi",
|
|
f"EMBED={install_ogboot_target}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"
|
|
]
|
|
if subprocess.run(ipxe_efi_cmd, capture_output=True).returncode == 0:
|
|
logger.info("Archivo ipxe.efi generado correctamente.")
|
|
else:
|
|
logger.error("ERROR\tNo se pudo generar el archivo ipxe.efi.")
|
|
return False
|
|
|
|
logger.info("Copiando ipxe.efi al directorio de destino:")
|
|
dest_ipxe_efi = os.path.join(install_ogboot_target, "tftpboot")
|
|
if subprocess.call(["cp", "bin-x86_64-efi/ipxe.efi", dest_ipxe_efi]) == 0:
|
|
logger.info(f"Archivo ipxe.efi copiado a {dest_ipxe_efi}")
|
|
else:
|
|
logger.error("ERROR\tNo se pudo copiar el archivo ipxe.efi.")
|
|
return False
|
|
|
|
os.chdir(cwd)
|
|
logger.info("Proceso completado exitosamente.")
|
|
return True
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
if update_ipxe_boot_files():
|
|
logger.info("Archivos de arranque actualizados correctamente.")
|
|
else:
|
|
logger.error("Hubo un error durante la actualización de los archivos de arranque.")
|
|
except Exception as e:
|
|
logger.error(f"ERROR\tFallo crítico: {e}")
|