1 | import os |
---|
2 | import subprocess |
---|
3 | |
---|
4 | #!/usr/bin/env python3 |
---|
5 | |
---|
6 | # Idioma por defecto. |
---|
7 | os.environ["LANG"] = os.getenv("LANG", "es_ES") |
---|
8 | subprocess.run(["locale-gen", os.environ["LANG"]]) |
---|
9 | |
---|
10 | # Directorios del proyecto OpenGnsys. |
---|
11 | os.environ["OPENGNSYS"] = os.getenv("OPENGNSYS", "/opt/opengnsys") |
---|
12 | if os.path.isdir(os.environ["OPENGNSYS"]): |
---|
13 | os.environ["OGBIN"] = os.path.join(os.environ["OPENGNSYS"], "bin") |
---|
14 | os.environ["OGETC"] = os.path.join(os.environ["OPENGNSYS"], "etc") |
---|
15 | os.environ["OGLIB"] = os.path.join(os.environ["OPENGNSYS"], "lib") |
---|
16 | os.environ["OGAPI"] = os.path.join(os.environ["OGLIB"], "engine", "bin") |
---|
17 | os.environ["OGSCRIPTS"] = os.path.join(os.environ["OPENGNSYS"], "scripts") |
---|
18 | os.environ["OGIMG"] = os.path.join(os.environ["OPENGNSYS"], "images") |
---|
19 | os.environ["OGCAC"] = os.path.join(os.environ["OPENGNSYS"], "cache") |
---|
20 | os.environ["OGLOG"] = os.path.join(os.environ["OPENGNSYS"], "log") |
---|
21 | |
---|
22 | os.environ["PATH"] = os.pathsep.join([ |
---|
23 | os.environ["PATH"], |
---|
24 | "/sbin", |
---|
25 | "/usr/sbin", |
---|
26 | "/usr/local/sbin", |
---|
27 | "/bin", |
---|
28 | "/usr/bin", |
---|
29 | "/usr/local/bin", |
---|
30 | "/opt/oglive/rootfs/opt/drbl/sbin", |
---|
31 | os.environ["OGSCRIPTS"], |
---|
32 | os.environ["OGAPI"], |
---|
33 | os.environ["OGBIN"] |
---|
34 | ]) |
---|
35 | |
---|
36 | # Exportar parámetros del kernel. |
---|
37 | with open("/proc/cmdline") as f: |
---|
38 | for i in f.read().split(): |
---|
39 | if "=" in i: |
---|
40 | key, value = i.split("=", 1) |
---|
41 | os.environ[key] = value |
---|
42 | |
---|
43 | # Cargar fichero de idioma. |
---|
44 | lang_file = os.path.join(os.environ["OGETC"], f"lang.{os.environ['LANG'].split('@')[0]}.conf") |
---|
45 | if os.path.isfile(lang_file): |
---|
46 | with open(lang_file) as f: |
---|
47 | for line in f: |
---|
48 | if "=" in line: |
---|
49 | key, value = line.strip().split("=", 1) |
---|
50 | os.environ[key] = value |
---|
51 | |
---|
52 | # Mensaje de carga del entorno. |
---|
53 | print(os.getenv("MSG_LOADAPI", ".")) |
---|
54 | |
---|
55 | # Cargar mapa de teclado. |
---|
56 | subprocess.run(["loadkeys", os.environ["LANG"].split("_")[0]], stdout=subprocess.DEVNULL) |
---|
57 | |
---|
58 | # Cargar API de funciones. |
---|
59 | for lib_file in os.listdir(os.environ["OGAPI"]): |
---|
60 | if lib_file.endswith(".lib"): |
---|
61 | exec(open(os.path.join(os.environ["OGAPI"], lib_file)).read()) |
---|
62 | |
---|
63 | # Cargar configuración del engine. |
---|
64 | engine_cfg = os.path.join(os.environ["OGETC"], "engine.cfg") |
---|
65 | if os.path.isfile(engine_cfg): |
---|
66 | exec(open(engine_cfg).read()) |
---|
67 | os.environ["OGLOGCOMMAND"] = os.getenv("OGLOGCOMMAND", "/tmp/command.log") |
---|
68 | os.environ["OGLOGSESSION"] = os.getenv("OGLOGSESSION", "/tmp/session.log") |
---|
69 | |
---|
70 | # Cargar las APIs según engine. |
---|
71 | ogengine = os.getenv("ogengine") |
---|
72 | if ogengine: |
---|
73 | for api_file in os.listdir(os.environ["OGAPI"]): |
---|
74 | if api_file.endswith(f".{ogengine}"): |
---|
75 | exec(open(os.path.join(os.environ["OGAPI"], api_file)).read()) |
---|
76 | |
---|
77 | # Configuración de la red (modo offline). |
---|
78 | initrd_cfg = "/tmp/initrd.cfg" |
---|
79 | if os.path.isfile(initrd_cfg): |
---|
80 | with open(initrd_cfg) as f: |
---|
81 | for line in f: |
---|
82 | if line.startswith("DEVICECFG="): |
---|
83 | device_cfg = line.strip().split("=", 1)[1] |
---|
84 | os.environ["DEVICECFG"] = device_cfg |
---|
85 | if os.path.isfile(device_cfg): |
---|
86 | exec(open(device_cfg).read()) |
---|
87 | |
---|
88 | # FIXME Pruebas para grupos de ordenadores |
---|
89 | os.environ["OGGROUP"] = os.getenv("group", "") |
---|
90 | |
---|
91 | root_repo = os.getenv("ROOTREPO", os.getenv("OGSERVERIMAGES")) |
---|
92 | |
---|
93 | # Fichero de registros. |
---|
94 | og_log_file = os.path.join(os.environ["OGLOG"], f"{ogGetIpAddress()}.log") |
---|
95 | os.environ["OGLOGFILE"] = og_log_file |
---|
96 | |
---|
97 | # Compatibilidad para usar proxy en clientes ogLive. |
---|
98 | if not os.getenv("http_proxy") and os.getenv("ogproxy"): |
---|
99 | os.environ["http_proxy"] = os.getenv("ogproxy") |
---|
100 | |
---|
101 | # Compatibilidad para usar servidor DNS en clientes ogLive. |
---|
102 | if not os.path.isfile("/run/resolvconf/resolv.conf") and os.getenv("ogdns"): |
---|
103 | os.makedirs("/run/resolvconf", exist_ok=True) |
---|
104 | with open("/run/resolvconf/resolv.conf", "w") as f: |
---|
105 | f.write(f"nameserver {os.getenv('ogdns')}\n") |
---|
106 | |
---|
107 | # Declaración de códigos de error. |
---|
108 | error_codes = { |
---|
109 | "OG_ERR_FORMAT": 1, |
---|
110 | "OG_ERR_NOTFOUND": 2, |
---|
111 | "OG_ERR_PARTITION": 3, |
---|
112 | "OG_ERR_LOCKED": 4, |
---|
113 | "OG_ERR_IMAGE": 5, |
---|
114 | "OG_ERR_NOTOS": 6, |
---|
115 | "OG_ERR_NOTEXEC": 7, |
---|
116 | "OG_ERR_NOTWRITE": 14, |
---|
117 | "OG_ERR_NOTCACHE": 15, |
---|
118 | "OG_ERR_CACHESIZE": 16, |
---|
119 | "OG_ERR_REDUCEFS": 17, |
---|
120 | "OG_ERR_EXTENDFS": 18, |
---|
121 | "OG_ERR_OUTOFLIMIT": 19, |
---|
122 | "OG_ERR_FILESYS": 20, |
---|
123 | "OG_ERR_CACHE": 21, |
---|
124 | "OG_ERR_NOGPT": 22, |
---|
125 | "OG_ERR_REPO": 23, |
---|
126 | "OG_ERR_NOMSDOS": 24, |
---|
127 | "OG_ERR_IMGSIZEPARTITION": 30, |
---|
128 | "OG_ERR_UPDATECACHE": 31, |
---|
129 | "OG_ERR_DONTFORMAT": 32, |
---|
130 | "OG_ERR_IMAGEFILE": 33, |
---|
131 | "OG_ERR_GENERIC": 40, |
---|
132 | "OG_ERR_UCASTSYNTAXT": 50, |
---|
133 | "OG_ERR_UCASTSENDPARTITION": 51, |
---|
134 | "OG_ERR_UCASTSENDFILE": 52, |
---|
135 | "OG_ERR_UCASTRECEIVERPARTITION": 53, |
---|
136 | "OG_ERR_UCASTRECEIVERFILE": 54, |
---|
137 | "OG_ERR_MCASTSYNTAXT": 55, |
---|
138 | "OG_ERR_MCASTSENDFILE": 56, |
---|
139 | "OG_ERR_MCASTRECEIVERFILE": 57, |
---|
140 | "OG_ERR_MCASTSENDPARTITION": 58, |
---|
141 | "OG_ERR_MCASTRECEIVERPARTITION": 59, |
---|
142 | "OG_ERR_PROTOCOLJOINMASTER": 60, |
---|
143 | "OG_ERR_DONTMOUNT_IMAGE": 70, |
---|
144 | "OG_ERR_DONTSYNC_IMAGE": 71, |
---|
145 | "OG_ERR_DONTUNMOUNT_IMAGE": 72, |
---|
146 | "OG_ERR_NOTDIFFERENT": 73, |
---|
147 | "OG_ERR_SYNCHRONIZING": 74, |
---|
148 | "OG_ERR_NOTUEFI": 80, |
---|
149 | "OG_ERR_NOTBIOS": 81 |
---|
150 | } |
---|
151 | |
---|
152 | for key, value in error_codes.items(): |
---|
153 | os.environ[key] = str(value) |
---|