refs #401 adds news directories before composer install
parent
2756508e16
commit
144265b66d
|
@ -5,7 +5,7 @@
|
||||||
##### Autor: Antonio Emmanuel Guerrero Silva <aguerrero@qindel.com> ########
|
##### Autor: Antonio Emmanuel Guerrero Silva <aguerrero@qindel.com> ########
|
||||||
#################################################################################
|
#################################################################################
|
||||||
|
|
||||||
import platform, os, sys, subprocess, datetime, shutil, argparse, time
|
import platform, os, sys, subprocess, datetime, shutil, argparse, time, pwd
|
||||||
|
|
||||||
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
|
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
|
||||||
|
|
||||||
|
@ -285,16 +285,67 @@ def generate_config_url():
|
||||||
return f"https://dl.cloudsmith.io/public/isc/kea-2-0/config.deb.txt?distro=ubuntu&codename={codename}&version={version}&arch={arch}"
|
return f"https://dl.cloudsmith.io/public/isc/kea-2-0/config.deb.txt?distro=ubuntu&codename={codename}&version={version}&arch={arch}"
|
||||||
|
|
||||||
def create_ogboot_project(path_opengnsys_base):
|
def create_ogboot_project(path_opengnsys_base):
|
||||||
|
# Verificar si el usuario 'ogboot' ya existe
|
||||||
|
try:
|
||||||
|
pwd.getpwnam('ogboot')
|
||||||
|
print("El usuario 'ogboot' ya existe")
|
||||||
|
except KeyError:
|
||||||
subprocess.run(["sudo", "useradd", "-m", "ogboot"])
|
subprocess.run(["sudo", "useradd", "-m", "ogboot"])
|
||||||
#subprocess.run(["composer", "create-project", "--no-interaction", "symfony/website-skeleton", path_opengnsys_base], user="root")
|
|
||||||
#parent_dir = os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))
|
# Verificar si el directorio ya existe
|
||||||
#composer_json_path = os.path.join(parent_dir, 'composer.json')
|
if os.path.exists(path_opengnsys_base):
|
||||||
subprocess.run(["composer", "create-project", "symfony/website-skeleton", path_opengnsys_base])
|
if not os.path.isdir(path_opengnsys_base):
|
||||||
|
raise NotADirectoryError(f"{path_opengnsys_base} existe y no es un directorio.")
|
||||||
|
else:
|
||||||
|
print(f"El directorio {path_opengnsys_base} ya existe.")
|
||||||
|
else:
|
||||||
|
os.makedirs(path_opengnsys_base)
|
||||||
|
# Cambiar el propietario del directorio a 'ogboot' si se creó por primera vez
|
||||||
|
subprocess.run(["sudo", "chown", "-R", "ogboot:ogboot", path_opengnsys_base])
|
||||||
|
|
||||||
|
# Copiar los archivos .env y composer.json primero
|
||||||
|
shutil.copy(f"{WORKDIR}/ogboot/.env", os.path.join(path_opengnsys_base, ".env"))
|
||||||
|
shutil.copy(f"{WORKDIR}/ogboot/composer.json", os.path.join(path_opengnsys_base, "composer.json"))
|
||||||
|
print(".env y composer.json copiados a", path_opengnsys_base)
|
||||||
|
bin_source = os.path.join(WORKDIR, "ogboot/bin")
|
||||||
|
bin_dest = os.path.join(path_opengnsys_base, "bin")
|
||||||
|
src_source = os.path.join(WORKDIR, "ogboot/src")
|
||||||
|
src_dest = os.path.join(path_opengnsys_base, "src")
|
||||||
|
|
||||||
|
config_source = os.path.join(WORKDIR, "ogboot/config")
|
||||||
|
config_dest = os.path.join(path_opengnsys_base, "config")
|
||||||
|
if os.path.exists(bin_dest):
|
||||||
|
shutil.rmtree(bin_dest)
|
||||||
|
shutil.copytree(bin_source, bin_dest)
|
||||||
|
|
||||||
|
if os.path.exists(src_dest):
|
||||||
|
shutil.rmtree(src_dest)
|
||||||
|
shutil.copytree(src_source, src_dest)
|
||||||
|
|
||||||
|
if os.path.exists(config_dest):
|
||||||
|
shutil.rmtree(config_dest)
|
||||||
|
shutil.copytree(config_source, config_dest)
|
||||||
|
|
||||||
|
subprocess.run(["sudo", "chmod", "-R", "755", path_opengnsys_base])
|
||||||
|
subprocess.run(["sudo", "chown", "-R", "ogboot:ogboot", path_opengnsys_base])
|
||||||
|
print("Esperando 20 segundos...")
|
||||||
|
time.sleep(20)
|
||||||
|
# Ejecutar Composer como el usuario 'ogboot' para instalar el proyecto Symfony
|
||||||
|
result = subprocess.run(["sudo", "-u", "ogboot", "composer", "install", "--no-interaction", "--working-dir", path_opengnsys_base])
|
||||||
|
if result.returncode != 0:
|
||||||
|
print("Error al crear el proyecto Symfony usando Composer")
|
||||||
|
return
|
||||||
|
|
||||||
os.chdir(path_opengnsys_base)
|
os.chdir(path_opengnsys_base)
|
||||||
shutil.copy(f"{WORKDIR}/ogboot/.env", INSTALL_TARGET)
|
|
||||||
subprocess.run(["rm", f"{path_opengnsys_base}/composer.lock"])
|
# Eliminar composer.lock si existe
|
||||||
|
composer_lock_path = os.path.join(path_opengnsys_base, "composer.lock")
|
||||||
|
if os.path.exists(composer_lock_path):
|
||||||
|
os.remove(composer_lock_path)
|
||||||
|
|
||||||
print("Esqueleto de la aplicación creado y archivo composer.lock eliminado.")
|
print("Esqueleto de la aplicación creado y archivo composer.lock eliminado.")
|
||||||
|
|
||||||
|
|
||||||
def createDirs(INSTALL_TARGET):
|
def createDirs(INSTALL_TARGET):
|
||||||
if not os.path.exists(INSTALL_TARGET):
|
if not os.path.exists(INSTALL_TARGET):
|
||||||
try:
|
try:
|
||||||
|
@ -438,28 +489,49 @@ def testPxe():
|
||||||
os.remove(f"{TFTPCFGDIR}/testpxe")
|
os.remove(f"{TFTPCFGDIR}/testpxe")
|
||||||
|
|
||||||
def tftpConfigure():
|
def tftpConfigure():
|
||||||
echoAndLog(f"{tftpConfigure.__name__}(): Configuring TFTP service.")
|
echoAndLog(f"{tftpConfigure.__name__}(): Configurando el servicio TFTP.")
|
||||||
|
|
||||||
# Habilitar TFTP y reiniciar Inetd.
|
# Habilitar TFTP y reiniciar Inetd.
|
||||||
if TFTPSERV:
|
if TFTPSERV:
|
||||||
if os.path.isfile(f"{INETDCFGDIR}/{TFTPSERV}"):
|
echoAndLog(f"TFTPSERV está configurado: {TFTPSERV}")
|
||||||
with open(f"{INETDCFGDIR}/{TFTPSERV}", "r+") as file:
|
|
||||||
|
inetd_cfg_path = f"{INETDCFGDIR}/{TFTPSERV}"
|
||||||
|
if os.path.isfile(inetd_cfg_path):
|
||||||
|
echoAndLog(f"El archivo de configuración de inetd existe: {inetd_cfg_path}")
|
||||||
|
|
||||||
|
with open(inetd_cfg_path, "r+") as file:
|
||||||
content = file.read()
|
content = file.read()
|
||||||
content = content.replace("disable.*", "disable = no")
|
new_content = content.replace("disable.*", "disable = no")
|
||||||
|
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
file.write(content)
|
file.write(new_content)
|
||||||
file.truncate()
|
file.truncate()
|
||||||
|
|
||||||
|
echoAndLog(f"Archivo de configuración de inetd modificado: {inetd_cfg_path}")
|
||||||
else:
|
else:
|
||||||
service = TFTPSERV
|
service = TFTPSERV
|
||||||
subprocess.run(["systemctl", "enable", f"{service}.service"])
|
echoAndLog(f"Habilitando y arrancando el servicio {service}.service")
|
||||||
subprocess.run(["systemctl", "start", f"{service}.service"])
|
|
||||||
service = INETDSERV
|
|
||||||
subprocess.run(["systemctl", "enable", f"{service}.service"])
|
|
||||||
subprocess.run(["systemctl", "start", f"{service}.service"])
|
|
||||||
|
|
||||||
os.symlink("/var/lib/tftpboot", f"{INSTALL_TARGET}/tftpboot")
|
subprocess.run(["systemctl", "enable", f"{service}.service"], check=True)
|
||||||
# comprobamos el servicio tftp
|
subprocess.run(["systemctl", "start", f"{service}.service"], check=True)
|
||||||
#time.sleep(1)
|
|
||||||
#testPxe()
|
service = INETDSERV
|
||||||
|
echoAndLog(f"Habilitando y arrancando el servicio {service}.service")
|
||||||
|
|
||||||
|
subprocess.run(["systemctl", "enable", f"{service}.service"], check=True)
|
||||||
|
subprocess.run(["systemctl", "start", f"{service}.service"], check=True)
|
||||||
|
|
||||||
|
symlink_target = f"{INSTALL_TARGET}/tftpboot"
|
||||||
|
echoAndLog(f"Creando enlace simbólico de /var/lib/tftpboot a {symlink_target}")
|
||||||
|
|
||||||
|
if not os.path.exists(symlink_target):
|
||||||
|
os.symlink("/var/lib/tftpboot", symlink_target)
|
||||||
|
else:
|
||||||
|
echoAndLog(f"El enlace simbólico ya existe: {symlink_target}")
|
||||||
|
|
||||||
|
# Comprobamos el servicio tftp
|
||||||
|
# time.sleep(1)
|
||||||
|
# testPxe()
|
||||||
|
|
||||||
def mount_NFS():
|
def mount_NFS():
|
||||||
if subprocess.call(["sudo", "mount", "-t", "nfs", "ognartefactos.evlt.uma.es:/", "/mnt"]) == 0:
|
if subprocess.call(["sudo", "mount", "-t", "nfs", "ognartefactos.evlt.uma.es:/", "/mnt"]) == 0:
|
||||||
|
|
Loading…
Reference in New Issue