|
|
|
@ -8,8 +8,13 @@
|
|
|
|
|
|
|
|
|
|
import platform, os, sys, subprocess, datetime, shutil, pwd, glob, logging, distro, re, json
|
|
|
|
|
|
|
|
|
|
ipxe_repo_url = "https://github.com/ipxe/ipxe.git"
|
|
|
|
|
oglive_iso_url = "https://ognproject.evlt.uma.es/trac/downloads/ogLive-focal-5.13.0-27-beta-amd64-r20210706.5b4bf5f.iso"
|
|
|
|
|
SAMBACFGDIR = "/etc/samba"
|
|
|
|
|
|
|
|
|
|
PROGRAM = os.path.splitext(os.path.basename(sys.argv[0]))[0]
|
|
|
|
|
PROGRAM_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
|
|
|
|
|
REPO_DIR = os.path.realpath (os.path.join (os.path.dirname (sys.argv[0]), '..'))
|
|
|
|
|
PROGRAM_NAME = os.path.basename(sys.argv[0])
|
|
|
|
|
|
|
|
|
|
config_file = os.path.join(PROGRAM_DIR, 'config.json')
|
|
|
|
@ -17,18 +22,10 @@ with open(config_file, 'r') as f:
|
|
|
|
|
config = json.load(f)
|
|
|
|
|
|
|
|
|
|
OGCORE_IP = config["ogCore_ServerIP"]
|
|
|
|
|
INSTALL_OPENGNSYS_TARGET = "/opt/opengnsys"
|
|
|
|
|
INSTALL_OGBOOT_TARGET = "/opt/ogboot"
|
|
|
|
|
INSTALL_TARGET = "/opt/ogboot"
|
|
|
|
|
GIT_REPO = "ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git"
|
|
|
|
|
INSTALL_OGBOOT_TARGET = config["ogBoot_Dir"]
|
|
|
|
|
OPENGNSYS_CLIENT_USER = config["ogBootSambaUser"]
|
|
|
|
|
OPENGNSYS_CLIENT_PASSWD = config["ogBootSambaPass"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OSDISTRIB = ""
|
|
|
|
|
OSVERSION = ""
|
|
|
|
|
IPXE_DIR = "/tmp/ogboot_ipxe"
|
|
|
|
|
WORKDIR ="/tmp/ogboot_installer"
|
|
|
|
|
|
|
|
|
|
DEFAULTDEV = ""
|
|
|
|
|
PACKAGES_TO_INSTALL = ["htop"]
|
|
|
|
@ -44,15 +41,10 @@ INETDSERV = "xinetd"
|
|
|
|
|
UBUNTU_OS_VERSION = "24"
|
|
|
|
|
PYTHON_VERSION = 3
|
|
|
|
|
|
|
|
|
|
if os.path.isdir(f"{PROGRAM_DIR}/../installer"):
|
|
|
|
|
REMOTE = 0
|
|
|
|
|
else:
|
|
|
|
|
REMOTE = 1
|
|
|
|
|
|
|
|
|
|
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', 'chmod', '775', log_file])
|
|
|
|
|
subprocess.run(['touch', log_file])
|
|
|
|
|
subprocess.run(['chmod', '775', log_file])
|
|
|
|
|
|
|
|
|
|
#Configure the log
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG,
|
|
|
|
@ -97,19 +89,6 @@ def check_distribution():
|
|
|
|
|
logger.error("Leaving the installation.")
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def downloadCode(url):
|
|
|
|
|
if len(url) != 1:
|
|
|
|
|
logger.error("Invalid number of parameters")
|
|
|
|
|
exit(1)
|
|
|
|
|
subprocess.run(["GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=accept-new git archive --remote=" + url + " --format zip --output opengnsys.zip --prefix=opengnsys/ " + BRANCH + " && unzip opengnsys.zip"], shell=True)
|
|
|
|
|
if subprocess.returncode != 0:
|
|
|
|
|
logger.error("Error getting OpenGnsys code from " + url)
|
|
|
|
|
return 1
|
|
|
|
|
subprocess.run(["rm -f opengnsys.zip"], shell=True)
|
|
|
|
|
logger.info("downloadCog_boot_create_dirsode(): code was downloaded")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
###:::::::::::::::::::::::::::::: INSTALL ::::::::::::::::::::::::::::::::::###
|
|
|
|
|
###############################################################################
|
|
|
|
@ -167,7 +146,8 @@ def get_missing_packages():
|
|
|
|
|
logger.info(f"Package to install: {package}...")
|
|
|
|
|
return faltantes
|
|
|
|
|
|
|
|
|
|
def install_packages(missing, log_packages_file="/tmp/installed_packages.log"):
|
|
|
|
|
def install_packages(log_packages_file="/tmp/installed_packages.log"):
|
|
|
|
|
missing = get_missing_packages()
|
|
|
|
|
if not missing:
|
|
|
|
|
logger.info("All packages are already installed.")
|
|
|
|
|
return
|
|
|
|
@ -177,9 +157,9 @@ def install_packages(missing, log_packages_file="/tmp/installed_packages.log"):
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
os.environ['DEBIAN_FRONTEND'] = 'noninteractive'
|
|
|
|
|
subprocess.run(["sudo", "apt-get", "update"], check=True)
|
|
|
|
|
subprocess.run(["apt-get", "update"], check=True)
|
|
|
|
|
subprocess.run(
|
|
|
|
|
["sudo", "apt-get", "install", "--allow-change-held-packages", "-y", "--no-install-recommends"] + missing,
|
|
|
|
|
["apt-get", "install", "--allow-change-held-packages", "-y", "--no-install-recommends"] + missing + ['apache2-'],
|
|
|
|
|
check=True
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -193,9 +173,9 @@ def install_packages(missing, log_packages_file="/tmp/installed_packages.log"):
|
|
|
|
|
# Check PHP version and install corresponding php-fpm package
|
|
|
|
|
php_version = subprocess.check_output(["php", "-v"]).decode("utf-8")
|
|
|
|
|
if "PHP 8.1" in php_version:
|
|
|
|
|
subprocess.run(["sudo", "apt-get", "install", "-y", "php8.1-fpm"], check=True)
|
|
|
|
|
subprocess.run(["apt-get", "install", "-y", "php8.1-fpm"], check=True)
|
|
|
|
|
elif "PHP 8.3" in php_version:
|
|
|
|
|
subprocess.run(["sudo", "apt-get", "install", "-y", "php8.3-fpm"], check=True)
|
|
|
|
|
subprocess.run(["apt-get", "install", "-y", "php8.3-fpm"], check=True)
|
|
|
|
|
else:
|
|
|
|
|
logger.warning("PHP version not supported.")
|
|
|
|
|
|
|
|
|
@ -205,41 +185,29 @@ def install_packages(missing, log_packages_file="/tmp/installed_packages.log"):
|
|
|
|
|
else:
|
|
|
|
|
del os.environ['DEBIAN_FRONTEND']
|
|
|
|
|
|
|
|
|
|
def autoConfigure():
|
|
|
|
|
global OSDISTRIB, OSVERSION
|
|
|
|
|
#distribution = platform.linux_distribution()
|
|
|
|
|
#distribution = distro.linux_distribution()
|
|
|
|
|
#OSDISTRIB = distribution[0]
|
|
|
|
|
OSDISTRIB = distro.name()
|
|
|
|
|
OSVERSION = distro.version()
|
|
|
|
|
#OSVERSION = distribution[1]
|
|
|
|
|
logger.info(f"OSDISTRIB: {OSDISTRIB}")
|
|
|
|
|
logger.info(f"OSVERSION: {OSVERSION}")
|
|
|
|
|
# Configuración según la distribución OSDISTRIB
|
|
|
|
|
|
|
|
|
|
def add_sudoers_permissions():
|
|
|
|
|
sudoers_entry = """
|
|
|
|
|
ogboot ALL=(ALL) NOPASSWD: /opt/bin/oglivecli
|
|
|
|
|
ogboot ALL=(root) NOPASSWD: /usr/bin/mount, /usr/bin/umount, /usr/bin/cp, /usr/bin/chmod, /usr/bin/chown, /usr/bin/md5sum, /usr/bin/smbpasswd, /usr/bin/cat, /usr/bin/tee, /usr/bin/sed, /usr/bin/gzip, /usr/bin/lz4, /usr/bin/cpio, /usr/bin/find, /bin/tee, /usr/bin/dd, /usr/bin/mkfs.ext4, /usr/bin/rsync
|
|
|
|
|
ogboot ALL=(root) NOPASSWD: /opt/ogboot/lib/*.iso /mnt
|
|
|
|
|
ogboot ALL=(root) NOPASSWD: __OGBOOT_TARGET__/lib/*.iso /mnt
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
sudoers_file = '/etc/sudoers.d/ogboot'
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
with open(sudoers_file, 'w') as file:
|
|
|
|
|
file.write(sudoers_entry)
|
|
|
|
|
file.write(sudoers_entry.replace ('__OGBOOT_TARGET__', INSTALL_OGBOOT_TARGET))
|
|
|
|
|
print("Sudoers permissions for 'ogboot' added successfully.")
|
|
|
|
|
except IOError as e:
|
|
|
|
|
print(f"Failed to write to {sudoers_file}: {e}")
|
|
|
|
|
|
|
|
|
|
def og_core_create_user(OPENGNSYS_CLIENT_USER):
|
|
|
|
|
def og_core_create_user(u):
|
|
|
|
|
try:
|
|
|
|
|
pwd.getpwnam(OPENGNSYS_CLIENT_USER)
|
|
|
|
|
logger.warning(f"User {OPENGNSYS_CLIENT_USER} already exists")
|
|
|
|
|
pwd.getpwnam(u)
|
|
|
|
|
logger.warning(f"User {u} already exists")
|
|
|
|
|
except KeyError:
|
|
|
|
|
subprocess.run(["sudo", "useradd", "-m", OPENGNSYS_CLIENT_USER])
|
|
|
|
|
logger.info(f"User {OPENGNSYS_CLIENT_USER} created successfully.")
|
|
|
|
|
subprocess.run(["useradd", "--create-home", u, "--shell", "/bin/bash"])
|
|
|
|
|
logger.info(f"User {u} created successfully.")
|
|
|
|
|
|
|
|
|
|
def og_boot_create_dirs():
|
|
|
|
|
global INSTALL_OGBOOT_TARGET
|
|
|
|
@ -253,9 +221,6 @@ def og_boot_create_dirs():
|
|
|
|
|
# Crear los directorios necesarios
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
# Cambiar el propietario de los directorios
|
|
|
|
|
subprocess.run(["chown", "-R", "ogboot:ogboot", INSTALL_OGBOOT_TARGET])
|
|
|
|
@ -267,15 +232,15 @@ def og_boot_create_dirs():
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
def og_boot_symfony_install():
|
|
|
|
|
global WORKDIR, INSTALL_OGBOOT_TARGET, OGCORE_IP
|
|
|
|
|
global INSTALL_OGBOOT_TARGET
|
|
|
|
|
logger.info("Creating Symfony application skeleton...")
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# Copiar los archivos .env y composer.json primero
|
|
|
|
|
env_src = os.path.join(f"{WORKDIR}", "ogboot/.env")
|
|
|
|
|
composer_src = os.path.join(f"{WORKDIR}", "ogboot/composer.json")
|
|
|
|
|
env_dest = os.path.join(f"{INSTALL_OGBOOT_TARGET}", ".env")
|
|
|
|
|
composer_dest = os.path.join(f"{INSTALL_OGBOOT_TARGET}", "composer.json")
|
|
|
|
|
env_src = os.path.join(f"{REPO_DIR}", ".env")
|
|
|
|
|
composer_src = os.path.join(f"{REPO_DIR}", "composer.json")
|
|
|
|
|
env_dest = os.path.join(f"{INSTALL_OGBOOT_TARGET}", ".env")
|
|
|
|
|
composer_dest = os.path.join(f"{INSTALL_OGBOOT_TARGET}", "composer.json")
|
|
|
|
|
|
|
|
|
|
shutil.copy(env_src, env_dest)
|
|
|
|
|
shutil.copy(composer_src, composer_dest)
|
|
|
|
@ -302,21 +267,20 @@ def og_boot_symfony_install():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def og_boot_copy_files():
|
|
|
|
|
global INSTALL_TARGET, WORKDIR
|
|
|
|
|
bin_source = os.path.join(WORKDIR, "ogboot/bin")
|
|
|
|
|
bin_source = os.path.join(REPO_DIR, "bin")
|
|
|
|
|
bin_dest = os.path.join(INSTALL_OGBOOT_TARGET, "bin")
|
|
|
|
|
src_source = os.path.join(WORKDIR, "ogboot/src")
|
|
|
|
|
src_source = os.path.join(REPO_DIR, "src")
|
|
|
|
|
src_dest = os.path.join(INSTALL_OGBOOT_TARGET, "src")
|
|
|
|
|
|
|
|
|
|
config_source = os.path.join(WORKDIR, "ogboot/config")
|
|
|
|
|
config_source = os.path.join(REPO_DIR, "config")
|
|
|
|
|
config_dest = os.path.join(INSTALL_OGBOOT_TARGET, "config")
|
|
|
|
|
|
|
|
|
|
lib_source = os.path.join(WORKDIR, "ogboot/lib")
|
|
|
|
|
lib_source = os.path.join(REPO_DIR, "lib")
|
|
|
|
|
lib_dest = os.path.join(INSTALL_OGBOOT_TARGET, "lib")
|
|
|
|
|
|
|
|
|
|
os.makedirs("/tmp/opt", exist_ok=True)
|
|
|
|
|
#os.makedirs("/tmp/opt", exist_ok=True)
|
|
|
|
|
|
|
|
|
|
subprocess.run(["chown", "-R", "ogboot:ogboot", "/tmp/opt"])
|
|
|
|
|
#subprocess.run(["chown", "-R", "ogboot:ogboot", "/tmp/opt"])
|
|
|
|
|
|
|
|
|
|
if os.path.exists(bin_dest):
|
|
|
|
|
shutil.rmtree(bin_dest)
|
|
|
|
@ -334,9 +298,9 @@ def og_boot_copy_files():
|
|
|
|
|
shutil.rmtree(lib_dest)
|
|
|
|
|
shutil.copytree(lib_source, lib_dest)
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
os.makedirs(os.path.join(INSTALL_OGBOOT_TARGET, "etc"), mode=0o775, exist_ok=True)
|
|
|
|
|
os.makedirs(os.path.join(INSTALL_OGBOOT_TARGET, "client"), mode=0o775, exist_ok=True)
|
|
|
|
|
os.makedirs(os.path.join(INSTALL_OGBOOT_TARGET, "public"), mode=0o775, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
subprocess.run(["chmod", "-R", "775", INSTALL_OGBOOT_TARGET])
|
|
|
|
|
subprocess.run(["chown", "-R", "ogboot:ogboot", INSTALL_OGBOOT_TARGET])
|
|
|
|
@ -349,30 +313,14 @@ def og_boot_composer_install():
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Ejecutar Composer como el usuario 'ogboot' para actualizar el paquete doctrine/dbal
|
|
|
|
|
result = subprocess.run(["sudo", "-u", "ogboot", "/opt/ogboot/bin/composer.phar", "update", "doctrine/dbal", "--working-dir", INSTALL_OGBOOT_TARGET])
|
|
|
|
|
result = subprocess.run(["sudo", "-u", "ogboot", INSTALL_OGBOOT_TARGET+"/bin/composer.phar", "update", "doctrine/dbal", "--working-dir", INSTALL_OGBOOT_TARGET])
|
|
|
|
|
if result.returncode != 0:
|
|
|
|
|
logger.error("Error updating doctrine/dbal package using Composer")
|
|
|
|
|
return
|
|
|
|
|
# Eliminar composer.lock si existe
|
|
|
|
|
composer_lock_path = os.path.join(INSTALL_OGBOOT_TARGET, "composer.lock")
|
|
|
|
|
if os.path.exists(composer_lock_path):
|
|
|
|
|
os.remove(composer_lock_path)
|
|
|
|
|
|
|
|
|
|
subprocess.call(["chown", "-R", "ogboot:ogboot", f"{INSTALL_OGBOOT_TARGET}/public"])
|
|
|
|
|
|
|
|
|
|
logger.info("Application skeleton created and composer.lock file removed.")
|
|
|
|
|
|
|
|
|
|
#def createDirs(INSTALL_TARGET):
|
|
|
|
|
# if not os.path.exists(INSTALL_TARGET):
|
|
|
|
|
# try:
|
|
|
|
|
# os.makedirs(INSTALL_TARGET)
|
|
|
|
|
# os.makedirs(os.path.join(INSTALL_TARGET, "client"))
|
|
|
|
|
# logger.info(f"{INSTALL_TARGET} directory created successfully.")
|
|
|
|
|
# except OSError:
|
|
|
|
|
# logger.error("Error while creating directory paths!")
|
|
|
|
|
# exit(1)
|
|
|
|
|
# else:
|
|
|
|
|
# logger.info(f"Directory {INSTALL_TARGET} already exists.")
|
|
|
|
|
logger.info("Application skeleton created.")
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
###:::::::::::::::::::::::::::: CONFIGURE ::::::::::::::::::::::::::::::::::###
|
|
|
|
@ -404,7 +352,7 @@ def get_ogboot_uid_gid():
|
|
|
|
|
def add_fstab_entries(uid, gid):
|
|
|
|
|
try:
|
|
|
|
|
fstab_entries = [
|
|
|
|
|
f'/opt/ogboot/lib/oglive.iso /tmp/opt/ogboot/lib/ogLive iso9660 loop,ro,users,uid={uid},gid={gid},noauto 0 0\n',
|
|
|
|
|
f'{INSTALL_OGBOOT_TARGET}/lib/oglive.iso {INSTALL_OGBOOT_TARGET}/mnt iso9660 loop,ro,users,uid={uid},gid={gid},noauto 0 0\n',
|
|
|
|
|
f'/var/lib/tftpboot/ogLive/ogclient.sqfs /tmp/ogclient_mount squashfs loop,ro,user,noauto 0 0\n'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
@ -435,47 +383,39 @@ def tftpConfigure():
|
|
|
|
|
TFTPCFGDIR = "/var/lib/tftpboot"
|
|
|
|
|
|
|
|
|
|
logger.info("Configuring tftpd-hpa...")
|
|
|
|
|
tftpd_config = """
|
|
|
|
|
# /etc/default/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)
|
|
|
|
|
|
|
|
|
|
shutil.move("/tmp/tftpd-hpa", "/etc/default/tftpd-hpa")
|
|
|
|
|
|
|
|
|
|
logger.info("\t2-Creating and setting permissions for the TFTP directory...")
|
|
|
|
|
os.makedirs("/var/lib/tftpboot", exist_ok=True)
|
|
|
|
|
|
|
|
|
|
subprocess.run("chown -R tftp:tftp /var/lib/tftpboot", shell=True, text=True, capture_output=True)
|
|
|
|
|
subprocess.run("chmod -R 775 /var/lib/tftpboot", shell=True, text=True, capture_output=True)
|
|
|
|
|
os.makedirs(TFTPCFGDIR, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
logger.info("\t3-Setting permissions for /var/lib/tftpboot directory...")
|
|
|
|
|
subprocess.run("systemctl restart tftpd-hpa", shell=True, text=True, capture_output=True)
|
|
|
|
|
logger.info("Checking tftpd-hpa service status...")
|
|
|
|
|
subprocess.run("systemctl status tftpd-hpa", shell=True, text=True, capture_output=True)
|
|
|
|
|
subprocess.run(f"chown -R tftp:ogboot {TFTPCFGDIR}", shell=True, text=True, capture_output=True)
|
|
|
|
|
subprocess.run(f"chmod -R 775 {TFTPCFGDIR}", shell=True, text=True, capture_output=True)
|
|
|
|
|
|
|
|
|
|
subprocess.run("systemctl restart tftpd-hpa", shell=True, text=True, capture_output=True)
|
|
|
|
|
|
|
|
|
|
if os.path.exists(TFTPCFGDIR):
|
|
|
|
|
subprocess.run(["chown", "-R", "tftp:ogboot", TFTPCFGDIR])
|
|
|
|
|
logger.info(f"{TFTPCFGDIR} directory permissions modified correctly.")
|
|
|
|
|
else:
|
|
|
|
|
logger.warning(f"\t1-{TFTPCFGDIR} directory not 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("tftp").pw_uid, pwd.getpwnam("ogboot").pw_gid)
|
|
|
|
|
#os.lchown(symlink_target, pwd.getpwnam("tftp").pw_uid, pwd.getpwnam("ogboot").pw_gid)
|
|
|
|
|
else:
|
|
|
|
|
logger.warning(f"The symbolic link already exists: {symlink_target}")
|
|
|
|
|
|
|
|
|
|
logger.info("Downloading oglive...")
|
|
|
|
|
iso_url = "https://ognproject.evlt.uma.es/trac/downloads/ogLive-focal-5.13.0-27-beta-amd64-r20210706.5b4bf5f.iso"
|
|
|
|
|
try:
|
|
|
|
|
result = subprocess.run(
|
|
|
|
|
["/opt/ogboot/bin/oglivecli", "download", iso_url],
|
|
|
|
|
[INSTALL_OGBOOT_TARGET+"/bin/oglivecli", "download", oglive_iso_url],
|
|
|
|
|
check=True,
|
|
|
|
|
capture_output=True,
|
|
|
|
|
text=True
|
|
|
|
@ -507,45 +447,27 @@ TFTP_OPTIONS="--secure"
|
|
|
|
|
logger.error(f"Subprocess failed: {e}")
|
|
|
|
|
logger.error("Continuing with the installation...")
|
|
|
|
|
|
|
|
|
|
def servicesCompilation():
|
|
|
|
|
global WORKDIR
|
|
|
|
|
hayErrores = 0
|
|
|
|
|
process = subprocess.run(["make"], cwd=f"{WORKDIR}/ogboot/sources/clients/ogAdmClient")
|
|
|
|
|
shutil.copy2(f"{WORKDIR}/ogboot/sources/clients/ogAdmClient/ogAdmClient", f"{WORKDIR}/ogboot/client/shared/bin")
|
|
|
|
|
if process.returncode != 0:
|
|
|
|
|
logger.info(f"{servicesCompilation.__name__}(): error while compiling OpenGnsys Admin Client")
|
|
|
|
|
hayErrores = 1
|
|
|
|
|
return hayErrores
|
|
|
|
|
|
|
|
|
|
def copyInterfaceAdm():
|
|
|
|
|
global WORKDIR, INSTALL_TARGET
|
|
|
|
|
hayErrores = 0
|
|
|
|
|
cp_process = subprocess.run(["cp", "-ar", f"{WORKDIR}/ogboot/sources/interface", f"{INSTALL_TARGET}/client/interfaceAdm"])
|
|
|
|
|
cp_process = subprocess.run(["cp", "-ar", f"{REPO_DIR}/sources/interface", f"{INSTALL_OGBOOT_TARGET}/client/interfaceAdm"])
|
|
|
|
|
if cp_process.returncode != 0:
|
|
|
|
|
logger.error(f"Error while copying Administration Interface Folder")
|
|
|
|
|
hayErrores = 1
|
|
|
|
|
return hayErrores
|
|
|
|
|
|
|
|
|
|
def copyClientFiles():
|
|
|
|
|
global WORKDIR, INSTALL_TARGET
|
|
|
|
|
errstatus = 0
|
|
|
|
|
logger.info(f"Copying OpenGnsys Client files.")
|
|
|
|
|
source_files = glob.glob(f"{WORKDIR}/ogboot/client/shared/*")
|
|
|
|
|
# Copy each file individually
|
|
|
|
|
for file in source_files:
|
|
|
|
|
cp_process = subprocess.run(["cp", "-a", file, f"{INSTALL_TARGET}/client"])
|
|
|
|
|
if cp_process.returncode != 0:
|
|
|
|
|
logger.error(f"Error while copying client structure: {file}")
|
|
|
|
|
errstatus = 1
|
|
|
|
|
if 0 != subprocess.run (['rsync', '-aH', f'{REPO_DIR}/client/shared/', f'{INSTALL_OGBOOT_TARGET}/client/']).returncode:
|
|
|
|
|
logger.error(f"Error while copying client structure")
|
|
|
|
|
errstatus = 1
|
|
|
|
|
|
|
|
|
|
logger.info(f"Copying OpenGnsys Cloning Engine files.")
|
|
|
|
|
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:
|
|
|
|
|
cp_engine_process = subprocess.run(["cp", "-a", file, f"{INSTALL_TARGET}/client/lib/engine/bin"])
|
|
|
|
|
if cp_engine_process.returncode != 0:
|
|
|
|
|
logger.error(f"Error while copying engine files: {file}")
|
|
|
|
|
errstatus = 1
|
|
|
|
|
os.makedirs(f"{INSTALL_OGBOOT_TARGET}/client/lib/engine/bin", mode=0o775, exist_ok=True)
|
|
|
|
|
if 0 != subprocess.run (['rsync', '-aH', f'{REPO_DIR}/client/engine/', f'{INSTALL_OGBOOT_TARGET}/client/lib/engine/bin/']).returncode:
|
|
|
|
|
logger.error(f"Error while copying engine files")
|
|
|
|
|
errstatus = 1
|
|
|
|
|
|
|
|
|
|
if errstatus == 0:
|
|
|
|
|
logger.info(f"Client copy files success.")
|
|
|
|
|
else:
|
|
|
|
@ -568,62 +490,44 @@ def get_first_network_interface_with_traffic():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def openGnsysConfigure():
|
|
|
|
|
global DEFAULTDEV, INSTALL_TARGET, OGCORE_IP, WORKDIR
|
|
|
|
|
i = 0
|
|
|
|
|
dev = ""
|
|
|
|
|
CONSOLEURL = ""
|
|
|
|
|
CONSOLEURL = f"https://{OGCORE_IP}/opengnsys"
|
|
|
|
|
with open(f"{WORKDIR}/ogboot/etc/ogAdmClient.cfg") as file:
|
|
|
|
|
content = file.read()
|
|
|
|
|
content = content.replace("SERVERIP", OGCORE_IP)
|
|
|
|
|
content = content.replace("OPENGNSYSURL", CONSOLEURL)
|
|
|
|
|
with open(f"{INSTALL_TARGET}/client/etc/ogAdmClient-{DEFAULTDEV}.cfg", "w") as outfile:
|
|
|
|
|
outfile.write(content)
|
|
|
|
|
if os.path.islink(f"{INSTALL_TARGET}/client/etc/ogAdmClient.cfg"):
|
|
|
|
|
logger.warning(f"Link {INSTALL_TARGET}/client/etc/ogAdmClient.cfg exists.")
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
os.symlink(f"{INSTALL_TARGET}/client/etc/ogAdmClient-{DEFAULTDEV}.cfg", f"{INSTALL_TARGET}/client/etc/ogAdmClient.cfg")
|
|
|
|
|
logger.info (f"Symbolic link created: {INSTALL_TARGET}/client/etc/ogAdmClient-{DEFAULTDEV}.cfg -> {INSTALL_TARGET}/client/etc/ogAdmClient.cfg")
|
|
|
|
|
except OSError as e:
|
|
|
|
|
logger.error(f"Error creating symbolic link: {e}")
|
|
|
|
|
TZ = subprocess.check_output(["timedatectl", "status"]).decode().split("\n")[2].split(":")[1].strip()
|
|
|
|
|
with open(f"{INSTALL_TARGET}/client/etc/engine.cfg", "a") as file:
|
|
|
|
|
file.write(f"# OpenGnsys Server timezone.\nTZ=\"{TZ.replace(' ', '')}\"\n")
|
|
|
|
|
logger.info(f"OpenGnsys config files created.")
|
|
|
|
|
def tzConfigure():
|
|
|
|
|
tdctl = subprocess.run (['timedatectl', 'show'], capture_output=True, text=True)
|
|
|
|
|
lines = tdctl.stdout.split ('\n')
|
|
|
|
|
TZ = list (filter (lambda elem: 'Timezone' in elem, lines))[0]
|
|
|
|
|
_, TZ = TZ.split ('=')
|
|
|
|
|
|
|
|
|
|
def mount_NFS():
|
|
|
|
|
if TZ:
|
|
|
|
|
with open(f"{INSTALL_OGBOOT_TARGET}/client/etc/engine.cfg", "a") as file:
|
|
|
|
|
file.write(f"# OpenGnsys Server timezone.\nTZ=\"{TZ}\"\n")
|
|
|
|
|
|
|
|
|
|
def install_ipxe():
|
|
|
|
|
global IPXE_DIR, INSTALL_OGBOOT_TARGET
|
|
|
|
|
repo_url = "https://github.com/ipxe/ipxe.git"
|
|
|
|
|
clone_dir = "/tmp/ogboot_ipxe"
|
|
|
|
|
|
|
|
|
|
# Clonar el repositorio desde Gitea
|
|
|
|
|
if os.path.exists(clone_dir):
|
|
|
|
|
logger.info(f"Eliminando el directorio {clone_dir} existente")
|
|
|
|
|
subprocess.call(["rm", "-rf", clone_dir])
|
|
|
|
|
if os.path.exists (f"{INSTALL_OGBOOT_TARGET}/tftpboot/undionly.kpxe"):
|
|
|
|
|
logger.info ('iPXE already present--not compiling again')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
logger.info(f"Clonando el repositorio {repo_url}")
|
|
|
|
|
if subprocess.call(["git", "-c", "http.sslVerify=false", "clone", repo_url, clone_dir]) == 0:
|
|
|
|
|
# Clonar el repositorio desde Gitea
|
|
|
|
|
logger.info(f"Clonando el repositorio {ipxe_repo_url}")
|
|
|
|
|
if subprocess.call(["git", "-c", "http.sslVerify=false", "clone", ipxe_repo_url, clone_dir]) == 0:
|
|
|
|
|
logger.info("Repositorio clonado correctamente.")
|
|
|
|
|
else:
|
|
|
|
|
logger.error(f"ERROR\tNo se pudo clonar el repositorio {repo_url}.")
|
|
|
|
|
logger.error(f"ERROR\tNo se pudo clonar el repositorio {ipxe_repo_url}.")
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Ejecutar el comando make en el directorio src
|
|
|
|
|
logger.info(f"Ejecutando make en {IPXE_DIR}/src")
|
|
|
|
|
#logger.info(f"Ejecutando make en {IPXE_DIR}/src")
|
|
|
|
|
os.chdir(f"{IPXE_DIR}/src")
|
|
|
|
|
if subprocess.call(["make", "-s", "-j", "4"]) == 0:
|
|
|
|
|
logger.info(f"Directorio {IPXE_DIR}/src correctamente compilado.")
|
|
|
|
|
else:
|
|
|
|
|
logger.error(f"ERROR\tNo se pudo compilar el directorio {IPXE_DIR}/src.")
|
|
|
|
|
exit(1)
|
|
|
|
|
#if subprocess.run(["make", "-s", "-j", "4"], capture_output=True).returncode == 0:
|
|
|
|
|
# logger.info(f"Directorio {IPXE_DIR}/src correctamente compilado.")
|
|
|
|
|
#else:
|
|
|
|
|
# logger.error(f"ERROR\tNo se pudo compilar el directorio {IPXE_DIR}/src.")
|
|
|
|
|
# exit(1)
|
|
|
|
|
|
|
|
|
|
if not os.path.exists("/opt/opengnsys"):
|
|
|
|
|
os.symlink("/opt/ogboot/", "/opt/opengnsys")
|
|
|
|
|
logger.info("Symbolic link created successfully.")
|
|
|
|
|
if subprocess.call(["make", "-s", "bin/undionly.kpxe", f"EMBED={INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"]) == 0:
|
|
|
|
|
logger.info("Generando make de undionly.kpxe:")
|
|
|
|
|
if subprocess.run(["make", "-s", "bin/undionly.kpxe", f"EMBED={INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"], capture_output=True).returncode == 0:
|
|
|
|
|
logger.info("Boot file mounted correctly.")
|
|
|
|
|
else:
|
|
|
|
|
logger.error("Failed to mount boot file.")
|
|
|
|
@ -631,19 +535,23 @@ def mount_NFS():
|
|
|
|
|
logger.info("Copiando undionly.kpxe con usuario ogboot:")
|
|
|
|
|
subprocess.call(["cp", "bin/undionly.kpxe", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
|
|
|
|
|
subprocess.call(["chown", "ogboot:ogboot", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
|
|
|
|
|
|
|
|
|
|
logger.info("Generando make de ipxe.efi:")
|
|
|
|
|
if subprocess.call(["make", "-s", "bin-x86_64-efi/ipxe.efi", f"EMBED={INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"]) == 0:
|
|
|
|
|
if subprocess.run(["make", "-s", "bin-x86_64-efi/ipxe.efi", f"EMBED={INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"], capture_output=True).returncode == 0:
|
|
|
|
|
logger.info("Properly constructed EFI file.")
|
|
|
|
|
else:
|
|
|
|
|
logger.error("Could not build EFI file.")
|
|
|
|
|
exit(1)
|
|
|
|
|
subprocess.call(["sudo", "cp", "bin-x86_64-efi/ipxe.efi", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
|
|
|
|
|
subprocess.call(["sudo", "chown", "-R", "tftp:ogboot", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
|
|
|
|
|
subprocess.run(["sudo", "chmod", "-R", "775", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
|
|
|
|
|
subprocess.call(["cp", "bin-x86_64-efi/ipxe.efi", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
|
|
|
|
|
subprocess.call(["chown", "-R", "tftp:ogboot", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
|
|
|
|
|
|
|
|
|
|
subprocess.run(["chmod", "-R", "775", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
|
|
|
|
|
os.makedirs(f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates", exist_ok=True)
|
|
|
|
|
subprocess.call(["sudo", "chown", "-R", "tftp:ogboot", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
|
|
|
|
|
subprocess.call(["sudo", "chmod", "-R", "775", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
|
|
|
|
|
subprocess.call(["sudo", "cp", f"{WORKDIR}/ogboot/tftpboot/ipxe_scripts/templates/pxe_default", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
|
|
|
|
|
subprocess.call(["chown", "-R", "tftp:ogboot", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
|
|
|
|
|
subprocess.call(["chmod", "-R", "775", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
|
|
|
|
|
subprocess.call(["cp", f"{REPO_DIR}/tftpboot/ipxe_scripts/templates/pxe_default", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
|
|
|
|
|
|
|
|
|
|
subprocess.call(["rm", "-rf", clone_dir])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_ip_address(interface):
|
|
|
|
@ -658,25 +566,20 @@ def get_ip_address(interface):
|
|
|
|
|
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]
|
|
|
|
|
global DEFAULTDEV, INSTALL_OGBOOT_TARGET
|
|
|
|
|
|
|
|
|
|
ip_address_server = get_ip_address(DEFAULTDEV)
|
|
|
|
|
template = os.path.join(WORKDIR, "ogboot/etc/dhcp_boot.ipxe.tmpl")
|
|
|
|
|
template = os.path.join(REPO_DIR, "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)
|
|
|
|
|
shutil.copy(template, ipxe_output)
|
|
|
|
|
with open(ipxe_output, "r") as ipxe_file:
|
|
|
|
|
#shutil.copy(template, ipxe_output)
|
|
|
|
|
with open(template, "r") as ipxe_file:
|
|
|
|
|
ipxe_content = ipxe_file.read()
|
|
|
|
|
ipxe_content = ipxe_content.replace("__SERVERIP__", ip_address_server)
|
|
|
|
|
with open(ipxe_output, "w") as ipxe_file:
|
|
|
|
|
ipxe_file.write(ipxe_content)
|
|
|
|
|
# Reemplazar SERVERIP con la dirección IP en la plantilla y guardarla en el archivo de salida
|
|
|
|
|
# with open(template, "r") as tmpl_file:
|
|
|
|
|
# template_content = tmpl_file.read()
|
|
|
|
|
# ipxe_content = template_content.replace("SERVERIP", ip_address_server)
|
|
|
|
|
# with open(ipxe_output, "w") as ipxe_file:
|
|
|
|
|
# ipxe_file.write(ipxe_content)
|
|
|
|
|
template_default = os.path.join(WORKDIR, "ogboot/tftpboot/ipxe_scripts/default.ipxe")
|
|
|
|
|
|
|
|
|
|
template_default = os.path.join(REPO_DIR, "tftpboot/ipxe_scripts/default.ipxe")
|
|
|
|
|
default_output = os.path.join(INSTALL_OGBOOT_TARGET, "tftpboot/ipxe_scripts/default.ipxe")
|
|
|
|
|
with open(template_default, "r") as default_tmpl_file:
|
|
|
|
|
default_template_content = default_tmpl_file.read()
|
|
|
|
@ -687,7 +590,7 @@ def generate_ipxe_script():
|
|
|
|
|
|
|
|
|
|
def user_exists(user):
|
|
|
|
|
try:
|
|
|
|
|
result = subprocess.run(["sudo", "pdbedit", "-L", "-u", user], capture_output=True, text=True)
|
|
|
|
|
result = subprocess.run(["pdbedit", "-L", "-u", user], capture_output=True, text=True)
|
|
|
|
|
return user in result.stdout
|
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
|
logger.error(f"Error checking if user exists: {e}")
|
|
|
|
@ -695,13 +598,11 @@ def user_exists(user):
|
|
|
|
|
|
|
|
|
|
def smbConfigure():
|
|
|
|
|
global OPENGNSYS_CLIENT_PASSWD, OPENGNSYS_CLIENT_USER, PYTHON_VERSION
|
|
|
|
|
SAMBACFGDIR = "/etc/samba"
|
|
|
|
|
#logger.info(f"{smbConfigure.__name__}(): Configuring Samba service.")
|
|
|
|
|
backupFile(f"{SAMBACFGDIR}/smb.conf")
|
|
|
|
|
# Copiar plantilla de recursos para OpenGnsys
|
|
|
|
|
with open(os.path.join(WORKDIR, 'ogboot/etc/smb-ogboot.conf.tmpl'), 'r') as tmpl_file:
|
|
|
|
|
with open(os.path.join(REPO_DIR, 'etc/smb-ogboot.conf.tmpl'), 'r') as tmpl_file:
|
|
|
|
|
template = tmpl_file.read()
|
|
|
|
|
replaced_template = template.replace('__OGBOOTDIR__', INSTALL_OPENGNSYS_TARGET)
|
|
|
|
|
replaced_template = template.replace('__OGBOOTDIR__', INSTALL_OGBOOT_TARGET)
|
|
|
|
|
with open(os.path.join(SAMBACFGDIR, 'smb-ogboot.conf'), 'w') as conf_file:
|
|
|
|
|
conf_file.write(replaced_template)
|
|
|
|
|
# Configurar y recargar Samba"
|
|
|
|
@ -724,52 +625,38 @@ def smbConfigure():
|
|
|
|
|
try:
|
|
|
|
|
if user_exists(OPENGNSYS_CLIENT_USER):
|
|
|
|
|
logger.info(f"{OPENGNSYS_CLIENT_USER} user exists. Changing password...")
|
|
|
|
|
subprocess.run(
|
|
|
|
|
["sudo", "smbpasswd", OPENGNSYS_CLIENT_USER],
|
|
|
|
|
input=f"{OPENGNSYS_CLIENT_PASSWD}\n{OPENGNSYS_CLIENT_PASSWD}\n",
|
|
|
|
|
text=True,
|
|
|
|
|
check=True
|
|
|
|
|
)
|
|
|
|
|
extra_params = []
|
|
|
|
|
else:
|
|
|
|
|
logger.info(f"{OPENGNSYS_CLIENT_USER} user does not exist. Registering user...")
|
|
|
|
|
subprocess.run(
|
|
|
|
|
["sudo", "smbpasswd", "-a", OPENGNSYS_CLIENT_USER],
|
|
|
|
|
input=f"{OPENGNSYS_CLIENT_PASSWD}\n{OPENGNSYS_CLIENT_PASSWD}\n",
|
|
|
|
|
text=True,
|
|
|
|
|
check=True
|
|
|
|
|
)
|
|
|
|
|
extra_params = ['-a']
|
|
|
|
|
|
|
|
|
|
subprocess.run(
|
|
|
|
|
["smbpasswd"] + extra_params + [OPENGNSYS_CLIENT_USER],
|
|
|
|
|
input=f"{OPENGNSYS_CLIENT_PASSWD}\n{OPENGNSYS_CLIENT_PASSWD}\n",
|
|
|
|
|
text=True,
|
|
|
|
|
capture_output=True,
|
|
|
|
|
check=True
|
|
|
|
|
)
|
|
|
|
|
logger.info("Add/Modify user: Operation completed successfully.")
|
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
|
logger.error(f"Error adding/modifying user: {e}")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
try:
|
|
|
|
|
process_add = subprocess.run(
|
|
|
|
|
["sudo", "smbpasswd", "-a", OPENGNSYS_CLIENT_USER],
|
|
|
|
|
input=f"{OPENGNSYS_CLIENT_PASSWD}\n{OPENGNSYS_CLIENT_PASSWD}\n",
|
|
|
|
|
text=True,
|
|
|
|
|
check=True
|
|
|
|
|
)
|
|
|
|
|
logger.info(f"The password for the user {OPENGNSYS_CLIENT_USER} has been set correctly.")
|
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
|
logger.error(f"Error setting password: {e}")
|
|
|
|
|
'''
|
|
|
|
|
def setup_nginx():
|
|
|
|
|
global DEFAULTDEV, WORKDIR
|
|
|
|
|
global DEFAULTDEV
|
|
|
|
|
try:
|
|
|
|
|
# Obtener la IP del servidor
|
|
|
|
|
#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
|
|
|
|
|
template_path = os.path.join(WORKDIR, "ogboot/etc/nginxServer.conf.tmpl")
|
|
|
|
|
template_path = os.path.join(REPO_DIR, "etc/nginxServer.conf.tmpl")
|
|
|
|
|
with open(template_path, 'r') as nginx_file:
|
|
|
|
|
nginx_content = nginx_file.read()
|
|
|
|
|
|
|
|
|
|
nginx_content = nginx_content.replace("__SERVERIP__", ip_address_server)
|
|
|
|
|
nginx_content = nginx_content.replace("__PHPVERSION__", php_version)
|
|
|
|
|
nginx_content = nginx_content.replace("__ROOT__", INSTALL_OGBOOT_TARGET)
|
|
|
|
|
|
|
|
|
|
# Ruta de destino para la configuración de nginx
|
|
|
|
|
nginx_output = "/etc/nginx/sites-available/ogboot.conf"
|
|
|
|
@ -779,12 +666,10 @@ def setup_nginx():
|
|
|
|
|
logger.info("Nginx configuration file created successfully.")
|
|
|
|
|
|
|
|
|
|
# Crear el enlace simbólico en sites-enabled
|
|
|
|
|
subprocess.run(["sudo", "ln", "-sf", nginx_output, "/etc/nginx/sites-enabled/ogboot.conf"])
|
|
|
|
|
subprocess.run(["ln", "-sf", nginx_output, "/etc/nginx/sites-enabled/ogboot.conf"])
|
|
|
|
|
|
|
|
|
|
logger.info("Symbolic link for nginx configuration created successfully.")
|
|
|
|
|
|
|
|
|
|
logger.info("Samba service restarted successfully.")
|
|
|
|
|
|
|
|
|
|
# Modificar el archivo de configuración de nginx para ejecutarse como ogboot
|
|
|
|
|
nginx_conf_path = "/etc/nginx/nginx.conf"
|
|
|
|
|
with open(nginx_conf_path, 'r') as nginx_conf_file:
|
|
|
|
@ -798,7 +683,7 @@ def setup_nginx():
|
|
|
|
|
logger.info("Nginx configuration file modified to run as ogboot.")
|
|
|
|
|
|
|
|
|
|
# Reiniciar el servicio de samba
|
|
|
|
|
subprocess.run(["sudo", "systemctl", "restart", "nginx.service"])
|
|
|
|
|
subprocess.run(["systemctl", "restart", "nginx.service"])
|
|
|
|
|
|
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
|
logger.error(f"Subprocess error: {e}")
|
|
|
|
@ -823,14 +708,14 @@ def get_php_fpm_version():
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
def modify_php_fpm_config():
|
|
|
|
|
php_version = get_php_fpm_version() # Establecemos la versión de PHP a 8.2
|
|
|
|
|
php_version = get_php_fpm_version()
|
|
|
|
|
php_fpm_conf_path = f"/etc/php/{php_version}/fpm/pool.d/www.conf"
|
|
|
|
|
new_fpm_conf_path = f"/etc/php/{php_version}/fpm/pool.d/ogboot.conf"
|
|
|
|
|
socket_path = f"/run/php/php{php_version}-fpm-ogboot.sock"
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# Copiar www.conf a ogboot.conf
|
|
|
|
|
subprocess.run(["sudo", "cp", php_fpm_conf_path, new_fpm_conf_path], check=True)
|
|
|
|
|
subprocess.run(["cp", php_fpm_conf_path, new_fpm_conf_path], check=True)
|
|
|
|
|
logger.info(f"Archivo {php_fpm_conf_path} copiado a {new_fpm_conf_path}")
|
|
|
|
|
|
|
|
|
|
# Leer el archivo copiado ogboot.conf
|
|
|
|
@ -858,7 +743,7 @@ def modify_php_fpm_config():
|
|
|
|
|
logger.info(f"Archivo {new_fpm_conf_path} modificado correctamente.")
|
|
|
|
|
|
|
|
|
|
# Reiniciar el servicio PHP-FPM
|
|
|
|
|
subprocess.run(["sudo", "systemctl", "restart", f"php{php_version}-fpm"], check=True)
|
|
|
|
|
subprocess.run(["systemctl", "restart", f"php{php_version}-fpm"], check=True)
|
|
|
|
|
logger.info("Servicio PHP-FPM reiniciado correctamente.")
|
|
|
|
|
|
|
|
|
|
# Verificar que el socket se ha creado
|
|
|
|
@ -880,15 +765,13 @@ logger.info(f":::::::::::::::::::::::: Starting ogBoot installation ::::::::::::
|
|
|
|
|
|
|
|
|
|
logger.info("environment variables")
|
|
|
|
|
logger.info(f"OGCORE_IP:{OGCORE_IP}")
|
|
|
|
|
logger.info(f"INSTALL_TARGET:{INSTALL_TARGET}")
|
|
|
|
|
logger.info(f"INSTALL_OGBOOT_TARGET:{INSTALL_OGBOOT_TARGET}")
|
|
|
|
|
logger.info(f"INSTALL_OPENGNSYS_TARGET:{INSTALL_OPENGNSYS_TARGET}")
|
|
|
|
|
logger.info(f"GIT_REPO:{GIT_REPO}")
|
|
|
|
|
|
|
|
|
|
if os.geteuid() != 0:
|
|
|
|
|
logger.error("This program must be run with root privileges..")
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
## doc no existe nunca
|
|
|
|
|
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..")
|
|
|
|
|
exit(2)
|
|
|
|
@ -901,17 +784,9 @@ except Exception as e:
|
|
|
|
|
logger.error(f"Error verifying Python distribution or version: {e}")
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
logger.info("Checking the operating system.")
|
|
|
|
|
autoConfigure()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"Error checking the operating system: {e}")
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
logger.info("Installing necessary packages.")
|
|
|
|
|
Missing = get_missing_packages()
|
|
|
|
|
install_packages(Missing)
|
|
|
|
|
install_packages()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"Error installing necessary packages: {e}")
|
|
|
|
|
exit(1)
|
|
|
|
@ -924,23 +799,6 @@ except Exception as e:
|
|
|
|
|
logger.error(f"Error obtaining network configuration: {e}")
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
logger.info("Configuring package repositories.")
|
|
|
|
|
if REMOTE == 1:
|
|
|
|
|
downloadCode(GIT_REPO)
|
|
|
|
|
else:
|
|
|
|
|
if os.path.exists(f"{WORKDIR}/ogboot"):
|
|
|
|
|
os.remove(f"{WORKDIR}/ogboot")
|
|
|
|
|
logger.info(f"Existing symbolic link to ogBoot directory removed.")
|
|
|
|
|
if not os.path.exists(WORKDIR):
|
|
|
|
|
os.makedirs(WORKDIR, mode=0o775, exist_ok=True)
|
|
|
|
|
logger.info(f"{WORKDIR}/ogboot directory created")
|
|
|
|
|
logger.info(f"Creating a symbolic link to the code directory")
|
|
|
|
|
os.symlink(os.path.dirname(PROGRAM_DIR), f"{WORKDIR}/ogboot")
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"Error configuring package repositories: {e}")
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
add_sudoers_permissions()
|
|
|
|
|
except Exception as e:
|
|
|
|
@ -1012,19 +870,12 @@ except Exception as e:
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
logger.info("Setting up NFS system")
|
|
|
|
|
mount_NFS()
|
|
|
|
|
logger.info("Installing iPXE")
|
|
|
|
|
install_ipxe()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"Error setting up NFS system: {e}")
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
logger.info("Compiling OpenGnsys services source code")
|
|
|
|
|
servicesCompilation()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"Error compiling OpenGnsys services: {e}")
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
logger.info("Copy folder Interface between administration and cloning engine")
|
|
|
|
|
copyInterfaceAdm()
|
|
|
|
@ -1055,7 +906,7 @@ except Exception as e:
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
logger.info("Configuring ogCore")
|
|
|
|
|
openGnsysConfigure()
|
|
|
|
|
tzConfigure()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"Error configuring ogCore: {e}")
|
|
|
|
|
exit(1)
|
|
|
|
|