Refs #202 adds EMBED script to ipxe make
parent
744218ab2b
commit
7a5d2b2c7b
|
@ -58,7 +58,7 @@ log_file = f'/var/log/{PROGRAM}.log'
|
|||
os.makedirs(os.path.dirname(log_file), exist_ok=True)
|
||||
subprocess.run(['sudo', 'touch', log_file])
|
||||
#subprocess.run(['sudo', 'chown', 'ogboot', log_file])
|
||||
subprocess.run(['sudo', 'chmod', '777', log_file])
|
||||
subprocess.run(['sudo', 'chmod', '775', log_file])
|
||||
|
||||
#Configure the log
|
||||
logging.basicConfig(level=logging.DEBUG,
|
||||
|
@ -212,23 +212,10 @@ def autoConfigure():
|
|||
logger.info(f"OSVERSION: {OSVERSION}")
|
||||
# Configuración según la distribución OSDISTRIB
|
||||
|
||||
def generate_config_url():
|
||||
with open('/etc/os-release', 'r') as file:
|
||||
lines = file.readlines()
|
||||
codename = None
|
||||
version = None
|
||||
for line in lines:
|
||||
if line.startswith('VERSION_CODENAME') or line.startswith('UBUNTU_CODENAME'):
|
||||
codename = line.split('=')[1].strip().strip('"')
|
||||
elif line.startswith('VERSION_ID'):
|
||||
version = line.split('=')[1].strip().strip('"')
|
||||
arch = os.uname().machine
|
||||
return f"https://dl.cloudsmith.io/public/isc/kea-2-0/config.deb.txt?distro=ubuntu&codename={codename}&version={version}&arch={arch}"
|
||||
|
||||
def downloadComposer():
|
||||
global WORKDIR, INSTALL_OGBOOT_TARGET
|
||||
logger.info("Downloading composer.phar...")
|
||||
os.makedirs(os.path.join(WORKDIR, "ogboot", "bin"), mode=0o750, exist_ok=True)
|
||||
os.makedirs(os.path.join(WORKDIR, "ogboot", "bin"), mode=0o775, exist_ok=True)
|
||||
subprocess.run(["curl", "-sS", "-o", os.path.join(WORKDIR, "ogboot", "bin", "composer.phar"), "https://getcomposer.org/installer"], check=True)
|
||||
if not os.path.isfile(os.path.join(WORKDIR, "ogboot", "bin", "composer.phar")):
|
||||
logger.error("Failed to download composer.phar")
|
||||
|
@ -280,8 +267,8 @@ def og_boot_create_dirs():
|
|||
else:
|
||||
try:
|
||||
# Crear los directorios necesarios
|
||||
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(INSTALL_OGBOOT_TARGET, mode=0o775, exist_ok=True)
|
||||
os.makedirs(os.path.join(INSTALL_OGBOOT_TARGET, "client"), mode=0o775, 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/templates", mode=0o750, exist_ok=True)
|
||||
|
@ -352,11 +339,11 @@ def og_boot_copy_files():
|
|||
shutil.rmtree(lib_dest)
|
||||
shutil.copytree(lib_source, lib_dest)
|
||||
|
||||
os.makedirs(os.path.join(INSTALL_TARGET, "etc"), mode=0o750, exist_ok=True)
|
||||
os.makedirs(os.path.join(INSTALL_TARGET, "client"), mode=0o750, exist_ok=True)
|
||||
os.makedirs(os.path.join(INSTALL_TARGET, "public"), mode=0o750, exist_ok=True)
|
||||
os.makedirs(os.path.join(INSTALL_TARGET, "etc"), mode=0o775, exist_ok=True)
|
||||
os.makedirs(os.path.join(INSTALL_TARGET, "client"), mode=0o775, exist_ok=True)
|
||||
os.makedirs(os.path.join(INSTALL_TARGET, "public"), mode=0o775, exist_ok=True)
|
||||
|
||||
subprocess.run(["sudo", "chmod", "-R", "755", INSTALL_OGBOOT_TARGET])
|
||||
subprocess.run(["sudo", "chmod", "-R", "775", INSTALL_OGBOOT_TARGET])
|
||||
subprocess.run(["sudo", "chown", "-R", "ogboot:ogboot", INSTALL_OGBOOT_TARGET])
|
||||
|
||||
def og_boot_composer_install():
|
||||
|
@ -391,64 +378,6 @@ def og_boot_composer_install():
|
|||
###:::::::::::::::::::::::::::: CONFIGURE ::::::::::::::::::::::::::::::::::###
|
||||
###############################################################################
|
||||
|
||||
def install_isc_kea():
|
||||
url = generate_config_url()
|
||||
print(f"URL generada: {url}")
|
||||
print("Ejecutando curl para obtener el archivo de configuración del repositorio KEA...")
|
||||
subprocess.run(["curl", "-1sLf", url, ">", "/etc/apt/sources.list.d/isc-kea-2-0.list"], check=True)
|
||||
print("El archivo de configuración del repositorio KEA ha sido guardado en /etc/apt/sources.list.d/isc-kea-2-0.list")
|
||||
|
||||
print("Descargando y agregando la clave GPG del repositorio KEA...")
|
||||
subprocess.run(["curl", "-1sLf", "https://dl.cloudsmith.io/public/isc/kea-2-0/gpg.8029D4AFA58CBB5E.key", "|", "gpg", "--dearmor", ">>", "/usr/share/keyrings/isc-kea-2-0-archive-keyring.gpg"], check=True)
|
||||
print("La clave GPG del repositorio KEA ha sido descargada y agregada correctamente")
|
||||
|
||||
print("Ejecutando apt-get update...")
|
||||
subprocess.run(["apt-get", "update"], check=True)
|
||||
|
||||
print("Comprobando disponibilidad de los paquetes...")
|
||||
if subprocess.run(["apt-cache", "show", "isc-kea-common"], capture_output=True).returncode == 0:
|
||||
print("El paquete isc-kea-common está disponible para ser instalado.")
|
||||
print("Descargando e instalando el paquete isc-kea-common...")
|
||||
subprocess.run(["apt-get", "install", "-y", "isc-kea-common"], check=True)
|
||||
print("El paquete isc-kea-common ha sido descargado e instalado correctamente.")
|
||||
else:
|
||||
print("El paquete isc-kea-common no está disponible en los repositorios apt.")
|
||||
|
||||
if subprocess.run(["apt-cache", "show", "isc-kea-dhcp4-server"], capture_output=True).returncode == 0:
|
||||
print("El paquete isc-kea-dhcp4-server está disponible para ser instalado.")
|
||||
print("Descargando e instalando el paquete isc-kea-dhcp4-server...")
|
||||
subprocess.run(["apt-get", "install", "-y", "isc-kea-dhcp4-server"], check=True)
|
||||
print("El paquete isc-kea-dhcp4-server ha sido descargado e instalado correctamente.")
|
||||
else:
|
||||
print("El paquete isc-kea-dhcp4-server no está disponible en los repositorios apt.")
|
||||
|
||||
if subprocess.run(["apt-cache", "show", "isc-kea-dhcp6-server"], capture_output=True).returncode == 0:
|
||||
print("El paquete isc-kea-dhcp6-server está disponible para ser instalado.")
|
||||
print("Descargando e instalando el paquete isc-kea-dhcp6-server...")
|
||||
subprocess.run(["apt-get", "install", "-y", "isc-kea-dhcp6-server"], check=True)
|
||||
print("El paquete isc-kea-dhcp6-server ha sido descargado e instalado correctamente.")
|
||||
else:
|
||||
print("El paquete isc-kea-dhcp6-server no está disponible en los repositorios apt.")
|
||||
|
||||
if subprocess.run(["apt-cache", "show", "isc-kea-dhcp-ddns-server"], capture_output=True).returncode == 0:
|
||||
print("El paquete isc-kea-dhcp-ddns-server está disponible para ser instalado.")
|
||||
print("Descargando e instalando el paquete isc-kea-dhcp-ddns-server...")
|
||||
subprocess.run(["apt-get", "install", "-y", "isc-kea-dhcp-ddns-server"], check=True)
|
||||
print("El paquete isc-kea-dhcp-ddns-server ha sido descargado e instalado correctamente.")
|
||||
else:
|
||||
print("El paquete isc-kea-dhcp-ddns-server no está disponible en los repositorios apt.")
|
||||
|
||||
if subprocess.run(["apt-cache", "show", "isc-kea-ctrl-agent"], capture_output=True).returncode == 0:
|
||||
print("El paquete isc-kea-ctrl-agent está disponible para ser instalado.")
|
||||
print("Descargando e instalando el paquete isc-kea-ctrl-agent...")
|
||||
subprocess.run(["apt-get", "install", "-y", "isc-kea-ctrl-agent"], check=True)
|
||||
print("El paquete isc-kea-ctrl-agent ha sido descargado e instalado correctamente.")
|
||||
else:
|
||||
print("El paquete isc-kea-ctrl-agent no está disponible en los repositorios apt.")
|
||||
|
||||
def install_kea():
|
||||
print(f"{install_kea.__name__}(): Instalación de muestra para el servicio DHCP de Kea.")
|
||||
|
||||
def backupFile(file):
|
||||
if not os.path.isfile(file):
|
||||
logger.warning(f"File {file} doesn't exist")
|
||||
|
@ -461,45 +390,6 @@ def backupFile(file):
|
|||
shutil.copy2(file, backup_file)
|
||||
logger.info(f"Backup of {file} successful")
|
||||
|
||||
def isc_keaDhcpConfigure():
|
||||
global DEVICE, NETMASK, NETIP, ROUTERIP, DNSIP, SERVERIP
|
||||
print(f"{isc_keaDhcpConfigure.__name__}(): Configuración de muestra para el servicio DHCP de Kea.")
|
||||
errcode = 0
|
||||
i = 0
|
||||
interfaces = "["
|
||||
#DEVICE = ["eth0", "eth1"] # Define the DEVICE variable with appropriate values
|
||||
#NETMASK = "255.255.255.0" # Replace with the actual value of NETMASK
|
||||
#NETIP = "192.168.0.1" # Replace with the actual value of NETIP
|
||||
#ROUTERIP = "192.168.0.1" # Replace with the actual value of ROUTERIP
|
||||
DNSIP = "192.168.0.1" # Replace with the actual value of DNSIP
|
||||
#SERVERIP = "192.168.0.1" # Replace with the actual value of SERVERIP
|
||||
# Rest of the code...
|
||||
# Define the NETMASK variable
|
||||
# Construir la lista de interfaces
|
||||
print(NETIP)
|
||||
print(NETMASK)
|
||||
#CIDR = mask2cidr(NETMASK)
|
||||
#print(CIDR) # Salida: 24
|
||||
print(ROUTERIP)
|
||||
print(DNSIP)
|
||||
with open("/etc/kea/kea-dhcp4.conf", "w") as file:
|
||||
file.write(
|
||||
f"""
|
||||
"interfaces": {interfaces},
|
||||
"SERVERIP": "{SERVERIP}",
|
||||
"NETIP": "{NETIP}",
|
||||
"NETMASK": "{NETMASK}",
|
||||
"ROUTERIP": "{ROUTERIP}",
|
||||
"DNSIP": "{DNSIP}"
|
||||
"""
|
||||
)
|
||||
# Si hubo errores al configurar, muestra un mensaje de error y sale de la función
|
||||
if errcode != 0:
|
||||
print(f"{isc_keaDhcpConfigure.__name__}(): Error al configurar el servicio DHCP de Kea.")
|
||||
return 1
|
||||
print(f"{isc_keaDhcpConfigure.__name__}(): Configuración de muestra para el servicio DHCP de Kea configurada en \"/etc/kea/kea-dhcp4.conf\".")
|
||||
return 0
|
||||
|
||||
def testPxe():
|
||||
global TFTPCFGDIR
|
||||
logger.info(f"Checking TFTP service... please wait.")
|
||||
|
@ -550,7 +440,7 @@ TFTP_OPTIONS="--secure"
|
|||
print("Creating and setting permissions for the TFTP directory...")
|
||||
run_command("sudo mkdir -p /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 775 /var/lib/tftpboot")
|
||||
|
||||
# Restart the tftpd-hpa service
|
||||
print("Restarting tftpd-hpa service...")
|
||||
|
@ -582,7 +472,7 @@ TFTP_OPTIONS="--secure"
|
|||
# subprocess.run(["systemctl", "start", f"{service}.service"], check=True)
|
||||
#Crear directorio /var/lib/tftpboot
|
||||
if not os.path.exists(TFTPCFGDIR):
|
||||
os.makedirs(TFTPCFGDIR, mode=0o750, exist_ok=True)
|
||||
os.makedirs(TFTPCFGDIR, mode=0o775, exist_ok=True)
|
||||
logger.info(f"Directory {TFTPCFGDIR} created.")
|
||||
else:
|
||||
logger.warning(f"Directory {TFTPCFGDIR} exist.")
|
||||
|
@ -648,7 +538,7 @@ def copyClientFiles():
|
|||
logger.error(f"Error while copying client structure: {file}")
|
||||
errstatus = 1
|
||||
logger.info(f"Copying OpenGnsys Cloning Engine files.")
|
||||
os.makedirs(f"{INSTALL_TARGET}/client/lib/engine/bin", mode=0o750, exist_ok=True)
|
||||
os.makedirs(f"{INSTALL_TARGET}/client/lib/engine/bin", mode=0o775, exist_ok=True)
|
||||
engine_files = glob.glob(f"{WORKDIR}/ogboot/client/engine/*.lib*")
|
||||
# Copiar cada archivo individualmente
|
||||
for file in engine_files:
|
||||
|
@ -776,11 +666,11 @@ def mount_NFS():
|
|||
if not os.path.exists("/opt/opengnsys"):
|
||||
os.symlink("/opt/ogboot/", "/opt/opengnsys")
|
||||
logger.info("Symbolic link created successfully.")
|
||||
#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.")
|
||||
#else:
|
||||
# logger.error("Failed to mount boot file.")
|
||||
# exit(1)
|
||||
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.")
|
||||
else:
|
||||
logger.error("Failed to mount boot file.")
|
||||
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", "chown", "ogboot:ogboot", f"{INSTALL_OPENGNSYS_TARGET}/tftpboot"])
|
||||
|
@ -797,7 +687,7 @@ def generate_ipxe_script():
|
|||
ip_address_server = subprocess.check_output(["ifconfig", DEFAULTDEV]).decode().split("\n")[1].split()[1]
|
||||
template = os.path.join(WORKDIR, "ogboot/etc/dhcp_boot.ipxe.tmpl")
|
||||
ipxe_output = f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"
|
||||
os.makedirs(os.path.dirname(ipxe_output), mode=0o750, exist_ok=True)
|
||||
os.makedirs(os.path.dirname(ipxe_output), mode=0o775, exist_ok=True)
|
||||
shutil.copy(template, ipxe_output)
|
||||
with open(ipxe_output, "r") as ipxe_file:
|
||||
ipxe_content = ipxe_file.read()
|
||||
|
@ -972,7 +862,7 @@ def install_oglive_daemon():
|
|||
logger.info(f"Copied {DAEMON_SCRIPT_SRC} to {DAEMON_SCRIPT_DEST}")
|
||||
|
||||
# Hacer el script ejecutable
|
||||
os.chmod(DAEMON_SCRIPT_DEST, 0o755)
|
||||
os.chmod(DAEMON_SCRIPT_DEST, 0o775)
|
||||
logger.info(f"Set executable permissions for {DAEMON_SCRIPT_DEST}")
|
||||
|
||||
# Copiar el archivo de servicio de systemd
|
||||
|
@ -1047,7 +937,7 @@ else:
|
|||
if not os.path.exists(f"{WORKDIR}/ogboot"):
|
||||
logger.warning(f"Does not exist {WORKDIR}/ogboot")
|
||||
if not os.path.exists(WORKDIR):
|
||||
os.makedirs(WORKDIR, mode=0o750, exist_ok=True)
|
||||
os.makedirs(WORKDIR, mode=0o775, exist_ok=True)
|
||||
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")
|
||||
|
||||
|
|
Loading…
Reference in New Issue