147 lines
7.5 KiB
Python
147 lines
7.5 KiB
Python
#!/usr/bin/python3
|
|
|
|
import sys
|
|
import os
|
|
import os.path
|
|
import locale
|
|
import importlib.util
|
|
|
|
def load_lang (name):
|
|
global lang
|
|
if name in sys.modules:
|
|
return True
|
|
elif (spec := importlib.util.find_spec (name)) is not None:
|
|
lang = importlib.util.module_from_spec (spec)
|
|
sys.modules[name] = lang
|
|
spec.loader.exec_module (lang)
|
|
return True
|
|
else:
|
|
#print(f"can't find the {name!r} module")
|
|
return False
|
|
|
|
l = locale.getlocale()[0]
|
|
if not l: print (f"couldn't set locale")
|
|
if not l or not load_lang (f'lang_{l}'):
|
|
if not load_lang ('lang_en_GB'):
|
|
raise ModuleNotFoundError (f"can't find the default language module", name=name)
|
|
|
|
TZ='Europe/Madrid'
|
|
|
|
|
|
## engine.cfg
|
|
OGLOGSESSION='/tmp/session.log'
|
|
OGLOGCOMMAND='/tmp/command.log'
|
|
#OGWINCHKDISK=True #Hacer chkdisk tras la clonacion
|
|
ACTIONCACHEFULL='NONE' #Que hacer cuando la cache no tenga espacio libre. [ NONE | FORMAT ] ]
|
|
RESTOREPROTOCOLNOTCACHE=None #Que protocolo de restauracion usar en el caso de que no exista cache o no exista espacio sufiente. [NONE | UNICAST | MULTICAST].NONE retorna error
|
|
IMGPROG='partclone'
|
|
IMGCOMP='lzop'
|
|
IMGEXT='img'
|
|
IMGREDUCE=True
|
|
#OGWINREDUCE=True #Al enviar particion reducir el sistema de archivos previamente.
|
|
MCASTERRORSESSION=120 #timeout (segundos) para abortar la sesion de multicast si no contacta con el servidor de multicast. Valor asignado a 0, utiliza los valores por defecto de udp-cast
|
|
MCASTWAIT=30 # timeout (segundos) para abortar la la transferencia si se interrumpe. Valor asignado a 0, utiliza los valores por defecto de udp-cast
|
|
#CREATESPEED=100000*4 # Factor para calcular el time-out al crear la imagen. 100000k -> 4s
|
|
#FACTORSYNC=120 # Factor de compresion para las imagenes (windos en ext4).
|
|
#BACKUP=False # Realizar copia de seguridad antes de crear la imagen.
|
|
#IMGFS='EXT4' # Sistema de archivo de la imagenes sincronizadas. EXT4 o BTRFS
|
|
#OGSLEEP=20 # Tiempo de sleep antes de realizar el reboot
|
|
NODEBUGFUNCTIONS=['ogCreateImageSyntax', 'ogGetHivePath', 'ogGetOsType', 'ogRestoreImageSyntax', 'ogUnmountAll', 'ogUnmountCache'] # Funciones que no deben mostrar salida de avisos si son llamadas por otras funciones.
|
|
#DEFAULTSPEED=''
|
|
## /engine.cfg
|
|
|
|
|
|
## loadenviron.sh
|
|
OPENGNSYS = '/opt/opengnsys'
|
|
OGBIN = os.path.join (OPENGNSYS, 'bin')
|
|
OGETC = os.path.join (OPENGNSYS, 'etc')
|
|
OGLIB = os.path.join (OPENGNSYS, 'lib')
|
|
OGAPI = os.path.join (OGLIB, 'engine', 'bin')
|
|
OGPYFUNCS = os.path.join (OPENGNSYS, 'functions')
|
|
OGSCRIPTS = os.path.join (OPENGNSYS, 'scripts')
|
|
OGIMG = os.path.join (OPENGNSYS, 'images')
|
|
OGCAC = os.path.join (OPENGNSYS, 'cache')
|
|
OGLOGFILE = '/var/log/clone-engine.log'
|
|
OGJSONLOGFILE = '/var/log/clone-engine.json.log'
|
|
DEBUG = 'yes'
|
|
_path = os.environ['PATH'] + ':/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin:/opt/oglive/rootfs/opt/drbl/sbin'
|
|
os.environ['PATH'] = ':'.join ([OGSCRIPTS, _path, OGAPI, OGBIN])
|
|
|
|
if os.path.exists ('/tmp/initrd.cfg'):
|
|
with open ('/tmp/initrd.cfg', 'r') as fd:
|
|
initrd_cfg = fd.read()
|
|
for l in initrd_cfg.splitlines():
|
|
if not l.startswith ('DEVICECFG='): continue ## eg. "DEVICECFG=/run/net-enp0s3.conf"
|
|
device_cfg = l.split ('=')[1]
|
|
if os.path.exists (device_cfg):
|
|
with open (device_cfg, 'r') as fd:
|
|
contents = fd.read()
|
|
exec (contents) ## !!!
|
|
## example contents:
|
|
#DEVICE='enp0s3'
|
|
#PROTO='none'
|
|
#IPV4ADDR='192.168.2.11'
|
|
#IPV4BROADCAST='192.168.2.255'
|
|
#IPV4NETMASK='255.255.255.0'
|
|
#IPV4GATEWAY='192.168.2.1'
|
|
#IPV4DNS0='0.0.0.0'
|
|
#IPV4DNS1='0.0.0.0'
|
|
#HOSTNAME='pc1'
|
|
#DNSDOMAIN=''
|
|
#NISDOMAIN=''
|
|
#ROOTSERVER='10.0.2.15'
|
|
#ROOTPATH=''
|
|
#filename=''
|
|
#UPTIME='161'
|
|
#DHCPLEASETIME='0'
|
|
#DOMAINSEARCH=''
|
|
break
|
|
## /loadenviron.sh
|
|
|
|
# Declaración de códigos de error.
|
|
OG_ERR_FORMAT=1 # Formato de ejecución incorrecto.
|
|
OG_ERR_NOTFOUND=2 # Fichero o dispositivo no encontrado.
|
|
OG_ERR_PARTITION=3 # Error en partición de disco.
|
|
OG_ERR_LOCKED=4 # Partición o fichero bloqueado.
|
|
OG_ERR_IMAGE=5 # Error al crear o restaurar una imagen.
|
|
OG_ERR_NOTOS=6 # Sin sistema operativo.
|
|
OG_ERR_NOTEXEC=7 # Programa o función no ejecutable.
|
|
# Códigos 8-13 reservados por ogAdmClient.h
|
|
OG_ERR_NOTWRITE=14 # No hay acceso de escritura
|
|
OG_ERR_NOTCACHE=15 # No hay particion cache en cliente
|
|
OG_ERR_CACHESIZE=16 # No hay espacio en la cache para almacenar fichero-imagen
|
|
OG_ERR_REDUCEFS=17 # Error al reducir sistema archivos
|
|
OG_ERR_EXTENDFS=18 # Error al expandir el sistema de archivos
|
|
OG_ERR_OUTOFLIMIT=19 # Valor fuera de rango o no válido.
|
|
OG_ERR_FILESYS=20 # Sistema de archivos desconocido o no se puede montar
|
|
OG_ERR_CACHE=21 # Error en partición de caché local
|
|
OG_ERR_NOGPT=22 # El disco indicado no contiene una particion GPT
|
|
OG_ERR_REPO=23 # Error al montar el repositorio de imagenes
|
|
OG_ERR_NOMSDOS=24 # El disco indicado no contienen una particion MSDOS
|
|
|
|
OG_ERR_IMGSIZEPARTITION=30 # Error al restaurar partición más pequeña que la imagen
|
|
OG_ERR_UPDATECACHE=31 # Error al realizar el comando updateCache
|
|
OG_ERR_DONTFORMAT=32 # Error al formatear
|
|
OG_ERR_IMAGEFILE=33 # Archivo de imagen corrupto o de otra versión de $IMGPROG
|
|
OG_ERR_GENERIC=40 # Error imprevisto no definido
|
|
OG_ERR_UCASTSYNTAXT=50 # Error en la generación de sintaxis de transferenica UNICAST
|
|
OG_ERR_UCASTSENDPARTITION=51 # Error en envío UNICAST de partición
|
|
OG_ERR_UCASTSENDFILE=52 # Error en envío UNICAST de un fichero
|
|
OG_ERR_UCASTRECEIVERPARTITION=53 # Error en la recepcion UNICAST de una particion
|
|
OG_ERR_UCASTRECEIVERFILE=54 # Error en la recepcion UNICAST de un fichero
|
|
OG_ERR_MCASTSYNTAXT=55 # Error en la generacion de sintaxis de transferenica Multicast.
|
|
OG_ERR_MCASTSENDFILE=56 # Error en envio MULTICAST de un fichero
|
|
OG_ERR_MCASTRECEIVERFILE=57 # Error en la recepcion MULTICAST de un fichero
|
|
OG_ERR_MCASTSENDPARTITION=58 # Error en envio MULTICAST de una particion
|
|
OG_ERR_MCASTRECEIVERPARTITION=59 # Error en la recepcion MULTICAST de una particion
|
|
OG_ERR_PROTOCOLJOINMASTER=60 # Error en la conexion de una sesion UNICAST|MULTICAST con el MASTER
|
|
|
|
OG_ERR_DONTMOUNT_IMAGE=70 # Error al montar una imagen sincronizada.
|
|
OG_ERR_DONTSYNC_IMAGE=71 # Imagen no sincronizable (es monolitica)
|
|
OG_ERR_DONTUNMOUNT_IMAGE=72 # Error al desmontar la imagen
|
|
OG_ERR_NOTDIFFERENT=73 # No se detectan diferencias entre la imagen basica y la particion.
|
|
OG_ERR_SYNCHRONIZING=74 # Error al sincronizar, puede afectar la creacion/restauracion de la imagen
|
|
|
|
OG_ERR_NOTUEFI=80 # La interfaz UEFI no está activa
|
|
OG_ERR_NOTBIOS=81 # La interfaz BIOS legacy no está activa
|