60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
import os
|
|
import subprocess
|
|
|
|
print (">>>>>>>>>>>>>>>>>>>> Load ", __name__, " <<<<<<<<<<<<<<<<<<<<<<")
|
|
|
|
print("==============================================")
|
|
print("OpenGnsys Clonning Engine Start...")
|
|
# Cargar entorno de OpenGnsys
|
|
#os.environ['OGETC'] = '/opt/opengnsys/etc' #Entorno opengnsys
|
|
os.environ['OGETC'] = 'etc' #Pruebas locales
|
|
print (f"OGETC: {os.environ['OGETC']}")
|
|
|
|
os.environ['PYTHONUNBUFFERED'] = '1'
|
|
print (f"PYTHONUNBUFFERED: {os.environ['PYTHONUNBUFFERED']}")
|
|
|
|
#loadenviron_path = os.path.join(os.environ['OGETC'], 'preinit', 'loadenviron.sh')
|
|
loadenviron_path = os.path.join(os.environ['OGETC'], 'preinit', 'loadenviron.py')
|
|
print (f"loadenviron_path: {loadenviron_path}")
|
|
print ("s//////////////////////////////////////////////////")
|
|
# Ejecutar el script y cargar las variables de entorno en Python
|
|
exec(open(loadenviron_path).read())
|
|
|
|
# Configurar las variables de entorno globales
|
|
for key, value in globals().items():
|
|
if isinstance(value, str):
|
|
os.environ[key] = value
|
|
|
|
print ("Variables de entorno cargadas desde loadenviron.py")
|
|
|
|
# Ejecutar un subproceso que utilizará las nuevas variables de entorno
|
|
################################################################################subprocess.run(['bash', '-c', 'env'], shell=True)
|
|
# Scripts de inicio
|
|
print ("step 2.1 >>>>>>>>>>>>>>>>>>>>>>>>>>")
|
|
scripts = ['fileslinks', 'loadmodules', 'metadevs', 'mountrepo', 'poweroff', 'otherservices']
|
|
for script in scripts:
|
|
script_path = os.path.join(os.environ['OGETC'], 'preinit', f'{script}.py')
|
|
print (f"<<<<<< script_path: {script_path}")
|
|
#subprocess.run(['bash', script_path])
|
|
subprocess.run(['python3', script_path])
|
|
|
|
print ("step 2.2 >>>>>>>>>>>>>>>>>>>>>>>>>>")
|
|
# Check and run the appropriate init script
|
|
init_scripts = [
|
|
os.path.join(os.environ['OGETC'], 'init', f'{os.environ.get("IPV4ADDR", "")}.sh'),
|
|
os.path.join(os.environ['OGETC'], 'init', f'{os.environ.get("OGGROUP", "")}.sh'),
|
|
os.path.join(os.environ['OGETC'], 'init', 'default.sh')
|
|
]
|
|
|
|
print ("step 2.3 >>>>>>>>>>>>>>>>>>>>>>>>>>")
|
|
for script in init_scripts:
|
|
if os.path.isfile(script):
|
|
subprocess.run(['bash', script])
|
|
break
|
|
else:
|
|
print("No se ha encontrado script de inicio (RUN halt)")
|
|
#subprocess.run(['halt'])
|
|
|
|
print("OpenGnsys Clonning Engine End.")
|
|
print("==============================================")
|