source: client/shared/scripts/installOfflineMode.py @ 937f1b5

ogClonningEngine
Last change on this file since 937f1b5 was 937f1b5, checked in by Antonio Emmanuel Guerrero Silva <aguerrero@…>, 7 months ago

refs #693 Code migration from the scripts directory

  • Property mode set to 100644
File size: 2.9 KB
Line 
1import os
2import subprocess
3import sys
4
5#!/usr/bin/env python3
6
7"""
8installOfflineMode
9Prepara 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
18PROG = os.path.basename(__file__)
19
20if len(sys.argv) > 1 and sys.argv[1] == "help":
21    og_help()
22
23og_echo("log", "session $MSG_HELP_installOfflineMode")
24
25# Cargamos las variables de entorno.
26OGENGINECONFIGURATE = os.getenv('OGENGINECONFIGURATE')
27if not OGENGINECONFIGURATE:
28    exec(open('/opt/opengnsys/etc/engine.cfg').read())
29
30DIRTFTP = "/opt/oglive/tftpboot"
31DIROGCLIENT = os.path.join(DIRTFTP, "ogclient")
32
33# Comprobamos que el DIROGCLIENT esta montado desde repo
34repo_ip = og_get_repo_ip()
35result = subprocess.run(['df'], capture_output=True, text=True)
36if 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.
40og_echo("log", "session [10] updateBootCache")
41if not update_boot_cache():
42    og_raise_error("OG_ERR_NOTCACHE", "")
43
44# Creamos los dir necesarios.
45OGCAC = "/path/to/ogcac"  # Placeholder for OGCAC path
46og_echo("log", f"session [40] mkdir -p {OGCAC}/{{ogclient, menus, log}}.")
47os.makedirs(os.path.join(OGCAC, "menus/images/iconos"), exist_ok=True)
48os.makedirs(os.path.join(OGCAC, "ogclient"), exist_ok=True)
49os.makedirs(os.path.join(OGCAC, "log"), exist_ok=True)
50os.makedirs(os.path.join(OGCAC, "opt/opengnsys/images"), exist_ok=True)
51
52# Comparamos el cliente en el server y en cache
53og_echo("log", f"session [60] cp {DIROGCLIENT}/ogclient.sqfs {OGCAC}/ogclient/")
54try:
55    with open(os.path.join(DIROGCLIENT, "ogclient.sqfs.sum"), 'r') as f:
56        SERVEROGCLIENT = f.read().strip()
57except FileNotFoundError:
58    SERVEROGCLIENT = None
59
60try:
61    with open(os.path.join(OGCAC, "ogclient/ogclient.sqfs.sum"), 'r') as f:
62        CACHEOGCLIENT = f.read().strip()
63except FileNotFoundError:
64    CACHEOGCLIENT = None
65
66if 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.
71IPCLIENT = og_get_ip_address()
72MENU = os.path.join("/path/to/oglog", f"{IPCLIENT}.info.html")  # Placeholder for OGLOG path
73ICONO = "images/iconos/logoopengnsys.png"
74if not os.path.isfile(MENU):
75    generate_menu_default()
76
77og_echo("log", f"session [90] cp {MENU} {OGCAC}/menus/{IPCLIENT}.html")
78subprocess.run(['cp', MENU, os.path.join(OGCAC, f"menus/{IPCLIENT}.html")])
79subprocess.run(['sed', '-i', 's/"../images"/"images"/g', os.path.join(OGCAC, f"menus/{IPCLIENT}.html")])
80subprocess.run(['wget', '--no-check-certificate', f"https://{og_get_repo_ip()}/opengnsys/{ICONO}", '-O', os.path.join(OGCAC, f"menus/{ICONO}")])
Note: See TracBrowser for help on using the repository browser.