refs #1632 add ogGrubDefaultEntry
parent
0022537bb3
commit
842b4a395b
|
@ -0,0 +1,26 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
import ogGlobals
|
||||||
|
from SystemLib import ogHelp
|
||||||
|
from BootLib import ogBootLoaderDefaultEntry
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser (add_help=False)
|
||||||
|
parser.add_argument ('disk')
|
||||||
|
parser.add_argument ('par')
|
||||||
|
parser.add_argument ('diskdefault')
|
||||||
|
parser.add_argument ('pardefault')
|
||||||
|
|
||||||
|
if 2 == len (sys.argv) and 'help' == sys.argv[1]:
|
||||||
|
#parser.print_help() sale en inglés aunque la locale indique otra cosa
|
||||||
|
ogHelp ('ogBootLoaderDefaultEntry', ogGlobals.lang.MSG_SEE+' ogGrubDefaultEntry', [])
|
||||||
|
sys.exit (0)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
ret = ogBootLoaderDefaultEntry (args.disk, args.par, args.diskdefault, args.pardefault)
|
||||||
|
|
||||||
|
if ret is not None:
|
||||||
|
if ret == True: sys.exit (0)
|
||||||
|
elif ret == False: sys.exit (1)
|
||||||
|
else: print (ret)
|
|
@ -0,0 +1,25 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
from SystemLib import ogHelp
|
||||||
|
from BootLib import ogGrubDefaultEntry
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser (add_help=False)
|
||||||
|
parser.add_argument ('disk')
|
||||||
|
parser.add_argument ('par')
|
||||||
|
parser.add_argument ('diskdefault')
|
||||||
|
parser.add_argument ('pardefault')
|
||||||
|
|
||||||
|
if 2 == len (sys.argv) and 'help' == sys.argv[1]:
|
||||||
|
#parser.print_help() sale en inglés aunque la locale indique otra cosa
|
||||||
|
ogHelp ('ogGrubDefaultEntry', 'ogGrubDefaultEntry int_ndisk int_npartition int_disk_default_entry int_npartition_default_entry', ['ogGrubDefaultEntry 1 6 1 1'])
|
||||||
|
sys.exit (0)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
ret = ogGrubDefaultEntry (args.disk, args.par, args.diskdefault, args.pardefault)
|
||||||
|
|
||||||
|
if ret is not None:
|
||||||
|
if ret == True: sys.exit (0)
|
||||||
|
elif ret == False: sys.exit (1)
|
||||||
|
else: print (ret)
|
|
@ -961,6 +961,8 @@ def ogBootLoaderDeleteEntry (disk, par, diskdel, pardel):
|
||||||
#@brief ver ogBootLoaderDefaultEntry
|
#@brief ver ogBootLoaderDefaultEntry
|
||||||
#@see ogBootLoaderDefaultEntry
|
#@see ogBootLoaderDefaultEntry
|
||||||
#*/ ##
|
#*/ ##
|
||||||
|
def ogGrubDefaultEntry (disk, par, diskdefault, pardefault):
|
||||||
|
return ogBootLoaderDefaultEntry (disk, par, diskdefault, pardefault)
|
||||||
|
|
||||||
#/**
|
#/**
|
||||||
# ogBootLoaderDefaultEntry int_disk_CFG int_partition_CFG int_disk_default_entry int_npartition_default_entry
|
# ogBootLoaderDefaultEntry int_disk_CFG int_partition_CFG int_disk_default_entry int_npartition_default_entry
|
||||||
|
@ -975,6 +977,56 @@ def ogBootLoaderDeleteEntry (disk, par, diskdel, pardel):
|
||||||
#@exception OG_ERR_OUTOFLIMIT Param $3 no es entero.
|
#@exception OG_ERR_OUTOFLIMIT Param $3 no es entero.
|
||||||
#@exception OG_ERR_NOTFOUND Fichero de configuración no encontrado: burg.cfg.
|
#@exception OG_ERR_NOTFOUND Fichero de configuración no encontrado: burg.cfg.
|
||||||
#*/ ##
|
#*/ ##
|
||||||
|
def ogBootLoaderDefaultEntry (disk, par, diskdefault, pardefault):
|
||||||
|
# Nombre de la función que llama a esta.
|
||||||
|
func = inspect.stack()[1][3]
|
||||||
|
|
||||||
|
# Error si no puede montar sistema de archivos.
|
||||||
|
dirmount = FileSystemLib.ogMount (disk, par)
|
||||||
|
if not dirmount: return None
|
||||||
|
|
||||||
|
# Comprobamos que exista fichero de configuración
|
||||||
|
# La función debe ser llamanda desde ogGrubDefaultEntry, ogBurgDefaultEntry or ogRefindDefaultEntry.
|
||||||
|
if 'ogGrubDefaultEntry' == func:
|
||||||
|
cfgfile = f'{dirmount}/boot/grubMBR/boot/grub/grub.cfg'
|
||||||
|
else:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f'Use ogGrubDefaultEntry')
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Error si no existe archivo de configuración
|
||||||
|
if not os.path.exists (cfgfile):
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, cfgfile)
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Dispositivo
|
||||||
|
label = DiskLib.ogDiskToDev (diskdefault, pardefault)
|
||||||
|
|
||||||
|
# Número de línea de la entrada por defecto en CFGFILE (primera de la partición).
|
||||||
|
grep_out = subprocess.run (['grep', '--line-number', '--max-count', '1', f'menuentry.*{label}', cfgfile], capture_output=True, text=True).stdout
|
||||||
|
if not grep_out:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'menuentry {label}')
|
||||||
|
return None
|
||||||
|
defaultentry, _ = grep_out.split (':', maxsplit=1)
|
||||||
|
|
||||||
|
# Si no hay entradas para borrar me salgo con aviso
|
||||||
|
if not defaultentry:
|
||||||
|
SystemLib.ogRaiseError (['session', 'log'], ogGlobals.OG_ERR_NOTFOUND, f'No menuentry {label}')
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Número de la de linea por defecto en el menú de usuario
|
||||||
|
menuentry = subprocess.run (f'grep -n -e menuentry {cfgfile}| cut -d: -f1 | grep -n {defaultentry} |cut -d: -f1', shell=True, text=True, capture_output=True).stdout
|
||||||
|
if not menuentry: return None
|
||||||
|
menuentry = int (menuentry)
|
||||||
|
# En grub y burg las líneas empiezan a contar desde cero
|
||||||
|
menuentry -= 1
|
||||||
|
subprocess.run (['sed', '--regexp-extended', '-i', f's/set default="?[0-9]*"?$/set default="{menuentry}"/g', cfgfile])
|
||||||
|
|
||||||
|
MSG = f'ogGlobals.lang.MSG_HELP_{func}'
|
||||||
|
try: MSG = eval (MSG)
|
||||||
|
except: MSG = ''
|
||||||
|
if '.' == MSG[-1]: MSG=MSG[0:-1]
|
||||||
|
print (f'{MSG}: {disk} {par} {diskdefault} {pardefault}')
|
||||||
|
return True
|
||||||
|
|
||||||
#/**
|
#/**
|
||||||
# ogGrubOgliveDefaultEntry num_disk num_part
|
# ogGrubOgliveDefaultEntry num_disk num_part
|
||||||
|
@ -1037,7 +1089,6 @@ def ogBootLoaderOgliveDefaultEntry (disk, par):
|
||||||
try: MSG = eval (MSG)
|
try: MSG = eval (MSG)
|
||||||
except: MSG = ''
|
except: MSG = ''
|
||||||
if '.' == MSG[-1]: MSG=MSG[0:-1]
|
if '.' == MSG[-1]: MSG=MSG[0:-1]
|
||||||
|
|
||||||
print (f'{MSG}: {disk} {par}')
|
print (f'{MSG}: {disk} {par}')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue