refs #1649 add ogLinuxBootParameters
parent
9704d21d20
commit
fc69e23984
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
from SystemLib import ogHelp
|
||||
from BootLib import ogLinuxBootParameters
|
||||
|
||||
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 ('ogLinuxBootParameters', 'ogLinuxBootParameters int_ndisk int_nfilesys', ['ogLinuxBootParameters 1 2'])
|
||||
sys.exit (0)
|
||||
|
||||
args = parser.parse_args()
|
||||
ret = ogLinuxBootParameters (args.disk, args.par)
|
||||
|
||||
if ret is not None:
|
||||
if ret == True: sys.exit (0)
|
||||
elif ret == False: sys.exit (1)
|
||||
else: print (ret)
|
|
@ -70,6 +70,52 @@ def ogGetWindowsName (disk, par):
|
|||
#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
|
||||
#@warning Función básica usada por \c ogBoot
|
||||
#*/ ##
|
||||
def ogLinuxBootParameters (disk, par):
|
||||
# Detectar id. de tipo de partición y codificar al mnemonico.
|
||||
mntdir = FileSystemLib.ogMount (disk, par)
|
||||
if not mntdir: return None
|
||||
|
||||
# Fichero de configuración de GRUB.
|
||||
confdir = mntdir # Sistema de archivos de arranque (/boot).
|
||||
if os.path.isdir (f'{mntdir}/boot'):
|
||||
confdir = f'{mntdir}/boot' # Sist. archivos raíz con directorio boot.
|
||||
## original bash code:
|
||||
## $MNTDIR/{,boot/}{{grubMBR,grubPARTITION}/boot/,}{grub{2,},{,efi/}EFI/*}/{menu.lst,grub.cfg}; do
|
||||
conffile = None
|
||||
for _uno in ['', 'boot']:
|
||||
for _dos in ['grubMBR/boot', 'grubPARTITION/boot', '']:
|
||||
for _tres in ['grub', 'grub2', 'EFI/*', 'efi/EFI/*']:
|
||||
for _cuatro in ['menu.lst', 'grub.cfg']:
|
||||
path = '/'.join ([mntdir, _uno, _dos, _tres, _cuatro])
|
||||
if os.path.exists (path):
|
||||
conffile = path
|
||||
if not conffile:
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, 'grub.cfg')
|
||||
return None
|
||||
|
||||
# Toma del fichero de configuracion los valores del kernel, initrd
|
||||
# y parámetros de arranque usando las cláusulas por defecto
|
||||
# ("default" en GRUB1, "set default" en GRUB2)
|
||||
# y los formatea para que sean compatibles con \c kexec . */
|
||||
awk_script = '''BEGIN {cont=-1;}
|
||||
$1~/^default$/ {sub(/=/," "); def=$2;}
|
||||
$1~/^set$/ && $2~/^default/ { gsub(/[="]/," "); def=$3;
|
||||
if (def ~ /saved_entry/) def=0;
|
||||
}
|
||||
$1~/^(title|menuentry)$/ {cont++}
|
||||
$1~/^set$/ && $2~/^root=.\\(hd__DISK__,(msdos|gpt)__PAR__\\).$/ { if (def==0) def=cont; }
|
||||
$1~/^(kernel|linux(16|efi)?)$/ { if (def==cont) {
|
||||
kern=$2;
|
||||
sub($1,""); sub($1,""); sub(/^[ \\t]*/,""); app=$0
|
||||
}
|
||||
}
|
||||
$1~/^initrd(16|efi)?$/ {if (def==cont) init=$2}
|
||||
END {if (kern!="") printf("%s %s %s", kern,init,app)}
|
||||
'''
|
||||
awk_script = awk_script.replace ('__DISK__', str (int (disk) - 1))
|
||||
awk_script = awk_script.replace ('__PAR__', par)
|
||||
awk_out = subprocess.run (['awk', awk_script, conffile], capture_output=True, text=True).stdout
|
||||
return awk_out
|
||||
|
||||
|
||||
#/**
|
||||
|
|
Loading…
Reference in New Issue