refs #1427 add ogGetOsUuid, fix bugs
parent
c8e76614ae
commit
2744273b82
|
@ -836,7 +836,8 @@ def ogGetPartitionsNumber (disk):
|
|||
if pttype in ['GPT', 'MSDOS']:
|
||||
partx_out = subprocess.run (['partx', '-gso', 'NR', DISK], capture_output=True, text=True).stdout
|
||||
lines = partx_out.splitlines()
|
||||
out = lines[-1].strip()
|
||||
if len(lines):
|
||||
out = lines[-1].strip()
|
||||
elif 'LVM' == pttype:
|
||||
lvs_out = subprocess.run (['lvs', '--noheadings', DISK], capture_output=True, text=True).stdout
|
||||
lines = lvs_out.splitlines()
|
||||
|
@ -1255,7 +1256,7 @@ def ogLockDisk(*args):
|
|||
#*/ ##
|
||||
def ogSetPartitionActive (disk, par):
|
||||
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
|
||||
|
||||
DISK = ogDiskToDev (disk)
|
||||
|
|
|
@ -65,36 +65,22 @@ def ogGetOsType(disk, partition):
|
|||
#@exception OG_ERR_FORMAT Formato incorrecto.
|
||||
#@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositiv
|
||||
#*/ ##
|
||||
def ogGetOsUuid():
|
||||
# Si se solicita, mostrar ayuda.
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "help":
|
||||
SystemLib.ogHelp(sys.argv[0], sys.argv[0] + " int_ndisk int_nfilesys", sys.argv[0] + " 1 2 => 540e47c6-8e78-4178-aa46-042e4803fb16")
|
||||
return
|
||||
def ogGetOsUuid (disk, par):
|
||||
mntdir = FileSystemLib.ogMount (disk, par)
|
||||
if not mntdir: return None
|
||||
|
||||
# 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.
|
||||
os_type = ogGetOsType(sys.argv[1], sys.argv[2])
|
||||
if os_type == "Linux":
|
||||
# Obtener UUID según el tipo de sistema operativo.
|
||||
os_type = ogGetOsType (disk, par)
|
||||
if 'Linux' == os_type:
|
||||
# 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()
|
||||
print(uuid)
|
||||
elif os_type == "Windows":
|
||||
uuid = subprocess.run (['findmnt', '-no', 'UUID', mntdir], capture_output=True, text=True).stdout.strip()
|
||||
if not uuid:
|
||||
uuid = open (os.path.join (mntdir, 'etc', 'machine-id')).read().strip()
|
||||
return uuid
|
||||
elif 'Windows' == os_type:
|
||||
# Leer identificador en clave de registro.
|
||||
uuid = RegistryLib.ogGetRegistryValue(MNTDIR, "SOFTWARE", "\\Microsoft\\Cryptography\\MachineGuid")
|
||||
print(uuid)
|
||||
uuid = RegistryLib.ogGetRegistryValue (mntdir, 'SOFTWARE', r'\Microsoft\Cryptography\MachineGuid')
|
||||
return uuid
|
||||
|
||||
|
||||
#/**
|
||||
|
|
|
@ -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)
|
|
@ -16,6 +16,7 @@ import os.path
|
|||
import subprocess
|
||||
|
||||
import ogGlobals
|
||||
import SystemLib
|
||||
import DiskLib
|
||||
import FileSystemLib
|
||||
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.
|
||||
UEFILib.ogRestoreEfiBootLoader (disk, par)
|
||||
esp = DiskLib.ogGetEsp()
|
||||
if not esp:
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, 'ESP')
|
||||
sys.exit (1)
|
||||
efidisk, efipart = esp.split()
|
||||
BootLib.ogGrubInstallMbr (efidisk, efipart, 'TRUE')
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue