agentcfg-imgname #37

Merged
nserrano merged 4 commits from agentcfg-imgname into main 2025-05-09 12:17:28 +02:00
4 changed files with 26 additions and 15 deletions

View File

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.8.4] - 2025-05-09
### Added
- When restoring an image, include the image name in the ogagent configuration file
## [0.8.3] - 2025-05-08
### Fixed

View File

@ -200,7 +200,7 @@ def ogAddCmd (disk, par, cmdfile, cmd):
#@exception OG_ERR_NOTFOUND Fichero o dispositivo no encontrado.
#@exception OG_ERR_LOCKED Sistema de archivos bloqueado.
#*/ ##
def ogConfigureOgagent (disk, par):
def ogConfigureOgagent (disk, par, imgname=''):
mntdir = FileSystemLib.ogMount (disk, par)
if not mntdir:
return
@ -217,19 +217,22 @@ def ogConfigureOgagent (disk, par):
ogcore_ip = NetLib.ogGetServerIp()
ogcore_port = NetLib.ogGetServerPort()
cfgfile_patched = cfgfile + '.patched'
in_opengnsys_section = False
cur_section = ''
with open (cfgfile, 'r') as fdin:
with open (cfgfile_patched, 'w') as fdout:
while True:
lineout = linein = fdin.readline()
if not linein: break
if in_opengnsys_section:
if 'remote' == linein[0:6]:
lineout = f'remote={ogcore_scheme}://{ogcore_ip}:{ogcore_port}/opengnsys/rest/\n'
if '[' == linein[0:1]:
in_opengnsys_section = False
if '[opengnsys]' == linein[0:11]:
in_opengnsys_section = True
m = re.match (r'\[(.*)] *$', linein)
if m:
cur_section = m.groups()[0]
else:
if 'opengnsys' == cur_section:
if re.match (r'remote *=', linein):
lineout = f'remote={ogcore_scheme}://{ogcore_ip}:{ogcore_port}/opengnsys/rest/\n'
elif re.match ('imgname *=', linein):
lineout = f'imgname={imgname}\n'
fdout.write (lineout)
os.rename (cfgfile_patched, cfgfile)

View File

@ -5,6 +5,7 @@
#@brief Script para realizar la configuracion del sistema operativo restaurado.
#@param 1 disco
#@param 2 particion
#@param 2 nombre imagen
#@return
#@TODO comprobar que el tipo de particion corresponde con el sistema de archivos.
#@exception OG_ERR_FORMAT # 1 formato incorrecto.
@ -30,8 +31,9 @@ import FileLib
## [ -f $DEVICECFG ] && source $DEVICECFG
## pero luego no utiliza ninguna de las variables definidas en el archivo...
disk = sys.argv[1]
par = sys.argv[2]
disk = sys.argv[1]
par = sys.argv[2]
imgname = sys.argv[3]
# Si el sistema de archivos no esta extendido, ampliarlo al tamaño de su partición.
partsize = DiskLib.ogGetPartitionSize (disk, par)
@ -71,7 +73,7 @@ if 'Windows' == ostype:
BootLib.ogFixBootSector (disk, par) # Configurar el boot sector de la partición Windows.
BootLib.ogWindowsBootParameters (disk, par) # Configurar el gestor de arranque de Windows XP/Vista/7.
BootLib.ogWindowsRegisterPartition (disk, par, 'C', disk, par) # Registrar en Windows que la partición indicada es su nueva unidad C:\
PostConfLib.ogConfigureOgagent (disk, par) # Configurar nuevo agente OGAgent.
PostConfLib.ogConfigureOgagent (disk, par, imgname) # Configurar nuevo agente OGAgent.
path1 = FileLib.ogGetPath (file=f'{mntdir}/windows/ogAdmWinClient.exe')
path2 = FileLib.ogGetPath (file=f'{mntdir}/winnt/ogAdmWinClient.exe')
if path1 or path2: # Eliminar el antiguo cliente de Windows.
@ -88,7 +90,7 @@ elif 'Linux' == ostype:
find_out = subprocess.run (['find', f'{mntdir}/usr/sbin', f'{mntdir}/sbin', f'{mntdir}/usr/local/sbin', '-name', 'ogAdmLnxClient', '-print'], capture_output=True, text=True).stdout
if find_out:
PostConfLib.ogUninstallLinuxClient (disk, par) # Eliminar el antiguo cliente de Linux.
PostConfLib.ogConfigureOgagent (disk, par) # Configurar nuevo agente OGAgent.
PostConfLib.ogConfigureOgagent (disk, par, imgname) # Configurar nuevo agente OGAgent.
## Modificar el nombre del equipo
print (f'Asignar nombre Linux "{host}".')
etc = FileLib.ogGetPath (src=f'{disk} {par}', file='/etc')
@ -154,6 +156,6 @@ elif 'MacOS' == ostype:
fd.write ('\trm -f /osxpostconf # Borrar fichero indicador de psotconfiguración\n')
fd.write ('fi\n')
os.chmod (f'{mntdir}/var/root/postconfd.sh', 0o700) # Dar permiso de ejecución.
PostConfLib.ogConfigureOgagent (disk, par) # Configurar nuevo agente OGAgent de sistema operativo.
PostConfLib.ogConfigureOgagent (disk, par, imgname) # Configurar nuevo agente OGAgent de sistema operativo.
sys.exit (0)

View File

@ -168,7 +168,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.py', disk, par])
subprocess.run (['configureOs.py', disk, par, imgname])
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')