refs #1427 add ogGetOsUuid, fix bugs

pull/1/head
Natalia Serrano 2025-02-03 12:48:30 +01:00
parent c8e76614ae
commit 2744273b82
4 changed files with 43 additions and 29 deletions

View File

@ -836,6 +836,7 @@ def ogGetPartitionsNumber (disk):
if pttype in ['GPT', 'MSDOS']: if pttype in ['GPT', 'MSDOS']:
partx_out = subprocess.run (['partx', '-gso', 'NR', DISK], capture_output=True, text=True).stdout partx_out = subprocess.run (['partx', '-gso', 'NR', DISK], capture_output=True, text=True).stdout
lines = partx_out.splitlines() lines = partx_out.splitlines()
if len(lines):
out = lines[-1].strip() out = lines[-1].strip()
elif 'LVM' == pttype: elif 'LVM' == pttype:
lvs_out = subprocess.run (['lvs', '--noheadings', DISK], capture_output=True, text=True).stdout lvs_out = subprocess.run (['lvs', '--noheadings', DISK], capture_output=True, text=True).stdout
@ -1255,7 +1256,7 @@ def ogLockDisk(*args):
#*/ ## #*/ ##
def ogSetPartitionActive (disk, par): def ogSetPartitionActive (disk, par):
if InventoryLib.ogIsEfiActive(): if InventoryLib.ogIsEfiActive():
SystemLib.ogEcho (['session', 'log'], 'warning', f'EFI: {ogGlobals.lang.MSG_DONTUSE} {ogSetPartitionActive}') SystemLib.ogEcho (['session', 'log'], 'warning', f'EFI: {ogGlobals.lang.MSG_DONTUSE} ogSetPartitionActive')
return return
DISK = ogDiskToDev (disk) DISK = ogDiskToDev (disk)

View File

@ -65,36 +65,22 @@ def ogGetOsType(disk, partition):
#@exception OG_ERR_FORMAT Formato incorrecto. #@exception OG_ERR_FORMAT Formato incorrecto.
#@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositiv #@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositiv
#*/ ## #*/ ##
def ogGetOsUuid(): def ogGetOsUuid (disk, par):
# Si se solicita, mostrar ayuda. mntdir = FileSystemLib.ogMount (disk, par)
if len(sys.argv) > 1 and sys.argv[1] == "help": if not mntdir: return None
SystemLib.ogHelp(sys.argv[0], sys.argv[0] + " int_ndisk int_nfilesys", sys.argv[0] + " 1 2 => 540e47c6-8e78-4178-aa46-042e4803fb16")
return
# Error si no se reciben 2 parametros.
if len(sys.argv) != 3:
SystemLib.ogRaiseError(
"session",
ogGlobals.OG_ERR_FORMAT,
f"Error: {sys.argv[0]} need 2 arguments.",
)
return
# Montar la particion, si no lo estaba previamente.
MNTDIR = FileSystemLib.ogMount(sys.argv[1], sys.argv[2])
if not MNTDIR:
return
# Obtener UUID según el tipo de sistema operativo. # Obtener UUID según el tipo de sistema operativo.
os_type = ogGetOsType(sys.argv[1], sys.argv[2]) os_type = ogGetOsType (disk, par)
if os_type == "Linux": if 'Linux' == os_type:
# Leer el UUID del sistema de ficheros raíz o el fichero de identificador. # Leer el UUID del sistema de ficheros raíz o el fichero de identificador.
uuid = subprocess.check_output(["findmnt", "-no", "UUID", MNTDIR], stderr=subprocess.DEVNULL).decode().strip() or open(os.path.join(MNTDIR, "etc", "machine-id")).read().strip() uuid = subprocess.run (['findmnt', '-no', 'UUID', mntdir], capture_output=True, text=True).stdout.strip()
print(uuid) if not uuid:
elif os_type == "Windows": uuid = open (os.path.join (mntdir, 'etc', 'machine-id')).read().strip()
return uuid
elif 'Windows' == os_type:
# Leer identificador en clave de registro. # Leer identificador en clave de registro.
uuid = RegistryLib.ogGetRegistryValue(MNTDIR, "SOFTWARE", "\\Microsoft\\Cryptography\\MachineGuid") uuid = RegistryLib.ogGetRegistryValue (mntdir, 'SOFTWARE', r'\Microsoft\Cryptography\MachineGuid')
print(uuid) return uuid
#/** #/**

View File

@ -0,0 +1,23 @@
#!/usr/bin/python3
import sys
import argparse
from SystemLib import ogHelp
from InventoryLib import ogGetOsUuid
parser = argparse.ArgumentParser (add_help=False)
parser.add_argument ('disk')
parser.add_argument ('par')
if 2 == len (sys.argv) and 'help' == sys.argv[1]:
#parser.print_help() sale en inglés aunque la locale indique otra cosa
ogHelp ('ogGetOsUuid', 'ogGetOsUuid int_ndisk int_nfilesys', ['ogGetOsUuid 1 2'])
sys.exit (0)
args = parser.parse_args()
ret = ogGetOsUuid (args.disk, args.par)
if ret is not None:
if ret == True: sys.exit (0)
elif ret == False: sys.exit (1)
else: print (ret)

View File

@ -16,6 +16,7 @@ import os.path
import subprocess import subprocess
import ogGlobals import ogGlobals
import SystemLib
import DiskLib import DiskLib
import FileSystemLib import FileSystemLib
import NetLib import NetLib
@ -61,6 +62,9 @@ if 'Windows' == ostype:
if InventoryLib.ogIsEfiActive(): # Si es UEFI copio el cargador de arranque a la partición EFI e instalo Grub. if InventoryLib.ogIsEfiActive(): # Si es UEFI copio el cargador de arranque a la partición EFI e instalo Grub.
UEFILib.ogRestoreEfiBootLoader (disk, par) UEFILib.ogRestoreEfiBootLoader (disk, par)
esp = DiskLib.ogGetEsp() esp = DiskLib.ogGetEsp()
if not esp:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, 'ESP')
sys.exit (1)
efidisk, efipart = esp.split() efidisk, efipart = esp.split()
BootLib.ogGrubInstallMbr (efidisk, efipart, 'TRUE') BootLib.ogGrubInstallMbr (efidisk, efipart, 'TRUE')
else: else: