firmware-type #9
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -1,5 +1,17 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- getConfiguration.py now collects the firmware type
|
||||||
|
- Configurar.py now creates partition tables of the right type (MSDOS/GPT) for each machine
|
||||||
|
|
||||||
## [0.1.1] - 2025-03-19
|
## [0.1.1] - 2025-03-19
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -9,6 +9,7 @@ import SystemLib
|
||||||
import CacheLib
|
import CacheLib
|
||||||
import FileSystemLib
|
import FileSystemLib
|
||||||
import DiskLib
|
import DiskLib
|
||||||
|
import InventoryLib
|
||||||
|
|
||||||
#Load engine configurator from engine.cfg file.
|
#Load engine configurator from engine.cfg file.
|
||||||
#Carga el configurador del engine desde el fichero engine.cfg
|
#Carga el configurador del engine desde el fichero engine.cfg
|
||||||
|
@ -61,22 +62,20 @@ sparam = tbprm[1] # Partitioning and formatting parameters
|
||||||
# Toma valores de disco y caché, separados por "*".
|
# Toma valores de disco y caché, separados por "*".
|
||||||
# Los valores están en las variables $dis: disco, $che: existe cache (1, 0), $tch: Tamaño de la cache.
|
# Los valores están en las variables $dis: disco, $che: existe cache (1, 0), $tch: Tamaño de la cache.
|
||||||
tbprm = pparam.split ('*')
|
tbprm = pparam.split ('*')
|
||||||
dis = ptt = tch = None
|
dis = tch = None
|
||||||
for item in tbprm:
|
for item in tbprm:
|
||||||
if '=' not in item: continue
|
if '=' not in item: continue
|
||||||
|
|
||||||
k, v = item.split ('=', 1)
|
k, v = item.split ('=', 1)
|
||||||
if k not in ['dis', 'tch', 'ptt']: ## 'ptt' added, unused 'che' removed
|
if k not in ['dis', 'tch']:
|
||||||
print (f'ignoring unknown disk parameter ({k})')
|
print (f'ignoring unknown disk parameter ({k})')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if 'dis' == k: dis = int (v)
|
if 'dis' == k: dis = int (v)
|
||||||
elif 'ptt' == k: ptt = v
|
|
||||||
elif 'tch' == k: tch = v
|
elif 'tch' == k: tch = v
|
||||||
|
|
||||||
# Error si no se define el parámetro de disco (dis).
|
# Error si no se define el parámetro de disco (dis).
|
||||||
if dis is None: sys.exit (ogGlobals.OG_ERR_FORMAT)
|
if dis is None: sys.exit (ogGlobals.OG_ERR_FORMAT)
|
||||||
if ptt is None: ptt = 'MSDOS'
|
|
||||||
if tch is None: tch = '0'
|
if tch is None: tch = '0'
|
||||||
|
|
||||||
# Toma valores de distribución de particiones, separados por "%".
|
# Toma valores de distribución de particiones, separados por "%".
|
||||||
|
@ -138,11 +137,10 @@ CacheLib.ogUnmountCache()
|
||||||
|
|
||||||
# Elimina la tabla de particiones
|
# Elimina la tabla de particiones
|
||||||
cur_ptt = DiskLib.ogGetPartitionTableType (dis)
|
cur_ptt = DiskLib.ogGetPartitionTableType (dis)
|
||||||
|
ptt = 'GPT' if InventoryLib.ogIsEfiActive() else 'MSDOS'
|
||||||
if not cur_ptt or ptt != cur_ptt:
|
if not cur_ptt or ptt != cur_ptt:
|
||||||
DiskLib.ogDeletePartitionTable (dis)
|
DiskLib.ogDeletePartitionTable (dis)
|
||||||
SystemLib.ogExecAndLog ('command', DiskLib.ogUpdatePartitionTable)
|
SystemLib.ogExecAndLog ('command', DiskLib.ogUpdatePartitionTable)
|
||||||
|
|
||||||
# Crea tabla de particiones MSDOS (NOTA: adaptar para tablas GPT).
|
|
||||||
DiskLib.ogCreatePartitionTable (dis, ptt)
|
DiskLib.ogCreatePartitionTable (dis, ptt)
|
||||||
|
|
||||||
# Inicia la cache.
|
# Inicia la cache.
|
||||||
|
|
|
@ -1,29 +1,20 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
#_______________________________________________________________________________________________________________________________
|
|
||||||
#
|
|
||||||
# Formato de salida:
|
|
||||||
# disk=Número de disco\tpar=Número de particion\tcod=Código de partición\tsfi=Sistema de ficheros\tsoi=Sistema instalado\ttam=Tamaño de la partición\n
|
|
||||||
#_______________________________________________________________________________________________________________________________
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from InventoryLib import ogGetSerialNumber, ogGetOsVersion
|
from InventoryLib import ogGetSerialNumber, ogGetOsVersion, ogIsEfiActive
|
||||||
from DiskLib import ogDiskToDev, ogGetPartitionsNumber, ogGetPartitionTableType, ogGetDiskSize, ogGetPartitionId, ogGetPartitionSize
|
from DiskLib import ogDiskToDev, ogGetPartitionsNumber, ogGetPartitionTableType, ogGetDiskSize, ogGetPartitionId, ogGetPartitionSize
|
||||||
from FileSystemLib import ogMount, ogGetMountPoint, ogGetFsType
|
from FileSystemLib import ogMount, ogGetMountPoint, ogGetFsType
|
||||||
|
|
||||||
# No registrar los errores.
|
|
||||||
#os.environ['DEBUG'] = 'no'
|
|
||||||
|
|
||||||
ser = ogGetSerialNumber()
|
ser = ogGetSerialNumber()
|
||||||
cfg = ''
|
fwt = 'UEFI' if ogIsEfiActive() else 'BIOS'
|
||||||
disks = len (ogDiskToDev())
|
print (f'ser={ser}\nfwt={fwt}')
|
||||||
|
|
||||||
for dsk in range (1, disks+1):
|
disks = len (ogDiskToDev())
|
||||||
particiones = ogGetPartitionsNumber (dsk)
|
if disks:
|
||||||
particiones = int (particiones) if particiones else 0
|
for dsk in range (1, disks+1):
|
||||||
# Tipo de tabla de particiones: 1=MSDOS, 2=GPT
|
# Tipo de tabla de particiones: 1=MSDOS, 2=GPT
|
||||||
ptt = ogGetPartitionTableType (dsk)
|
ptt = ogGetPartitionTableType (dsk)
|
||||||
ptt_map = {
|
ptt_map = {
|
||||||
|
@ -33,19 +24,26 @@ for dsk in range (1, disks+1):
|
||||||
'ZPOOL': 4,
|
'ZPOOL': 4,
|
||||||
}
|
}
|
||||||
ptt = ptt_map.get (ptt, 0)
|
ptt = ptt_map.get (ptt, 0)
|
||||||
|
|
||||||
# Información de disco (partición 0)
|
# Información de disco (partición 0)
|
||||||
s = ogGetDiskSize (dsk)
|
s = ogGetDiskSize (dsk)
|
||||||
cfg += f'{dsk}:0:{ptt}:::{s}:0;'
|
print (f'disk={dsk}\tpar=0\tcpt={ptt}\tfsi=\tsoi=\ttam={s}\tuso=0')
|
||||||
|
|
||||||
|
particiones = ogGetPartitionsNumber (dsk)
|
||||||
|
particiones = int (particiones) if particiones else 0
|
||||||
for par in range (1, particiones+1):
|
for par in range (1, particiones+1):
|
||||||
# Código del identificador de tipo de partición
|
# Código del identificador de tipo de partición
|
||||||
cod = ogGetPartitionId (dsk, par)
|
cod = ogGetPartitionId (dsk, par)
|
||||||
|
|
||||||
# Tipo del sistema de ficheros
|
# Tipo del sistema de ficheros
|
||||||
fsi = ogGetFsType (dsk, par)
|
fsi = ogGetFsType (dsk, par)
|
||||||
if not fsi: fsi = 'EMPTY'
|
if not fsi: fsi = 'EMPTY'
|
||||||
|
|
||||||
# Tamaño de la particón
|
# Tamaño de la particón
|
||||||
tam = ogGetPartitionSize (dsk, par)
|
tam = ogGetPartitionSize (dsk, par)
|
||||||
if not tam: tam = '0'
|
if not tam: tam = '0'
|
||||||
# Sistema operativo instalado
|
|
||||||
|
# Sistema operativo instalado y porcentaje de uso
|
||||||
soi = ''
|
soi = ''
|
||||||
uso = '0'
|
uso = '0'
|
||||||
if fsi not in ['', 'EMPTY', 'LINUX-SWAP', 'LINUX-LVM', 'ZVOL']:
|
if fsi not in ['', 'EMPTY', 'LINUX-SWAP', 'LINUX-LVM', 'ZVOL']:
|
||||||
|
@ -59,7 +57,6 @@ for dsk in range (1, disks+1):
|
||||||
# Sistema de archivos para datos (sistema operativo "DATA")
|
# Sistema de archivos para datos (sistema operativo "DATA")
|
||||||
if not soi and fsi not in ['EMPTY', 'CACHE']:
|
if not soi and fsi not in ['EMPTY', 'CACHE']:
|
||||||
soi = 'DATA'
|
soi = 'DATA'
|
||||||
# Obtener porcentaje de uso.
|
|
||||||
mntpt = ogGetMountPoint (dsk, par)
|
mntpt = ogGetMountPoint (dsk, par)
|
||||||
uso = subprocess.run (['df', mntpt], capture_output=True, text=True).stdout.splitlines()[-1].split()[4].replace ('%', '')
|
uso = subprocess.run (['df', mntpt], capture_output=True, text=True).stdout.splitlines()[-1].split()[4].replace ('%', '')
|
||||||
if not uso: uso = '0'
|
if not uso: uso = '0'
|
||||||
|
@ -67,39 +64,14 @@ for dsk in range (1, disks+1):
|
||||||
soi = ''
|
soi = ''
|
||||||
uso = '0'
|
uso = '0'
|
||||||
|
|
||||||
cfg += f'{dsk}:{par}:{cod}:{fsi}:{soi}:{tam}:{uso};'
|
print (f'disk={dsk}\tpar={par}\tcpt={cod}\tfsi={fsi}\tsoi={soi}\ttam={tam}\tuso={uso}')
|
||||||
|
else:
|
||||||
# Crear configuración por defecto para cliente sin disco.
|
print ('disk=1\tpar=0\tcpt=0\tfsi=\tsoi=\ttam=0\tuso=0')
|
||||||
if not cfg:
|
|
||||||
cfg = '1:0:0:::0;'
|
|
||||||
|
|
||||||
# Guardar salida en fichero temporal.
|
|
||||||
cfgfile = '/tmp/getconfig'
|
|
||||||
with open (cfgfile, 'w') as f:
|
|
||||||
if ser: f.write (f'{ser};\n')
|
|
||||||
f.write (cfg + '\n')
|
|
||||||
|
|
||||||
# Crear el menú por defecto a partir del fichero generado (no dar ninguna salida).
|
# Crear el menú por defecto a partir del fichero generado (no dar ninguna salida).
|
||||||
|
# requiere /tmp/getconfig pero este script ya no lo crea
|
||||||
#subprocess.run ([f'{ogGlobals.OGSCRIPTS}/generateMenuDefault'])
|
#subprocess.run ([f'{ogGlobals.OGSCRIPTS}/generateMenuDefault'])
|
||||||
|
|
||||||
# Componer salida formateada.
|
|
||||||
awk_script = r'''{ n=split($0,sep,";");
|
|
||||||
for (i=1; i<n; i++){
|
|
||||||
c=split (sep[i],dua,":");
|
|
||||||
if (i==1 && c==1)
|
|
||||||
printf ("ser=%s\n", dua[1]);
|
|
||||||
else
|
|
||||||
printf ("disk=%s\tpar=%s\tcpt=%s\tfsi=%s\tsoi=%s\ttam=%s\tuso=%s\n",
|
|
||||||
dua[1],dua[2],dua[3],dua[4],dua[5],dua[6],dua[7]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'''
|
|
||||||
subprocess.run (['awk', awk_script, cfgfile])
|
|
||||||
|
|
||||||
# Borramos marcas de arranque de Windows
|
# Borramos marcas de arranque de Windows
|
||||||
for f in glob.glob ('/mnt/*/ogboot.*') + glob.glob ('/mnt/*/*/ogboot.*'):
|
for f in glob.glob ('/mnt/*/ogboot.*') + glob.glob ('/mnt/*/*/ogboot.*'):
|
||||||
os.unlink (f)
|
os.unlink (f)
|
||||||
|
|
||||||
# Volver a registrar los errores.
|
|
||||||
#os.environ.pop('DEBUG', None)
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue