diff --git a/client/lib/engine/bin/BootLib.py b/client/lib/engine/bin/BootLib.py index c298994..b963842 100644 --- a/client/lib/engine/bin/BootLib.py +++ b/client/lib/engine/bin/BootLib.py @@ -456,7 +456,7 @@ def ogGrubInstallMbr (disk, par, checkos='FALSE', kernelparam=''): os.makedirs (f'{secondstage}{prefixsecondstage}/boot/grub/') #Preparar configuración segunda etapa: crear ubicacion subprocess.run (['sed', '-i', 's/^set -e/#set -e/', '/etc/grub.d/00_header']) #Preparar configuración segunda etapa: crear cabecera del fichero (ingnorar errores) # (ogLive 5.0) Si 'pkgdatadir' está vacía ponemos valor de otros ogLive - subprocess.run (['sed', '-i', '/grub-mkconfig_lib/i\pkgdatadir=${pkgdatadir:-"${datarootdir}/grub"}', '/etc/grub.d/00_header']) + subprocess.run (['sed', '-i', r'/grub-mkconfig_lib/i\pkgdatadir=${pkgdatadir:-"${datarootdir}/grub"}', '/etc/grub.d/00_header']) out = subprocess.run (['/etc/grub.d/00_header'], capture_output=True, text=True).stdout with open (f'{secondstage}{prefixsecondstage}/boot/grub/grub.cfg', 'w') as fd: fd.write (out + '\n') @@ -563,7 +563,7 @@ def ogGrubInstallPartition (disk, par, checkos='FALSE', kernelparam=''): os.makedirs (f'{secondstage}{prefixsecondstage}/boot/grub/') #Preparar configuración segunda etapa: crear ubicacion subprocess.run (['sed', '-i', 's/^set -e/#set -e/', '/etc/grub.d/00_header']) #Preparar configuración segunda etapa: crear cabecera del fichero (ingnorar errores) # (ogLive 5.0) Si 'pkgdatadir' está vacía ponemos valor de otros ogLive - subprocess.run (['sed', '-i', '/grub-mkconfig_lib/i\pkgdatadir=${pkgdatadir:-"${datarootdir}/grub"}', '/etc/grub.d/00_header']) + subprocess.run (['sed', '-i', r'/grub-mkconfig_lib/i\pkgdatadir=${pkgdatadir:-"${datarootdir}/grub"}', '/etc/grub.d/00_header']) out = subprocess.run (['/etc/grub.d/00_header'], capture_output=True, text=True).stdout with open (f'{secondstage}{prefixsecondstage}/boot/grub/grub.cfg', 'w') as fd: fd.write (out + '\n') diff --git a/client/lib/engine/bin/PostConfLib.py b/client/lib/engine/bin/PostConfLib.py index a6e7f58..4871c6d 100644 --- a/client/lib/engine/bin/PostConfLib.py +++ b/client/lib/engine/bin/PostConfLib.py @@ -67,8 +67,8 @@ def ogInstallFirstBoot (disk, par, cmdfile): # Creamos el archivo cmd y creamos un par de comandos para que una vez acabe la # postconfiguracion resetee el mini setup, sino lo haria en cada arranque. with open (full_cmdfile, 'w') as fd: - fd.write ('REG ADD HKLM\System\Setup /v SystemSetupInProgress /t REG_DWORD /d 0 /f\n') - fd.write ('REG ADD HKLM\System\Setup /v CmdLine /t REG_SZ /d "" /f\n') + fd.write (r'REG ADD HKLM\System\Setup /v SystemSetupInProgress /t REG_DWORD /d 0 /f\n') + fd.write (r'REG ADD HKLM\System\Setup /v CmdLine /t REG_SZ /d "" /f\n') # Crear los valores de registro necesarios para que se haga la ejecución del .cmd al aranque. RegistryLib.ogSetRegistryValue (mntdir, 'SYSTEM', r'\Setup\SystemSetupInProgress', 1) diff --git a/client/shared/scripts/configureOs.py b/client/shared/scripts/configureOs.py index 051c6c6..13248df 100755 --- a/client/shared/scripts/configureOs.py +++ b/client/shared/scripts/configureOs.py @@ -18,6 +18,7 @@ import subprocess import ogGlobals import DiskLib import FileSystemLib +import NetLib import InventoryLib import BootLib import UEFILib @@ -28,8 +29,8 @@ import FileLib ## [ -f $DEVICECFG ] && source $DEVICECFG ## pero luego no utiliza ninguna de las variables definidas en el archivo... -disk = sys.argv[0] -par = sys.argv[1] +disk = sys.argv[1] +par = sys.argv[2] # Si el sistema de archivos no esta extendido, ampliarlo al tamaño de su partición. partsize = DiskLib.ogGetPartitionSize (disk, par) diff --git a/client/shared/scripts/deployImage.py b/client/shared/scripts/deployImage.py index f18be81..e5a2ec2 100755 --- a/client/shared/scripts/deployImage.py +++ b/client/shared/scripts/deployImage.py @@ -8,6 +8,7 @@ import shutil import ogGlobals import SystemLib +import FileSystemLib import DiskLib import NetLib import StringLib @@ -19,7 +20,13 @@ import ImageLib # Si Repositorio es local (CACHE) realiza un restoreImage CACHE # El deploy, si detecta que el cliente no tiene una CACHE o no tiene espacio suficiente consulta el engine.cfg RESTOREPROTOCOLNOCACHE +prog = os.path.basename (sys.argv[0]) + def main (repo, imgname, disk, par, proto='UNICAST', protoopt=''): + if repo: repo = repo.upper() + else: repo = 'REPO' + proto = proto.upper() + protoopt = protoopt.upper() time1 = time.time() # Clear temporary file used as log track by httpdlog @@ -31,7 +38,7 @@ def main (repo, imgname, disk, par, proto='UNICAST', protoopt=''): fd.write ('') # Registro de inicio de ejecución - SystemLib.ogEcho (['log', 'session'], None, f'[1] {ogGlobals.lang.MSG_SCRIPTS_START} {__file__} {" ".join(sys.argv)}') + SystemLib.ogEcho (['log', 'session'], None, f'[1] {ogGlobals.lang.MSG_SCRIPTS_START} {prog} {" ".join(sys.argv)}') # Si el origen(pariticion) esta bloqueada salir. if FileSystemLib.ogIsLocked (disk, par): @@ -42,17 +49,21 @@ def main (repo, imgname, disk, par, proto='UNICAST', protoopt=''): FileSystemLib.ogUnmount (disk, par) # Valor por defecto para el repositorio. - if repo == NetLib.ogGetIpAddress() or 'CACHE' == repo: - MODE = 'CACHE' + mode = None + if NetLib.ogGetIpAddress() == repo or 'CACHE' == repo: + mode = 'CACHE' else: if StringLib.ogCheckIpAddress (repo) or 'REPO' == repo: if not NetLib.ogChangeRepo (repo): SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, repo) sys.exit (1) - MODE = 'REPO' + mode = 'REPO' #Informacioin previa de la imagen - imgpath = FileLib.ogGetPath (MODE, f'{imgname}.img') + if mode: + imgpath = FileLib.ogGetPath (src=mode, file=f'{imgname}.img') + else: + imgpath = FileLib.ogGetPath (file=f'{imgname}.img') imgos = ImageLib.ogGetImageInfo (imgpath) #if imgos == 1: sys.exit(SystemLib.ogRaiseError("session", OG_ERR_NOTFOUND, f"{repo} {imgname}")) #elif imgos == 5: sys.exit(SystemLib.ogRaiseError("session", OG_ERR_IMAGEFILE, f"{repo} {imgname}")) @@ -65,9 +76,9 @@ def main (repo, imgname, disk, par, proto='UNICAST', protoopt=''): SystemLib.ogEcho (['log', 'session'], None, f'[1] REPO={repo} IMG-FILE={imgname}.img SIZE={imgsize} (KB) METADATA={imgos}') # Procesar repositorio. - if 'CACHE' == MODE: + if 'CACHE' == mode: nextoperation = 'CACHE' - elif 'REPO' == MODE: + elif 'REPO' == mode: if 'MULTICAST-DIRECT' == proto: nextoperation = 'MULTICAST' elif 'UNICAST-DIRECT' == proto: @@ -78,7 +89,7 @@ def main (repo, imgname, disk, par, proto='UNICAST', protoopt=''): proto = proto.split ('-')[0] SystemLib.ogEcho (['log', 'session'], None, f'[2] updateCache {repo} "/{imgname}.img" {proto} {protoopt}') time2 = time.time() - retval = subprocess.run (['updateCache', repo, f'/{imgname}.img', proto, protoopt]).returncode + retval = subprocess.run (['updateCache.py', repo, f'/{imgname}.img', proto, protoopt]).returncode time2 = time.time() - time2 SystemLib.ogEcho (['log', 'session'], None, f' [ ] {ogGlobals.lang.MSG_SCRIPTS_TIME_PARTIAL} updateCache {int (time2/60)}m {int (time2%60)}s') if 0 == retval: @@ -132,7 +143,7 @@ def main (repo, imgname, disk, par, proto='UNICAST', protoopt=''): retval = subprocess.run (['restoreImageCustom'] + params).returncode else: SystemLib.ogEcho (['log', 'session'], None, f'[55] {ogGlobals.lang.MSG_HELP_ogRestoreImage}: restoreImage {params}') - retval = subprocess.run (['restoreImage'] + params).returncode + retval = subprocess.run (['restoreImage.py'] + params).returncode # Mostrar resultados. resumerestoreimage = subprocess.run (['grep', '--max-count', '1', 'Total Time:', ogGlobals.OGLOGCOMMAND], capture_output=True, text=True).stdout @@ -153,7 +164,7 @@ def main (repo, imgname, disk, par, proto='UNICAST', protoopt=''): subprocess.run (['configureOsCustom', disk, par, repo, imgname]) else: SystemLib.ogEcho (['log', 'session'], None, f'[90] {ogGlobals.lang.MSG_SCRIPTS_OS_CONFIGURE}') - subprocess.run (['configureOs', disk, par]) + subprocess.run (['configureOs.py', disk, par]) time_total = time.time() - time1 SystemLib.ogEcho (['log', 'session'], None, f'[100] {ogGlobals.lang.MSG_SCRIPTS_TIME_TOTAL} {int (time_total/60)}m {int (time_total%60)}s') @@ -165,8 +176,7 @@ def main (repo, imgname, disk, par, proto='UNICAST', protoopt=''): sys.exit (retval) if __name__ == '__main__': - if len (sys.argv) < 4: - SystemLib.ogRaiseError ('session', ogGlobals.OG_ERR_FORMAT, f'{ogGlobals.lang.MSG_FORMAT}: {__file__} REPO imagen ndisco nparticion [ UNICAST-DIRECT|UNICAST|UNICAST-CACHE|MULTICAST-DIRECT|MULTICAST|MULTICAST-CACHE|TORRENT [opciones protocolo] ]') + if len (sys.argv) < 6: + SystemLib.ogRaiseError ('session', ogGlobals.OG_ERR_FORMAT, f'{ogGlobals.lang.MSG_FORMAT}: {prog} REPO imagen ndisco nparticion [ UNICAST-DIRECT|UNICAST|UNICAST-CACHE|MULTICAST-DIRECT|MULTICAST|MULTICAST-CACHE|TORRENT [opciones protocolo] ]') sys.exit (1) - sys.argv[0] = sys.argv[0].upper() if sys.argv[0] else 'REPO' - main (*sys.argv) + main (*sys.argv[1:]) diff --git a/client/shared/scripts/restoreImage.py b/client/shared/scripts/restoreImage.py index 39fc017..a5f0ff6 100644 --- a/client/shared/scripts/restoreImage.py +++ b/client/shared/scripts/restoreImage.py @@ -48,7 +48,7 @@ SystemLib.ogEcho (['log', 'session'], None, f'[1] {ogGlobals.lang.MSG_SCRIPTS_ST # Procesar parámetros de entrada print (f'argv ({sys.argv}) len ({len (sys.argv)})') -if len (sys.argv) < 6: +if len (sys.argv) < 5: SystemLib.ogRaiseError ('session', ogGlobals.OG_ERR_FORMAT, f'{ogGlobals.lang.MSG_FORMAT}: {prog} REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones protocolo]') sys.exit (1) diff --git a/client/shared/scripts/updateCache.py b/client/shared/scripts/updateCache.py index 655e861..773bef3 100644 --- a/client/shared/scripts/updateCache.py +++ b/client/shared/scripts/updateCache.py @@ -40,9 +40,9 @@ print (f'argv ({sys.argv}) len ({len (sys.argv)})') if len (sys.argv) < 3: SystemLib.ogRaiseError ('session', ogGlobals.OG_ERR_FORMAT, f'{ogGlobals.lang.MSG_FORMAT}: {prog} str_REPO _str_Relative_Path_OGIMG_with_/ PROTOCOLO OPCIONES_PROTOCOLO OPCIONES_UPDATECACHE') sys.exit (1) -#_, repositorio, path, protocolo, optprotocolo, cacheopts = sys.argv -_, repositorio, path, protocolo, optprotocolo = sys.argv -cacheopts = '' +_, repositorio, path, protocolo, *other = sys.argv +optprotocolo = other[0] if len (other) > 0 else '' +cacheopts = other[1] if len (other) > 1 else '' if 'RSYNC' == protocolo: raise Exception ('synchronised images are no longer supported')