Refs #202 add/remove packages
parent
c64ad8cb21
commit
c1782d25bf
|
@ -6,4 +6,4 @@
|
|||
"ogBoot_GitRepo": "ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git",
|
||||
"ogBootSambaUser": "ogboot",
|
||||
"ogBootSambaPass": "og"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ def get_missing_packages():
|
|||
case "18.04":
|
||||
PACKAGES_TO_INSTALL = ["nano", "wget", "tree"]
|
||||
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 _:
|
||||
PACKAGES_TO_INSTALL = ["bash", "nc", "rsync"]
|
||||
case "suse":
|
||||
|
@ -175,7 +175,7 @@ def get_missing_packages():
|
|||
for package in PACKAGES_TO_INSTALL:
|
||||
if not is_installed(package):
|
||||
faltantes.append(package)
|
||||
logger.info(f"::::::Package to install: {package}...")
|
||||
logger.info(f"Package to install: {package}...")
|
||||
return faltantes
|
||||
|
||||
def install_packages(missing, log_packages_file=f"/tmp/installed_packages.log"):
|
||||
|
@ -410,45 +410,45 @@ def run_command(command):
|
|||
print(result.stdout)
|
||||
|
||||
def tftpConfigure():
|
||||
global TFTPSERV, INETDSERV, TFTPCFGDIR
|
||||
global TFTPSERV, INETDSERV, TFTPCFGDIR
|
||||
# Update the package list
|
||||
#print("Updating package list...")
|
||||
run_command("sudo apt update")
|
||||
#print("Updating package list...")
|
||||
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
|
||||
print("Installing tftpd-hpa...")
|
||||
run_command("sudo DEBIAN_FRONTEND=noninteractive apt install -y tftpd-hpa")
|
||||
# Install tftpd-hpa in non-interactive mode
|
||||
print("Installing tftpd-hpa...")
|
||||
run_command("sudo DEBIAN_FRONTEND=noninteractive apt install -y tftpd-hpa")
|
||||
|
||||
# Configure tftpd-hpa
|
||||
print("Configuring tftpd-hpa...")
|
||||
tftpd_config = """
|
||||
# /etc/default/tftpd-hpa
|
||||
# Configure tftpd-hpa
|
||||
print("Configuring tftpd-hpa...")
|
||||
tftpd_config = """
|
||||
# /etc/default/tftpd-hpa
|
||||
|
||||
TFTP_USERNAME="tftp"
|
||||
TFTP_DIRECTORY="/var/lib/tftpboot"
|
||||
TFTP_ADDRESS="0.0.0.0:69"
|
||||
TFTP_OPTIONS="--secure"
|
||||
"""
|
||||
with open("/tmp/tftpd-hpa", "w") as config_file:
|
||||
config_file.write(tftpd_config)
|
||||
"""
|
||||
with open("/tmp/tftpd-hpa", "w") as config_file:
|
||||
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
|
||||
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 775 /var/lib/tftpboot")
|
||||
# Create and set 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 chown -R tftp:tftp /var/lib/tftpboot")
|
||||
run_command("sudo chmod -R 775 /var/lib/tftpboot")
|
||||
|
||||
# Restart the tftpd-hpa service
|
||||
print("Restarting tftpd-hpa service...")
|
||||
run_command("sudo systemctl restart tftpd-hpa")
|
||||
# Restart the tftpd-hpa service
|
||||
print("Restarting tftpd-hpa service...")
|
||||
run_command("sudo systemctl restart tftpd-hpa")
|
||||
|
||||
# Check the status of the tftpd-hpa service
|
||||
print("Checking tftpd-hpa service status...")
|
||||
run_command("sudo systemctl status tftpd-hpa")
|
||||
# Check the status of the tftpd-hpa service
|
||||
print("Checking tftpd-hpa service status...")
|
||||
run_command("sudo systemctl status tftpd-hpa")
|
||||
# if TFTPSERV:
|
||||
# logger.info(f"TFTPSERV is configured: {TFTPSERV}")
|
||||
# inetd_cfg_path = f"{INETDCFGDIR}/{TFTPSERV}"
|
||||
|
@ -468,42 +468,43 @@ TFTP_OPTIONS="--secure"
|
|||
# subprocess.run(["systemctl", "start", f"{service}.service"], check=True)
|
||||
# service = INETDSERV
|
||||
# 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)
|
||||
#Crear directorio /var/lib/tftpboot
|
||||
if not os.path.exists(TFTPCFGDIR):
|
||||
os.makedirs(TFTPCFGDIR, mode=0o775, exist_ok=True)
|
||||
logger.info(f"Directory {TFTPCFGDIR} created.")
|
||||
else:
|
||||
logger.warning(f"Directory {TFTPCFGDIR} exist.")
|
||||
symlink_target = f"{INSTALL_OGBOOT_TARGET}/tftpboot"
|
||||
logger.info(f"Creating symbolic link from {TFTPCFGDIR} to {symlink_target}")
|
||||
if not os.path.exists(symlink_target):
|
||||
os.symlink(TFTPCFGDIR, symlink_target)
|
||||
os.lchown(symlink_target, pwd.getpwnam("ogboot").pw_uid, pwd.getpwnam("ogboot").pw_gid)
|
||||
else:
|
||||
logger.warning(f"The symbolic link already exists: {symlink_target}")
|
||||
#Descargar oglive
|
||||
logger.info("Downloading oglive...")
|
||||
iso_name = "ogLive-focal-5.13.0-27-beta-amd64-r20210706.5b4bf5f.iso"
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["sudo", "/opt/ogboot/bin/oglivecli", "download", iso_name],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
logger.info(f"oglivecli install output: {result.stdout}")
|
||||
except subprocess.CalledProcessError as e:
|
||||
logger.error(f"Failed to install ogLive client: {e.stderr}")
|
||||
logger.error("Continuing with the installation...")
|
||||
#Crear directorio /var/lib/tftpboot
|
||||
if not os.path.exists(TFTPCFGDIR):
|
||||
os.makedirs(TFTPCFGDIR, mode=0o775, exist_ok=True)
|
||||
subprocess.run(["chown", "-R", "tftp:ogboot", TFTPCFGDIR])
|
||||
logger.info(f"Directory {TFTPCFGDIR} created.")
|
||||
else:
|
||||
logger.warning(f"Directory {TFTPCFGDIR} exist.")
|
||||
symlink_target = f"{INSTALL_OGBOOT_TARGET}/tftpboot"
|
||||
logger.info(f"Creating symbolic link from {TFTPCFGDIR} to {symlink_target}")
|
||||
if not os.path.exists(symlink_target):
|
||||
os.symlink(TFTPCFGDIR, symlink_target)
|
||||
os.lchown(symlink_target, pwd.getpwnam("ogboot").pw_uid, pwd.getpwnam("ogboot").pw_gid)
|
||||
else:
|
||||
logger.warning(f"The symbolic link already exists: {symlink_target}")
|
||||
#Descargar oglive
|
||||
logger.info("Downloading oglive...")
|
||||
iso_name = "ogLive-focal-5.13.0-27-beta-amd64-r20210706.5b4bf5f.iso"
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["sudo", "/opt/ogboot/bin/oglivecli", "download", iso_name],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
logger.info(f"oglivecli install output: {result.stdout}")
|
||||
except subprocess.CalledProcessError as e:
|
||||
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...")
|
||||
#if os.path.islink(symlink_target):
|
||||
# run_command(f"sudo rm -rf {symlink_target}")
|
||||
#elif os.path.exists(symlink_target):
|
||||
# run_command(f"sudo ln -s {TFTPCFGDIR} {INSTALL_OGBOOT_TARGET}")
|
||||
#logger.info("Creating symbolic link from /opt/ogboot/tftpboot to /var/lib/tftpboot...")
|
||||
#if os.path.islink(symlink_target):
|
||||
# run_command(f"sudo rm -rf {symlink_target}")
|
||||
#elif os.path.exists(symlink_target):
|
||||
# run_command(f"sudo ln -s {TFTPCFGDIR} {INSTALL_OGBOOT_TARGET}")
|
||||
#----------------------------------------------------------------------------------------------
|
||||
#----------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -682,9 +683,21 @@ def mount_NFS():
|
|||
exit(1)
|
||||
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():
|
||||
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")
|
||||
ipxe_output = f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"
|
||||
os.makedirs(os.path.dirname(ipxe_output), mode=0o775, exist_ok=True)
|
||||
|
@ -752,7 +765,8 @@ def setup_nginx():
|
|||
global DEFAULTDEV, WORKDIR
|
||||
try:
|
||||
# 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()
|
||||
|
||||
# Leer y modificar la plantilla de configuración de nginx
|
||||
|
@ -935,9 +949,9 @@ if REMOTE == 1:
|
|||
exit(1)
|
||||
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=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)}")
|
||||
os.symlink(os.path.dirname(PROGRAM_DIR), f"{WORKDIR}/ogboot")
|
||||
|
||||
|
|
Loading…
Reference in New Issue