refs #700 fixed errors

ticket-700
Antonio Guerrero 2024-10-08 14:42:12 -06:00
parent f3d4009501
commit 35011be213
2 changed files with 62 additions and 8 deletions

View File

@ -4,14 +4,19 @@ import subprocess
print("==============================================")
print("OpenGnsys Clonning Engine Start...")
# Cargar entorno de OpenGnsys
os.environ['OGETC'] = '/opt/opengnsys/etc'
#os.environ['OGETC'] = '/opt/opengnsys/etc' #Entorno opengnsys
os.environ['OGETC'] = 'shared/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.sh')
loadenviron_path = os.path.join(os.environ['OGETC'], 'preinit', 'loadenviron.py')
print (f"loadenviron_path: {loadenviron_path}")
exec(open(loadenviron_path).read())
print ("set environment:")
subprocess.run(['bash', '-c', f'set -a && source {loadenviron_path} && set +a'], shell=True)
print("==============================================")

View File

@ -1,15 +1,36 @@
import os
import subprocess
#!/usr/bin/env python3
print("=============== START LOAD ENVIRONMENT =================")
# Idioma por defecto.
os.environ["LANG"] = os.getenv("LANG", "es_ES")
subprocess.run(["locale-gen", os.environ["LANG"]])
print("-- step 2")
os.environ["LC_ALL"] = os.getenv("LC_ALL", os.environ["LANG"])
print("-- step 3")
result = subprocess.run(["locale-gen", os.environ["LANG"]], capture_output=True, text=True)
if result.returncode != 0:
print(f"Error generating locale: {result.stderr}")
print("-- step 4")
opengnsys_path = os.environ['OPENGNSYS']
print(f"OPENGNSYS Directory: {opengnsys_path}")
print("-- step 5")
# Directorios del proyecto OpenGnsys.
os.environ["OPENGNSYS"] = os.getenv("OPENGNSYS", "/opt/opengnsys")
print("-- step 6")
print (f"OPENGNSYS: {os.environ['OPENGNSYS']}")
if os.path.isdir(os.environ["OPENGNSYS"]):
print("OPENGNSYS directory found")
os.environ["OGBIN"] = os.path.join(os.environ["OPENGNSYS"], "bin")
os.environ["OGETC"] = os.path.join(os.environ["OPENGNSYS"], "etc")
os.environ["OGLIB"] = os.path.join(os.environ["OPENGNSYS"], "lib")
@ -32,7 +53,7 @@ if os.path.isdir(os.environ["OPENGNSYS"]):
os.environ["OGAPI"],
os.environ["OGBIN"]
])
print("-- step 7")
# Exportar parámetros del kernel.
with open("/proc/cmdline") as f:
for i in f.read().split():
@ -40,6 +61,7 @@ if os.path.isdir(os.environ["OPENGNSYS"]):
key, value = i.split("=", 1)
os.environ[key] = value
print("-- step 8")
# Cargar fichero de idioma.
lang_file = os.path.join(os.environ["OGETC"], f"lang.{os.environ['LANG'].split('@')[0]}.conf")
if os.path.isfile(lang_file):
@ -48,18 +70,39 @@ if os.path.isdir(os.environ["OPENGNSYS"]):
if "=" in line:
key, value = line.strip().split("=", 1)
os.environ[key] = value
print("-- step 9")
# Mensaje de carga del entorno.
print(os.getenv("MSG_LOADAPI", "."))
print("-- step 10")
# Cargar mapa de teclado.
subprocess.run(["loadkeys", os.environ["LANG"].split("_")[0]], stdout=subprocess.DEVNULL)
print("-- step 10.1")
# Imprimir todas las variables de entorno declaradas hasta el momento.
for key, value in os.environ.items():
print(f"{key}: {value}")
print("-- step 11")
# Cargar API de funciones.
def execute_lib_file(filepath):
with open(filepath) as f:
code = compile(f.read(), filepath, 'exec')
exec(code, globals())
for lib_file in os.listdir(os.environ["OGAPI"]):
if lib_file.endswith(".lib"):
exec(open(os.path.join(os.environ["OGAPI"], lib_file)).read())
execute_lib_file(os.path.join(os.environ["OGAPI"], lib_file))
# for lib_file in os.listdir(os.environ["OGAPI"]):
# if lib_file.endswith(".lib"):
# exec(open(os.path.join(os.environ["OGAPI"], lib_file)).read())
print("-- step 12")
# Cargar configuración del engine.
engine_cfg = os.path.join(os.environ["OGETC"], "engine.cfg")
if os.path.isfile(engine_cfg):
@ -67,6 +110,8 @@ if os.path.isdir(os.environ["OPENGNSYS"]):
os.environ["OGLOGCOMMAND"] = os.getenv("OGLOGCOMMAND", "/tmp/command.log")
os.environ["OGLOGSESSION"] = os.getenv("OGLOGSESSION", "/tmp/session.log")
print("-- step 13")
# Cargar las APIs según engine.
ogengine = os.getenv("ogengine")
if ogengine:
@ -74,6 +119,7 @@ if os.path.isdir(os.environ["OPENGNSYS"]):
if api_file.endswith(f".{ogengine}"):
exec(open(os.path.join(os.environ["OGAPI"], api_file)).read())
print("-- step 14")
# Configuración de la red (modo offline).
initrd_cfg = "/tmp/initrd.cfg"
if os.path.isfile(initrd_cfg):
@ -85,6 +131,7 @@ if os.path.isdir(os.environ["OPENGNSYS"]):
if os.path.isfile(device_cfg):
exec(open(device_cfg).read())
print("-- step 15")
# FIXME Pruebas para grupos de ordenadores
os.environ["OGGROUP"] = os.getenv("group", "")
@ -93,6 +140,8 @@ if os.path.isdir(os.environ["OPENGNSYS"]):
# Fichero de registros.
og_log_file = os.path.join(os.environ["OGLOG"], f"{ogGetIpAddress()}.log")
os.environ["OGLOGFILE"] = og_log_file
else:
print("ERROR: OPENGNSYS directory not found")
# Compatibilidad para usar proxy en clientes ogLive.
if not os.getenv("http_proxy") and os.getenv("ogproxy"):