Refs #438 Add changes for Ubuntu 22.04
parent
0c6691ad4a
commit
dfa432fd66
|
|
@ -5,16 +5,26 @@
|
||||||
##### Autor: Antonio Emmanuel Guerrero Silva <aguerrero@qindel.com> ########
|
##### Autor: Antonio Emmanuel Guerrero Silva <aguerrero@qindel.com> ########
|
||||||
#################################################################################
|
#################################################################################
|
||||||
|
|
||||||
import platform, os, sys, subprocess, datetime, shutil, pwd, glob, zipfile, urllib.request, logging
|
import platform, os, sys, subprocess, datetime, shutil, pwd, glob, zipfile, urllib.request, logging, distro
|
||||||
|
|
||||||
global PACKAGES, UBUNTU_OS_VERSION, PYTHON_VERSION, INSTALL_OGBOOT_TARGET, PROGRAM_DIR, OPENGNSYS_SERVER
|
global PACKAGES, UBUNTU_OS_VERSION, PYTHON_VERSION, INSTALL_OGBOOT_TARGET, PROGRAM_DIR, OPENGNSYS_SERVER
|
||||||
|
|
||||||
|
# Reload variables from bashrc
|
||||||
|
subprocess.run(['source', '~/.bashrc'], shell=True)
|
||||||
|
|
||||||
# Leer variables de entorno
|
# Leer variables de entorno
|
||||||
env_ogCore_ServerIP = os.environ.get('OGCORE_SERVER_IP') #"172.17.8.82"
|
#env_ogCore_ServerIP = os.environ.get('OGCORE_SERVER_IP') #"172.17.8.82"
|
||||||
env_ogCore_Server = os.environ.get('OGCORE_SERVER') #"opengnsys.es"
|
#env_ogCore_Server = os.environ.get('OGCORE_SERVER') #"opengnsys.es"
|
||||||
env_ogCore_Dir = os.environ.get('OGCORE_DIR') #{INSTALL_OPENGNSYS_TARGET}
|
#env_ogCore_Dir = os.environ.get('OGCORE_DIR') #{INSTALL_OPENGNSYS_TARGET}
|
||||||
env_ogBoot_Dir = os.environ.get('OGBOOT_DIR') #{INSTALL_OGBOOT_TARGET}
|
#env_ogBoot_Dir = os.environ.get('OGBOOT_DIR') #{INSTALL_OGBOOT_TARGET}
|
||||||
env_ogBoot_GitRepo = os.environ.get('OGBOOT_GIT_REPO') #"ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git"
|
#env_ogBoot_GitRepo = os.environ.get('OGBOOT_GIT_REPO') #"ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git"
|
||||||
|
|
||||||
|
# Leer variables de entorno
|
||||||
|
env_ogCore_ServerIP = "172.17.8.82" #os.getenv('OGCORE_SERVER_IP') #"172.17.8.82"
|
||||||
|
env_ogCore_Server = "opengnsys.es" #os.getenv('OGCORE_SERVER') #"opengnsys.es"
|
||||||
|
env_ogCore_Dir = "/opt/opengnsys" #os.getenv('OGCORE_DIR') #{INSTALL_OPENGNSYS_TARGET}
|
||||||
|
env_ogBoot_Dir = "/opt/ogboot" #os.getenv('OGBOOT_DIR') #{INSTALL_OGBOOT_TARGET}
|
||||||
|
env_ogBoot_GitRepo = "ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git" #os.getenv('OGBOOT_GIT_REPO') #"ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git"
|
||||||
|
|
||||||
PROGRAM = os.path.splitext(os.path.basename(sys.argv[0]))[0]
|
PROGRAM = os.path.splitext(os.path.basename(sys.argv[0]))[0]
|
||||||
PROGRAM_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
|
PROGRAM_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
|
||||||
|
|
@ -48,7 +58,7 @@ INETDSERV = "xinetd"
|
||||||
OPENGNSYS_CLIENT_PASSWD="og"
|
OPENGNSYS_CLIENT_PASSWD="og"
|
||||||
OPENGNSYS_CLIENT_USER="opengnsys"
|
OPENGNSYS_CLIENT_USER="opengnsys"
|
||||||
|
|
||||||
UBUNTU_OS_VERSION = "18"
|
UBUNTU_OS_VERSION = "22"
|
||||||
PYTHON_VERSION = 3
|
PYTHON_VERSION = 3
|
||||||
|
|
||||||
if os.path.isdir(f"{PROGRAM_DIR}/../installer"):
|
if os.path.isdir(f"{PROGRAM_DIR}/../installer"):
|
||||||
|
|
@ -56,6 +66,13 @@ if os.path.isdir(f"{PROGRAM_DIR}/../installer"):
|
||||||
else:
|
else:
|
||||||
REMOTE = 1
|
REMOTE = 1
|
||||||
|
|
||||||
|
# Create log file with sudo and set owner to ogboot
|
||||||
|
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])
|
||||||
|
|
||||||
#Configurar el registro
|
#Configurar el registro
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
logging.basicConfig(level=logging.DEBUG,
|
||||||
format='%(asctime)s %(levelname)s\t%(message)s',
|
format='%(asctime)s %(levelname)s\t%(message)s',
|
||||||
|
|
@ -151,12 +168,16 @@ def install_packages(missing, log_packages_file=f"/tmp/installed_packages.log"):
|
||||||
logger.info("All missing packages have been installed.")
|
logger.info("All missing packages have been installed.")
|
||||||
|
|
||||||
def autoConfigure():
|
def autoConfigure():
|
||||||
distribution = platform.linux_distribution()
|
#distribution = platform.linux_distribution()
|
||||||
OSDISTRIB = distribution[0]
|
#distribution = distro.linux_distribution()
|
||||||
OSVERSION = distribution[1]
|
#OSDISTRIB = distribution[0]
|
||||||
|
OSDISTRIB = distro.name()
|
||||||
|
OSVERSION = distro.version()
|
||||||
|
#OSVERSION = distribution[1]
|
||||||
logger.info(f"OSDISTRIB: {OSDISTRIB}")
|
logger.info(f"OSDISTRIB: {OSDISTRIB}")
|
||||||
logger.info(f"OSVERSION: {OSVERSION}")
|
logger.info(f"OSVERSION: {OSVERSION}")
|
||||||
|
print(f'{OSDISTRIB}...............{OSDISTRIB}')
|
||||||
|
print(f'{OSVERSION}...............{OSVERSION}')
|
||||||
# Configuración según la distribución OSDISTRIB
|
# Configuración según la distribución OSDISTRIB
|
||||||
if OSDISTRIB == 'Ubuntu':
|
if OSDISTRIB == 'Ubuntu':
|
||||||
# Código para Ubuntu
|
# Código para Ubuntu
|
||||||
|
|
@ -170,7 +191,8 @@ def autoConfigure():
|
||||||
pass
|
pass
|
||||||
elif OSVERSION == '22.04':
|
elif OSVERSION == '22.04':
|
||||||
# Código para Ubuntu 22.04
|
# Código para Ubuntu 22.04
|
||||||
PACKAGES = ["apache2", "arp-scan", "automake", "build-essential", "btrfs-progs", "composer", "curl", "ctorrent", "debootstrap", "g++-multilib", "gawk", "gettext", "graphviz", "grub-efi-amd64-signed", "isc-dhcp-server", "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", "php-pdo", "php-pear", "php-xml", "php-zip", "procps", "coreutils", "rsync", "samba", "schroot", "shim-signed", "squashfs-tools", "subversion", "tftp-hpa", "tftpd-hpa", "udpcast", "unzip", "wakeonlan", "wget", "xinetd"]
|
print(f'ubu 22.04')
|
||||||
|
PACKAGES = ["apache2", "arp-scan", "automake", "build-essential", "btrfs-progs", "composer", "curl", "ctorrent", "debootstrap", "g++-multilib", "gawk", "gettext", "graphviz", "grub-efi-amd64-signed", "kea-dhcp-server", "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", "php-pdo", "php-pear", "php-xml", "php-zip", "procps", "coreutils", "rsync", "samba", "schroot", "shim-signed", "squashfs-tools", "subversion", "tftpd-hpa", "udpcast", "unzip", "wakeonlan", "wget", "xinetd"]
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
logger.error("Ubuntu version not supported by ogBoot.")
|
logger.error("Ubuntu version not supported by ogBoot.")
|
||||||
|
|
@ -458,28 +480,74 @@ def testPxe():
|
||||||
logger.error("TFTP service is down.")
|
logger.error("TFTP service is down.")
|
||||||
os.remove(f"{TFTPCFGDIR}/testpxe")
|
os.remove(f"{TFTPCFGDIR}/testpxe")
|
||||||
|
|
||||||
|
def run_command(command):
|
||||||
|
result = subprocess.run(command, shell=True, text=True, capture_output=True)
|
||||||
|
if result.returncode != 0:
|
||||||
|
print(f"Error executing command: {command}")
|
||||||
|
print(result.stderr)
|
||||||
|
exit(1)
|
||||||
|
print(result.stdout)
|
||||||
|
|
||||||
def tftpConfigure():
|
def tftpConfigure():
|
||||||
if TFTPSERV:
|
# Update the package list
|
||||||
logger.info(f"TFTPSERV is configured: {TFTPSERV}")
|
print("Updating package list...")
|
||||||
inetd_cfg_path = f"{INETDCFGDIR}/{TFTPSERV}"
|
run_command("sudo apt update")
|
||||||
if os.path.isfile(inetd_cfg_path):
|
|
||||||
logger.error(f"The inetd configuration file exists: {inetd_cfg_path}")
|
run_command("sudo DEBIAN_FRONTEND=noninteractive apt install -y build-essential")
|
||||||
with open(inetd_cfg_path, "r+") as file:
|
|
||||||
content = file.read()
|
# Install tftpd-hpa in non-interactive mode
|
||||||
new_content = content.replace("disable.*", "disable = no")
|
print("Installing tftpd-hpa...")
|
||||||
file.seek(0)
|
run_command("sudo DEBIAN_FRONTEND=noninteractive apt install -y tftpd-hpa")
|
||||||
file.write(new_content)
|
|
||||||
file.truncate()
|
# Configure tftpd-hpa
|
||||||
logger.info(f"Modified inetd configuration file: {inetd_cfg_path}")
|
print("Configuring tftpd-hpa...")
|
||||||
else:
|
tftpd_config = """
|
||||||
service = TFTPSERV
|
# /etc/default/tftpd-hpa
|
||||||
logger.info(f"Enabling and starting the service {service}.service")
|
|
||||||
subprocess.run(["systemctl", "enable", f"{service}.service"], check=True)
|
TFTP_USERNAME="tftp"
|
||||||
subprocess.run(["systemctl", "start", f"{service}.service"], check=True)
|
TFTP_DIRECTORY="/var/lib/tftpboot"
|
||||||
service = INETDSERV
|
TFTP_ADDRESS="0.0.0.0:69"
|
||||||
logger.info(f"Enabling and starting the service {service}.service")
|
TFTP_OPTIONS="--secure"
|
||||||
subprocess.run(["systemctl", "enable", f"{service}.service"], check=True)
|
"""
|
||||||
subprocess.run(["systemctl", "start", f"{service}.service"], check=True)
|
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")
|
||||||
|
|
||||||
|
# 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 755 /var/lib/tftpboot")
|
||||||
|
|
||||||
|
# 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")
|
||||||
|
# if TFTPSERV:
|
||||||
|
# logger.info(f"TFTPSERV is configured: {TFTPSERV}")
|
||||||
|
# inetd_cfg_path = f"{INETDCFGDIR}/{TFTPSERV}"
|
||||||
|
# if os.path.isfile(inetd_cfg_path):
|
||||||
|
# logger.error(f"The inetd configuration file exists: {inetd_cfg_path}")
|
||||||
|
# with open(inetd_cfg_path, "r+") as file:
|
||||||
|
# content = file.read()
|
||||||
|
# new_content = content.replace("disable.*", "disable = no")
|
||||||
|
# file.seek(0)
|
||||||
|
# file.write(new_content)
|
||||||
|
# file.truncate()
|
||||||
|
# logger.info(f"Modified inetd configuration file: {inetd_cfg_path}")
|
||||||
|
# else:
|
||||||
|
# service = TFTPSERV
|
||||||
|
# logger.info(f"Enabling and starting the service {service}.service")
|
||||||
|
# subprocess.run(["systemctl", "enable", f"{service}.service"], check=True)
|
||||||
|
# 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", "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=0o750, exist_ok=True)
|
os.makedirs(TFTPCFGDIR, mode=0o750, exist_ok=True)
|
||||||
|
|
@ -494,13 +562,19 @@ def tftpConfigure():
|
||||||
#Crear enlace simbólico de /var/lib/tftpboot/ogLive a /var/lib/tftpboot/ogLive/ogclient
|
#Crear enlace simbólico de /var/lib/tftpboot/ogLive a /var/lib/tftpboot/ogLive/ogclient
|
||||||
subprocess.run(["ln", "-s", "{TFTPCFGDIR}/ogLive", "{TFTPCFGDIR}/ogclient"])
|
subprocess.run(["ln", "-s", "{TFTPCFGDIR}/ogLive", "{TFTPCFGDIR}/ogclient"])
|
||||||
|
|
||||||
symlink_target = f"{INSTALL_TARGET}/tftpboot"
|
symlink_target = f"{INSTALL_OGBOOT_TARGET}/tftpboot"
|
||||||
logger.info(f"Creating symbolic link from /{TFTPCFGDIR} to {symlink_target}")
|
logger.info(f"Creating symbolic link from {TFTPCFGDIR} to {symlink_target}")
|
||||||
if not os.path.exists(symlink_target):
|
#if not os.path.exists(symlink_target):
|
||||||
os.symlink("{TFTPCFGDIR}", symlink_target)
|
# os.symlink("{TFTPCFGDIR}", symlink_target)
|
||||||
os.chown(symlink_target, pwd.getpwnam("ogboot").pw_uid, pwd.getpwnam("ogboot").pw_gid)
|
# os.chown(symlink_target, pwd.getpwnam("ogboot").pw_uid, pwd.getpwnam("ogboot").pw_gid)
|
||||||
else:
|
#else:
|
||||||
logger.warning(f"The symbolic link already exists: {symlink_target}")
|
# logger.warning(f"The symbolic link already exists: {symlink_target}")
|
||||||
|
# Create the symbolic link
|
||||||
|
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} {symlink_target}")
|
||||||
|
|
||||||
def servicesCompilation():
|
def servicesCompilation():
|
||||||
hayErrores = 0
|
hayErrores = 0
|
||||||
|
|
@ -709,7 +783,8 @@ logger.info(f"Starting installation of ogBoot.")
|
||||||
if os.geteuid() != 0:
|
if os.geteuid() != 0:
|
||||||
logger.error("This program must be run with root privileges..")
|
logger.error("This program must be run with root privileges..")
|
||||||
exit(1)
|
exit(1)
|
||||||
if os.path.exists(os.path.join(INSTALL_OGBOOT_TARGET + "/doc/")):
|
print(f':INSTALL_OGBOOT_TARGET:::${INSTALL_OGBOOT_TARGET}')
|
||||||
|
if os.path.exists(os.path.join(INSTALL_OGBOOT_TARGET, "/doc/")):
|
||||||
logger.warning(f"ogBoot is already installed. Run {INSTALL_OGBOOT_TARGET}/lib/ogboot_devel_update.py” with root privileges to update..")
|
logger.warning(f"ogBoot is already installed. Run {INSTALL_OGBOOT_TARGET}/lib/ogboot_devel_update.py” with root privileges to update..")
|
||||||
exit(2)
|
exit(2)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue