Refs 401 Fixed version of python3 installer added
parent
ef5aeacffa
commit
68a7b438e5
|
@ -1,11 +1,8 @@
|
|||
#!ipxe
|
||||
echo Booting by ipxe
|
||||
echo MAC Address: ${net0/mac}
|
||||
set macaddress ${net0/mac}
|
||||
set prefix tftp://SERVERIP/ipxe_scripts
|
||||
echo Prefix: ${prefix}
|
||||
set prefix tftp://__SERVERIP__/ipxe_scripts
|
||||
set configfile ${prefix}/01-${net0/mac}
|
||||
echo Config File: ${configfile}
|
||||
ifopen net0
|
||||
route
|
||||
# Intentar cargar la configuración personalizada por MAC
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
comment = OpenGnsys init files
|
||||
browseable = no
|
||||
writeable = no
|
||||
path = OGBOOTDIR/tftpboot
|
||||
path = __OGBOOTDIR__/tftpboot
|
||||
guest ok = no
|
||||
|
||||
[ogclient]
|
||||
|
@ -10,5 +10,5 @@
|
|||
browseable = no
|
||||
writeable = no
|
||||
locking = no
|
||||
path = OGBOOTDIR/client
|
||||
path = __OGBOOTDIR__/client
|
||||
guest ok = no
|
||||
|
|
|
@ -7,13 +7,15 @@
|
|||
|
||||
import platform, os, sys, subprocess, datetime, shutil, argparse, time
|
||||
|
||||
global UBUNTU_OS_VERSION, OPENGNGYS_VERSION, PYTHON_VERSION, DEPENDENCIES2, INSTALL_OGBOOT_TARGET, WORK_DIR, LOG_FILE, CHECKPKG, INSTALLPKG, PATH, PROGRAM_DIR, OPENGNSYS_SERVER, UPDATEPKGLIST
|
||||
global UBUNTU_OS_VERSION, OPENGNGYS_VERSION, PYTHON_VERSION_LAST, PYTHON_VERSION, DEPENDENCIES2, INSTALL_OGBOOT_TARGET, WORK_DIR, LOG_FILE, CHECKPKG, INSTALLPKG, PATH, PROGRAM_DIR, OPENGNSYS_SERVER, UPDATEPKGLIST
|
||||
|
||||
UPDATEPKGLIST = ""
|
||||
UBUNTU_OS_VERSION = "22"
|
||||
OPENGNGYS_VERSION = "1.2.0"
|
||||
PYTHON_VERSION = 3
|
||||
PYTHON_VERSION_LAST = 0
|
||||
INSTALL_TARGET="/opt/ogboot"
|
||||
INSTALL_OPENGNSYS_TARGET = "/opt/opengnsys"
|
||||
INSTALL_OGBOOT_TARGET = "/opt/ogboot"
|
||||
WORK_DIR = "/tmp/ogboot_installer"
|
||||
DEPENDENCIES2 = []
|
||||
|
@ -64,8 +66,8 @@ TFTPCFGDIR = "/var/lib/tftpboot"
|
|||
PHPFPMSERV = "php7.2-fpm"
|
||||
INETDCFGDIR = "/etc/xinetd.d/"
|
||||
INETDSERV = "xinetd"
|
||||
OPENGNSYS_CLIENT_PASSWD="passusuog"
|
||||
OPENGNSYS_CLIENT_USER="usuog"
|
||||
OPENGNSYS_CLIENT_PASSWD="og"
|
||||
OPENGNSYS_CLIENT_USER="opengnsys"
|
||||
|
||||
required_packages_18 = [
|
||||
"apache2", "arp-scan", "automake", "build-essential", "btrfs-progs", "composer", "curl", "ctorrent",
|
||||
|
@ -111,37 +113,38 @@ def errorAndLog(message):
|
|||
print(log_message)
|
||||
|
||||
def check_python_version():
|
||||
try:
|
||||
# Obtener la versión de Python instalada
|
||||
python_version = platform.python_version()
|
||||
try:
|
||||
# Obtener la versión de Python instalada
|
||||
python_version = platform.python_version()
|
||||
|
||||
# Convertir la versión a una tupla para comparar fácilmente
|
||||
python_version_tuple = tuple(map(int, python_version.split('.')))
|
||||
# Convertir la versión a una tupla para comparar fácilmente
|
||||
python_version_tuple = tuple(map(int, python_version.split('.')))
|
||||
|
||||
# Verificar si la versión es al menos PYTHON_VERSION.x
|
||||
if python_version_tuple >= (PYTHON_VERSION, 0):
|
||||
echoAndLog(f"LOG\tVersión de python instalada: {python_version}")
|
||||
else:
|
||||
echoAndLog(f"ERROR\tVersión de python es inferior a la requerida. Version instalada: {python_version}" + ".")
|
||||
exit()
|
||||
except Exception as e:
|
||||
echoAndLog(f"ERROR\tProblema al verificar la versión de Python: {e}")
|
||||
exit()
|
||||
# Verificar si la versión es al menos PYTHON_VERSION.x
|
||||
if python_version_tuple >= (PYTHON_VERSION, 0):
|
||||
echoAndLog(f"LOG\tVersión de python instalada: {python_version}")
|
||||
PYTHON_VERSION_LAST = platform.python_version()
|
||||
else:
|
||||
echoAndLog(f"ERROR\tVersión de python es inferior a la requerida. Version instalada: {python_version}" + ".")
|
||||
exit()
|
||||
except Exception as e:
|
||||
echoAndLog(f"ERROR\tProblema al verificar la versión de Python: {e}")
|
||||
exit()
|
||||
|
||||
def check_distribution():
|
||||
if os.path.exists("/etc/os-release"):
|
||||
with open("/etc/os-release", "r") as file:
|
||||
for line in file:
|
||||
if line.startswith("VERSION"):
|
||||
VERSION = line.split("=")[1].strip().strip('"')
|
||||
break
|
||||
if VERSION.startswith(UBUNTU_OS_VERSION + "."):
|
||||
return
|
||||
print(f"La instalación de OpenGnsys {OPENGNGYS_VERSION} se ha probado con funcionalidad completa sobre Ubuntu {UBUNTU_OS_VERSION}")
|
||||
go_on = input("Desea continuar? [s/N]: ")
|
||||
if go_on.upper() != "S":
|
||||
print("Abandonando la instalación.")
|
||||
exit()
|
||||
if os.path.exists("/etc/os-release"):
|
||||
with open("/etc/os-release", "r") as file:
|
||||
for line in file:
|
||||
if line.startswith("VERSION"):
|
||||
VERSION = line.split("=")[1].strip().strip('"')
|
||||
break
|
||||
if VERSION.startswith(UBUNTU_OS_VERSION + "."):
|
||||
return
|
||||
print(f"La instalación de OpenGnsys {OPENGNGYS_VERSION} se ha probado con funcionalidad completa sobre Ubuntu {UBUNTU_OS_VERSION}")
|
||||
go_on = input("Desea continuar? [s/N]: ")
|
||||
if go_on.upper() != "S":
|
||||
print("Abandonando la instalación.")
|
||||
exit()
|
||||
|
||||
def cidr2mask(cidr):
|
||||
# Number of args to shift, 255..255, first non-255 byte, zeroes
|
||||
|
@ -171,19 +174,19 @@ def downloadCode(url):
|
|||
###:::::::::::::::::::::::::::::: INSTALL ::::::::::::::::::::::::::::::::::###
|
||||
###############################################################################
|
||||
def is_installed(package):
|
||||
try:
|
||||
# Verifica si el paquete está instalado
|
||||
subprocess.run(["dpkg", "-s", package], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
return True
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
try:
|
||||
# Verifica si el paquete está instalado
|
||||
subprocess.run(["dpkg", "-s", package], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
return True
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
|
||||
def get_missing_packages(packages):
|
||||
faltantes = []
|
||||
for package in packages:
|
||||
if not is_installed(package):
|
||||
faltantes.append(package)
|
||||
return faltantes
|
||||
faltantes = []
|
||||
for package in packages:
|
||||
if not is_installed(package):
|
||||
faltantes.append(package)
|
||||
return faltantes
|
||||
|
||||
def install_packages(missing, log_file="installed_packages.log"):
|
||||
if not missing:
|
||||
|
@ -196,7 +199,7 @@ def install_packages(missing, log_file="installed_packages.log"):
|
|||
with open(log_file, "a") as log:
|
||||
for package in missing:
|
||||
print(f"Instalando {package}")
|
||||
subprocess.run(["sudo", "apt-get", "install", "-y", package], check=True)
|
||||
subprocess.run(["sudo", "apt-get", "install", "--force-yes", "-y", package], check=True)
|
||||
print(f"{package} instalado correctamente.")
|
||||
log.write(package + "\n")
|
||||
print("Todos los paquetes faltantes han sido instalados.")
|
||||
|
@ -283,7 +286,8 @@ def generate_config_url():
|
|||
|
||||
def create_ogboot_project(path_opengnsys_base):
|
||||
subprocess.run(["sudo", "useradd", "-m", "ogboot"])
|
||||
subprocess.run(["composer", "create-project", "--no-interaction", "symfony/website-skeleton", path_opengnsys_base], user="root")
|
||||
#subprocess.run(["composer", "create-project", "--no-interaction", "symfony/website-skeleton", path_opengnsys_base], user="root")
|
||||
subprocess.run(["composer", "create-project", "--no-interaction", "symfony/website-skeleton", path_opengnsys_base])
|
||||
subprocess.run(["rm", f"{path_opengnsys_base}/composer.lock"])
|
||||
print("Esqueleto de la aplicación creado y archivo composer.lock eliminado.")
|
||||
|
||||
|
@ -452,6 +456,82 @@ def tftpConfigure():
|
|||
time.sleep(1)
|
||||
#testPxe()
|
||||
|
||||
def mount_NFS():
|
||||
if subprocess.call(["sudo", "mount", "-t", "nfs", "ognartefactos.evlt.uma.es:/", "/mnt"]) == 0:
|
||||
print("Sistema NFS montado correctamente.")
|
||||
else:
|
||||
print("Error: No se pudo montar el sistema NFS.")
|
||||
exit(1)
|
||||
|
||||
subprocess.call(["ls", "/mnt/"])
|
||||
|
||||
subprocess.call(["sudo", "cp", "-r", "/mnt/srv/artefactos/ipxe/", "/tmp"])
|
||||
|
||||
os.chdir("/tmp/ipxe/src")
|
||||
if subprocess.call(["sudo", "make", "-j", "4"]) == 0:
|
||||
print("Directorio /tmp/ipxe/src montado correctamente.")
|
||||
else:
|
||||
print("Error: No se pudo montar el directorio /tmp/ipxe/src.")
|
||||
exit(1)
|
||||
|
||||
if subprocess.call(["sudo", "make", "bin/undionly.kpxe", "EMBED=/opt/opengnsys/tftpboot/ipxe_scripts/dhcp_boot.ipxe"]) == 0:
|
||||
print("Fichero de arranque montado correctamente.")
|
||||
else:
|
||||
print("Error: No se pudo montar el fichero de arranque.")
|
||||
exit(1)
|
||||
|
||||
subprocess.call(["sudo", "cp", "bin/undionly.kpxe", "/opt/opengnsys/tftpboot"])
|
||||
|
||||
if subprocess.call(["sudo", "make", "bin-x86_64-efi/ipxe.efi", "EMBED=/opt/opengnsys/tftpboot/ipxe_scripts/dhcp_boot.ipxe"]) == 0:
|
||||
print("Fichero EFI construido correctamente.")
|
||||
else:
|
||||
print("Error: No se pudo construir el fichero EFI.")
|
||||
exit(1)
|
||||
|
||||
subprocess.call(["sudo", "cp", "bin-x86_64-efi/ipxe.efi", "/opt/opengnsys/tftpboot"])
|
||||
|
||||
|
||||
def generate_ipxe_script():
|
||||
print("Generando script IPXE...")
|
||||
#os.symlink(INSTALL_TARGET, INSTALL_OPENGNSYS_TARGET)
|
||||
#print(f"INSTALL_TARGET: {INSTALL_TARGET}")
|
||||
#print(f"INSTALL_OPENGNSYS_TARGET: {INSTALL_OPENGNSYS_TARGET}")
|
||||
#os.symlink(INSTALL_TARGET, INSTALL_OPENGNSYS_TARGET, target_is_directory=True)
|
||||
ip_address_server = subprocess.check_output(["ifconfig", "eth0"]).decode().split("\n")[1].split()[1]
|
||||
template = os.path.join(WORKDIR, "ogboot/etc/dhcp_boot.ipxe.tmpl")
|
||||
ipxe_output = "/opt/ogboot/tftpboot/ipxe_scripts/dhcp_boot.ipxe"
|
||||
|
||||
os.makedirs(os.path.dirname(ipxe_output), exist_ok=True)
|
||||
|
||||
print (f"copiando -{template}- a -{ipxe_output}-")
|
||||
print (f"reemplazando IP -{ip_address_server}- en -{ipxe_output}-")
|
||||
shutil.copy(template, ipxe_output)
|
||||
with open(ipxe_output, "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)
|
||||
|
||||
#################33
|
||||
# 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 = "ogboot/tftpboot/ipxe_scripts/default.ipxe"
|
||||
default_output = "/opt/ogboot/tftpboot/ipxe_scripts/default.ipxe"
|
||||
|
||||
with open(template_default, "r") as default_tmpl_file:
|
||||
default_template_content = default_tmpl_file.read()
|
||||
default_ipxe_content = default_template_content.replace("__SERVERIP__", ip_address_server)
|
||||
with open(default_output, "w") as default_ipxe_file:
|
||||
default_ipxe_file.write(default_ipxe_content)
|
||||
|
||||
print("Archivos creados correctamente.")
|
||||
|
||||
|
||||
def smbConfigure():
|
||||
echoAndLog(f"{smbConfigure.__name__}(): Configuring Samba service.")
|
||||
|
||||
|
@ -460,29 +540,43 @@ def smbConfigure():
|
|||
# Copiar plantilla de recursos para OpenGnsys
|
||||
with open(os.path.join(WORKDIR, 'ogboot/etc/smb-ogboot.conf.tmpl'), 'r') as tmpl_file:
|
||||
template = tmpl_file.read()
|
||||
replaced_template = template.replace('OGBOOTDIR', INSTALL_OGBOOT_TARGET)
|
||||
replaced_template = template.replace('OGBOOTDIR', INSTALL_TARGET)
|
||||
|
||||
with open(os.path.join(SAMBACFGDIR, 'smb-ogboot.conf'), 'w') as conf_file:
|
||||
conf_file.write(replaced_template)
|
||||
|
||||
# Configurar y recargar Samba"
|
||||
subprocess.run(["perl", "-pi", "-e", "s/WORKGROUP/OPENGNSYS/; s/server string \=.*/server string \= ogBoot Samba Server/", f"{SAMBACFGDIR}/smb.conf"])
|
||||
with open(f"{SAMBACFGDIR}/smb.conf", "a") as file:
|
||||
if not any("smb-ogboot" in line for line in file):
|
||||
if "smb-ogboot" not in open(f"{SAMBACFGDIR}/smb.conf").read():
|
||||
with open(f"{SAMBACFGDIR}/smb.conf", "a") as file:
|
||||
file.write(f"include = {SAMBACFGDIR}/smb-ogboot.conf\n")
|
||||
service = SAMBASERV
|
||||
subprocess.run([ENABLESERVICE])
|
||||
subprocess.run([STARTSERVICE])
|
||||
if subprocess.run(["echo", "$?"]).returncode != 0:
|
||||
errorAndLog(f"{smbConfigure.__name__}(): error while configure Samba")
|
||||
subprocess.run(["systemctl", "enable", f"{service}.service"])
|
||||
subprocess.run(["systemctl", "start", f"{service}.service"])
|
||||
# Comprobar si se ha configurado correctamente Samba
|
||||
if subprocess.run(["systemctl", "is-active", f"{service}.service"]).returncode == 0:
|
||||
print(f"{service} service started successfully.")
|
||||
else:
|
||||
errorAndLog(f"Failed to start {service} service.")
|
||||
return 1
|
||||
# Crear clave para usuario de acceso a los recursos.
|
||||
smbpasswd_command = f"echo -ne \"{OPENGNSYS_CLIENT_PASSWD}\\n{OPENGNSYS_CLIENT_PASSWD}\\n\" | smbpasswd -a -s {OPENGNSYS_CLIENT_USER}"
|
||||
subprocess.run(smbpasswd_command, shell=True)
|
||||
|
||||
# Establecer la contraseña para el usuario opengnsys
|
||||
smbpasswd_command = f"(echo {OPENGNSYS_CLIENT_PASSWD}; echo {OPENGNSYS_CLIENT_PASSWD}) | sudo smbpasswd -s -a {OPENGNSYS_CLIENT_USER}"
|
||||
if "Python 3.7" in {PYTHON_VERSION}:
|
||||
result = subprocess.run(smbpasswd_command, shell=True, capture_output=True, text=True)
|
||||
if result.returncode == 0:
|
||||
print(f"La contraseña para el usuario {OPENGNSYS_CLIENT_USER} se ha establecido correctamente.")
|
||||
else:
|
||||
print(f"Error al establecer la contraseña: {result.stderr}")
|
||||
else:
|
||||
print(f"python_version --({PYTHON_VERSION})--")
|
||||
#process = subprocess.Popen(smbpasswd_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
process = subprocess.Popen(smbpasswd_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout, stderr = process.communicate()
|
||||
if process.returncode == 0:
|
||||
print(f"La contraseña para el usuario {OPENGNSYS_CLIENT_USER} se ha establecido correctamente.")
|
||||
else:
|
||||
print(f"Error al establecer la contraseña: {stderr}")
|
||||
echoAndLog(f"{smbConfigure.__name__}(): Added Samba configuration.")
|
||||
return 0
|
||||
|
||||
###############################################################################
|
||||
###:::::::::::::::::::::::::::::::: MAIN :::::::::::::::::::::::::::::::::::###
|
||||
###############################################################################
|
||||
|
@ -495,7 +589,7 @@ if os.path.exists(os.path.join(INSTALL_OGBOOT_TARGET + "/doc/")):
|
|||
check_distribution()
|
||||
check_python_version()
|
||||
autoConfigure()
|
||||
Missing = get_missing_packages (required_packages_22)
|
||||
Missing = get_missing_packages (required_packages_18)
|
||||
install_packages(Missing)
|
||||
|
||||
if REMOTE == 1:
|
||||
|
@ -520,8 +614,13 @@ if os.system("echo $?") != 0:
|
|||
# Configuración de TFTP.
|
||||
tftpConfigure()
|
||||
|
||||
generate_ipxe_script()
|
||||
|
||||
# Montar sistema NFS.
|
||||
mount_NFS()
|
||||
|
||||
# Configuración de Samba.
|
||||
#smbConfigure()
|
||||
smbConfigure()
|
||||
|
||||
if subprocess.run(["echo", "$?"]).returncode != 0:
|
||||
errorAndLog("Error while configuring Samba server!")
|
||||
|
@ -574,5 +673,5 @@ elif args.dhcp == 'configure':
|
|||
pass
|
||||
pass
|
||||
elif args.dhcp == 'none':
|
||||
print("DHCP no será instalado ni configurado")
|
||||
pass
|
||||
print("DHCP no será instalado ni configurado")
|
||||
pass
|
Loading…
Reference in New Issue