1 | import os |
---|
2 | import subprocess |
---|
3 | import sys |
---|
4 | |
---|
5 | #!/usr/bin/env python3 |
---|
6 | |
---|
7 | """ |
---|
8 | installOfflineMode |
---|
9 | Prepara el equipo cliente para el modo offline. |
---|
10 | |
---|
11 | @exception OG_ERR_NOTFOUND Fichero o dispositivo no encontrado. |
---|
12 | @exception OG_ERR_NOTCACHE No existe cache. |
---|
13 | @author Irina Gomez. ETSII. Universidad de Sevilla |
---|
14 | @date 2013/12/5 |
---|
15 | """ |
---|
16 | |
---|
17 | |
---|
18 | PROG = os.path.basename(__file__) |
---|
19 | |
---|
20 | if len(sys.argv) > 1 and sys.argv[1] == "help": |
---|
21 | og_help() |
---|
22 | |
---|
23 | og_echo("log", "session $MSG_HELP_installOfflineMode") |
---|
24 | |
---|
25 | # Cargamos las variables de entorno. |
---|
26 | OGENGINECONFIGURATE = os.getenv('OGENGINECONFIGURATE') |
---|
27 | if not OGENGINECONFIGURATE: |
---|
28 | exec(open('/opt/opengnsys/etc/engine.cfg').read()) |
---|
29 | |
---|
30 | DIRTFTP = "/opt/oglive/tftpboot" |
---|
31 | DIROGCLIENT = os.path.join(DIRTFTP, "ogclient") |
---|
32 | |
---|
33 | # Comprobamos que el DIROGCLIENT esta montado desde repo |
---|
34 | repo_ip = og_get_repo_ip() |
---|
35 | result = subprocess.run(['df'], capture_output=True, text=True) |
---|
36 | if f"{repo_ip} {DIRTFTP}" not in result.stdout: |
---|
37 | og_raise_error("OG_ERR_NOTFOUND", "REPO OGclient") |
---|
38 | |
---|
39 | # Copiamos el kernel y el initrd. |
---|
40 | og_echo("log", "session [10] updateBootCache") |
---|
41 | if not update_boot_cache(): |
---|
42 | og_raise_error("OG_ERR_NOTCACHE", "") |
---|
43 | |
---|
44 | # Creamos los dir necesarios. |
---|
45 | OGCAC = "/path/to/ogcac" # Placeholder for OGCAC path |
---|
46 | og_echo("log", f"session [40] mkdir -p {OGCAC}/{{ogclient, menus, log}}.") |
---|
47 | os.makedirs(os.path.join(OGCAC, "menus/images/iconos"), exist_ok=True) |
---|
48 | os.makedirs(os.path.join(OGCAC, "ogclient"), exist_ok=True) |
---|
49 | os.makedirs(os.path.join(OGCAC, "log"), exist_ok=True) |
---|
50 | os.makedirs(os.path.join(OGCAC, "opt/opengnsys/images"), exist_ok=True) |
---|
51 | |
---|
52 | # Comparamos el cliente en el server y en cache |
---|
53 | og_echo("log", f"session [60] cp {DIROGCLIENT}/ogclient.sqfs {OGCAC}/ogclient/") |
---|
54 | try: |
---|
55 | with open(os.path.join(DIROGCLIENT, "ogclient.sqfs.sum"), 'r') as f: |
---|
56 | SERVEROGCLIENT = f.read().strip() |
---|
57 | except FileNotFoundError: |
---|
58 | SERVEROGCLIENT = None |
---|
59 | |
---|
60 | try: |
---|
61 | with open(os.path.join(OGCAC, "ogclient/ogclient.sqfs.sum"), 'r') as f: |
---|
62 | CACHEOGCLIENT = f.read().strip() |
---|
63 | except FileNotFoundError: |
---|
64 | CACHEOGCLIENT = None |
---|
65 | |
---|
66 | if CACHEOGCLIENT != SERVEROGCLIENT: |
---|
67 | subprocess.run(['cp', os.path.join(DIROGCLIENT, "ogclient.sqfs"), os.path.join(OGCAC, "ogclient/")]) |
---|
68 | subprocess.run(['cp', os.path.join(DIROGCLIENT, "ogclient.sqfs.sum"), os.path.join(OGCAC, "ogclient/")]) |
---|
69 | |
---|
70 | # Si se ha generado el menu de inicio lo copiamos a cache. |
---|
71 | IPCLIENT = og_get_ip_address() |
---|
72 | MENU = os.path.join("/path/to/oglog", f"{IPCLIENT}.info.html") # Placeholder for OGLOG path |
---|
73 | ICONO = "images/iconos/logoopengnsys.png" |
---|
74 | if not os.path.isfile(MENU): |
---|
75 | generate_menu_default() |
---|
76 | |
---|
77 | og_echo("log", f"session [90] cp {MENU} {OGCAC}/menus/{IPCLIENT}.html") |
---|
78 | subprocess.run(['cp', MENU, os.path.join(OGCAC, f"menus/{IPCLIENT}.html")]) |
---|
79 | subprocess.run(['sed', '-i', 's/"../images"/"images"/g', os.path.join(OGCAC, f"menus/{IPCLIENT}.html")]) |
---|
80 | subprocess.run(['wget', '--no-check-certificate', f"https://{og_get_repo_ip()}/opengnsys/{ICONO}", '-O', os.path.join(OGCAC, f"menus/{ICONO}")]) |
---|