Refs #202 add/remove packages

ogboot_installer
Antonio Guerrero 2024-07-11 18:34:34 +00:00
parent c64ad8cb21
commit c1782d25bf
2 changed files with 79 additions and 65 deletions

View File

@ -6,4 +6,4 @@
"ogBoot_GitRepo": "ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git", "ogBoot_GitRepo": "ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git",
"ogBootSambaUser": "ogboot", "ogBootSambaUser": "ogboot",
"ogBootSambaPass": "og" "ogBootSambaPass": "og"
} }

View File

@ -149,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", "samba-common-bin", "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", "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":
@ -175,7 +175,7 @@ def get_missing_packages():
for package in PACKAGES_TO_INSTALL: for package in PACKAGES_TO_INSTALL:
if not is_installed(package): if not is_installed(package):
faltantes.append(package) faltantes.append(package)
logger.info(f"::::::Package to install: {package}...") logger.info(f"Package to install: {package}...")
return faltantes return faltantes
def install_packages(missing, log_packages_file=f"/tmp/installed_packages.log"): def install_packages(missing, log_packages_file=f"/tmp/installed_packages.log"):
@ -410,45 +410,45 @@ 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 775 /var/lib/tftpboot") run_command("sudo chmod -R 775 /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}"
@ -468,42 +468,43 @@ TFTP_OPTIONS="--secure"
# 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=0o775, exist_ok=True) os.makedirs(TFTPCFGDIR, mode=0o775, exist_ok=True)
logger.info(f"Directory {TFTPCFGDIR} created.") subprocess.run(["chown", "-R", "tftp:ogboot", TFTPCFGDIR])
else: logger.info(f"Directory {TFTPCFGDIR} created.")
logger.warning(f"Directory {TFTPCFGDIR} exist.") else:
symlink_target = f"{INSTALL_OGBOOT_TARGET}/tftpboot" logger.warning(f"Directory {TFTPCFGDIR} exist.")
logger.info(f"Creating symbolic link from {TFTPCFGDIR} to {symlink_target}") symlink_target = f"{INSTALL_OGBOOT_TARGET}/tftpboot"
if not os.path.exists(symlink_target): logger.info(f"Creating symbolic link from {TFTPCFGDIR} to {symlink_target}")
os.symlink(TFTPCFGDIR, symlink_target) if not os.path.exists(symlink_target):
os.lchown(symlink_target, pwd.getpwnam("ogboot").pw_uid, pwd.getpwnam("ogboot").pw_gid) os.symlink(TFTPCFGDIR, symlink_target)
else: os.lchown(symlink_target, pwd.getpwnam("ogboot").pw_uid, pwd.getpwnam("ogboot").pw_gid)
logger.warning(f"The symbolic link already exists: {symlink_target}") else:
#Descargar oglive logger.warning(f"The symbolic link already exists: {symlink_target}")
logger.info("Downloading oglive...") #Descargar oglive
iso_name = "ogLive-focal-5.13.0-27-beta-amd64-r20210706.5b4bf5f.iso" logger.info("Downloading oglive...")
try: iso_name = "ogLive-focal-5.13.0-27-beta-amd64-r20210706.5b4bf5f.iso"
result = subprocess.run( try:
["sudo", "/opt/ogboot/bin/oglivecli", "download", iso_name], result = subprocess.run(
check=True, ["sudo", "/opt/ogboot/bin/oglivecli", "download", iso_name],
capture_output=True, check=True,
text=True capture_output=True,
) text=True
logger.info(f"oglivecli install output: {result.stdout}") )
except subprocess.CalledProcessError as e: logger.info(f"oglivecli install output: {result.stdout}")
logger.error(f"Failed to install ogLive client: {e.stderr}") except subprocess.CalledProcessError as e:
logger.error("Continuing with the installation...") logger.error(f"Failed to install ogLive client: {e.stderr}")
logger.error("Continuing with the installation...")
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
#logger.info("Creating symbolic link from /opt/ogboot/tftpboot to /var/lib/tftpboot...") #logger.info("Creating symbolic link from /opt/ogboot/tftpboot to /var/lib/tftpboot...")
#if os.path.islink(symlink_target): #if os.path.islink(symlink_target):
# run_command(f"sudo rm -rf {symlink_target}") # run_command(f"sudo rm -rf {symlink_target}")
#elif os.path.exists(symlink_target): #elif os.path.exists(symlink_target):
# run_command(f"sudo ln -s {TFTPCFGDIR} {INSTALL_OGBOOT_TARGET}") # run_command(f"sudo ln -s {TFTPCFGDIR} {INSTALL_OGBOOT_TARGET}")
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
@ -682,9 +683,21 @@ def mount_NFS():
exit(1) exit(1)
subprocess.call(["sudo", "cp", "bin-x86_64-efi/ipxe.efi", f"{INSTALL_OPENGNSYS_TARGET}/tftpboot"]) subprocess.call(["sudo", "cp", "bin-x86_64-efi/ipxe.efi", f"{INSTALL_OPENGNSYS_TARGET}/tftpboot"])
def get_ip_address(interface):
try:
result = subprocess.check_output(["ip", "addr", "show", interface]).decode()
for line in result.split('\n'):
if "inet " in line:
ip_address = line.strip().split()[1].split('/')[0]
return ip_address
except subprocess.CalledProcessError as e:
print(f"Error get address IP: {e}")
return None
def generate_ipxe_script(): def generate_ipxe_script():
global DEFAULTDEV, INSTALL_OGBOOT_TARGET, WORKDIR global DEFAULTDEV, INSTALL_OGBOOT_TARGET, WORKDIR
ip_address_server = subprocess.check_output(["ifconfig", DEFAULTDEV]).decode().split("\n")[1].split()[1] #ip_address_server = subprocess.check_output(["ifconfig", DEFAULTDEV]).decode().split("\n")[1].split()[1]
ip_address_server = get_ip_address(DEFAULTDEV)
template = os.path.join(WORKDIR, "ogboot/etc/dhcp_boot.ipxe.tmpl") template = os.path.join(WORKDIR, "ogboot/etc/dhcp_boot.ipxe.tmpl")
ipxe_output = f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe" ipxe_output = f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"
os.makedirs(os.path.dirname(ipxe_output), mode=0o775, exist_ok=True) os.makedirs(os.path.dirname(ipxe_output), mode=0o775, exist_ok=True)
@ -752,7 +765,8 @@ def setup_nginx():
global DEFAULTDEV, WORKDIR global DEFAULTDEV, WORKDIR
try: try:
# Obtener la IP del servidor # Obtener la IP del servidor
ip_address_server = subprocess.check_output(["ifconfig", DEFAULTDEV]).decode().split("\n")[1].split()[1] #ip_address_server = subprocess.check_output(["ifconfig", DEFAULTDEV]).decode().split("\n")[1].split()[1]
ip_address_server = get_ip_address(DEFAULTDEV)
php_version = get_php_fpm_version() php_version = get_php_fpm_version()
# Leer y modificar la plantilla de configuración de nginx # Leer y modificar la plantilla de configuración de nginx
@ -935,9 +949,9 @@ if REMOTE == 1:
exit(1) exit(1)
else: else:
if not os.path.exists(f"{WORKDIR}/ogboot"): if not os.path.exists(f"{WORKDIR}/ogboot"):
logger.warning(f"Does not exist {WORKDIR}/ogboot")
if not os.path.exists(WORKDIR): if not os.path.exists(WORKDIR):
os.makedirs(WORKDIR, mode=0o775, exist_ok=True) os.makedirs(WORKDIR, mode=0o775, exist_ok=True)
logger.info(f"Dir {WORKDIR}/ogboot created")
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")