refs #1630 add ogGrubHidePartitions, fix bugs
parent
10745c1ca1
commit
3639dc1931
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
import ogGlobals
|
||||||
|
from SystemLib import ogHelp
|
||||||
|
from BootLib import ogBootLoaderHidePartitions
|
||||||
|
|
||||||
|
if 2 == len (sys.argv) and 'help' == sys.argv[1]:
|
||||||
|
#parser.print_help() sale en inglés aunque la locale indique otra cosa
|
||||||
|
ogHelp ('ogBootLoaderHidePartitions', ogGlobals.lang.MSG_SEE+' ogGrubHidePartitions', [])
|
||||||
|
sys.exit (0)
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser (add_help=False)
|
||||||
|
if 3 == len (sys.argv):
|
||||||
|
parser.add_argument ('disk')
|
||||||
|
parser.add_argument ('par')
|
||||||
|
elif 5 == len (sys.argv):
|
||||||
|
parser.add_argument ('disk')
|
||||||
|
parser.add_argument ('par')
|
||||||
|
parser.add_argument ('datadisk')
|
||||||
|
parser.add_argument ('datapar')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
if 3 == len (sys.argv):
|
||||||
|
ret = ogBootLoaderHidePartitions (args.disk, args.par)
|
||||||
|
elif 5 == len (sys.argv):
|
||||||
|
ret = ogBootLoaderHidePartitions (args.disk, args.par, args.datadisk, args.datapar)
|
||||||
|
|
||||||
|
if ret is not None:
|
||||||
|
if ret == True: sys.exit (0)
|
||||||
|
elif ret == False: sys.exit (1)
|
||||||
|
else: print (ret)
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
import ogGlobals
|
||||||
|
from SystemLib import ogHelp
|
||||||
|
from BootLib import ogGrubHidePartitions
|
||||||
|
|
||||||
|
if 2 == len (sys.argv) and 'help' == sys.argv[1]:
|
||||||
|
#parser.print_help() sale en inglés aunque la locale indique otra cosa
|
||||||
|
ogHelp ('ogGrubHidePartitions', 'ogGrubHidePartitions int_ndisk int_npartition [ num_disk_partdata num_partdata ]', ['ogGrubHidePartitions 1 2', 'ogGrubHidePartitions 1 2 1 3'])
|
||||||
|
sys.exit (0)
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser (add_help=False)
|
||||||
|
if 3 == len (sys.argv):
|
||||||
|
parser.add_argument ('disk')
|
||||||
|
parser.add_argument ('par')
|
||||||
|
elif 5 == len (sys.argv):
|
||||||
|
parser.add_argument ('disk')
|
||||||
|
parser.add_argument ('par')
|
||||||
|
parser.add_argument ('datadisk')
|
||||||
|
parser.add_argument ('datapar')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
if 3 == len (sys.argv):
|
||||||
|
ret = ogGrubHidePartitions (args.disk, args.par)
|
||||||
|
elif 5 == len (sys.argv):
|
||||||
|
ret = ogGrubHidePartitions (args.disk, args.par, args.datadisk, args.datapar)
|
||||||
|
|
||||||
|
if ret is not None:
|
||||||
|
if ret == True: sys.exit (0)
|
||||||
|
elif ret == False: sys.exit (1)
|
||||||
|
else: print (ret)
|
|
@ -440,7 +440,7 @@ def ogGrubInstallMbr (disk, par, checkos='FALSE', kernelparam=''):
|
||||||
prefixsecondstage = '' # Reactivamos el grub con el grub.cfg original.
|
prefixsecondstage = '' # Reactivamos el grub con el grub.cfg original.
|
||||||
else: # SI Reconfigurar segunda etapa (grub.cfg) == TRUE
|
else: # SI Reconfigurar segunda etapa (grub.cfg) == TRUE
|
||||||
#llamada a updateBootCache para que aloje la primera fase del ogLive
|
#llamada a updateBootCache para que aloje la primera fase del ogLive
|
||||||
subprocess.run ([f'{ogGlobals.OGSCRIPTS}/updateBootCache.py'], check=True) ## TODO: check that this works
|
subprocess.run ([f'{ogGlobals.OGSCRIPTS}/updateBootCache.py'], check=True)
|
||||||
|
|
||||||
if InventoryLib.ogIsEfiActive():
|
if InventoryLib.ogIsEfiActive():
|
||||||
# UEFI: grubSintax necesita grub.cfg para detectar los kernels: si no existe recupero backup.
|
# UEFI: grubSintax necesita grub.cfg para detectar los kernels: si no existe recupero backup.
|
||||||
|
@ -713,6 +713,8 @@ def ogCleanLinuxDevices (disk, par):
|
||||||
#@brief ver ogBootLoaderHidePartitions
|
#@brief ver ogBootLoaderHidePartitions
|
||||||
#@see ogBootLoaderHidePartitions
|
#@see ogBootLoaderHidePartitions
|
||||||
#*/ ##
|
#*/ ##
|
||||||
|
def ogGrubHidePartitions (disk, par, datadisk=None, datapar=None):
|
||||||
|
return ogBootLoaderHidePartitions (disk, par, datadisk, datapar)
|
||||||
|
|
||||||
#/**
|
#/**
|
||||||
# ogBootLoaderHidePartitions num_disk num_part
|
# ogBootLoaderHidePartitions num_disk num_part
|
||||||
|
@ -726,6 +728,82 @@ def ogCleanLinuxDevices (disk, par):
|
||||||
#@exception No existe archivo de configuracion del grub/burg.
|
#@exception No existe archivo de configuracion del grub/burg.
|
||||||
#*/
|
#*/
|
||||||
|
|
||||||
|
def ogBootLoaderHidePartitions (disk, par, datadisk=None, datapar=None):
|
||||||
|
# Nombre de la función que llama a esta.
|
||||||
|
func = inspect.stack()[1][3]
|
||||||
|
|
||||||
|
# Si no existe $4 pongo un valor imposible para la partición de datos
|
||||||
|
if datapar:
|
||||||
|
partdata = DiskLib.ogDiskToDev (datadisk, datapar)
|
||||||
|
else:
|
||||||
|
partdata = '0'
|
||||||
|
|
||||||
|
# Archivo de configuracion del grub
|
||||||
|
DIRMOUNT = FileSystemLib.ogMount (disk, par)
|
||||||
|
# La función debe ser llamanda desde ogGrubHidePartitions or ogBurgHidePartitions.
|
||||||
|
if 'ogGrubHidePartitions' == func:
|
||||||
|
cfgfile = f'{DIRMOUNT}/boot/grubMBR/boot/grub/grub.cfg'
|
||||||
|
else:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f'Use ogGrubHidePartitions')
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Error si no existe archivo del grub
|
||||||
|
if not os.path.exists (cfgfile):
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, cfgfile)
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Si solo hay una particion de Windows me salgo
|
||||||
|
num_ntfs = 0
|
||||||
|
disks = DiskLib.ogDiskToDev()
|
||||||
|
fdisk_out = subprocess.run (['fdisk', '-l']+disks, capture_output=True, text=True).stdout
|
||||||
|
for l in fdisk_out.splitlines():
|
||||||
|
if 'NTFS' in l: num_ntfs += 1
|
||||||
|
if 1 == num_ntfs: return True
|
||||||
|
|
||||||
|
# Elimino llamadas a parttool, se han incluido en otras ejecuciones de esta funcion.
|
||||||
|
subprocess.run (['sed', '-i', '/parttool/d', cfgfile])
|
||||||
|
|
||||||
|
parttabletype = DiskLib.ogGetPartitionTableType (disk)
|
||||||
|
parttabletype = parttabletype.lower()
|
||||||
|
|
||||||
|
# Entradas de Windows: numero de linea y particion. De mayor a menor.
|
||||||
|
#1:/dev/sda2
|
||||||
|
#2:/dev/sda3
|
||||||
|
awk_out = subprocess.run (f'''
|
||||||
|
awk '/menuentry.*Windows/ {{gsub(/\\)"/, ""); gsub(/^.*dev/,""); print NR":/dev"$1}} ' {cfgfile}
|
||||||
|
''', shell=True, text=True).stdout
|
||||||
|
if awk_out:
|
||||||
|
winentry = awk_out.splitlines()
|
||||||
|
winentry.reverse()
|
||||||
|
else:
|
||||||
|
winentry = []
|
||||||
|
|
||||||
|
# Particiones de Windows, pueden no estar en el grub.
|
||||||
|
winpart = []
|
||||||
|
for l in fdisk_out.splitlines(): ## aprovechamos la variable fdisk_out de antes
|
||||||
|
if 'NTFS' not in l: continue
|
||||||
|
items = l.split (' ')
|
||||||
|
winpart.append (items[0])
|
||||||
|
winpart.reverse()
|
||||||
|
|
||||||
|
# Modifico todas las entradas de Windows.
|
||||||
|
for entry in winentry:
|
||||||
|
line, part = entry.split (':')
|
||||||
|
# En cada entrada, oculto o muestro cada particion.
|
||||||
|
TEXT = ''
|
||||||
|
for parthidden in winpart:
|
||||||
|
# Muestro la particion de la entrada actual y la de datos.
|
||||||
|
if parthidden == part or parthidden == partdata:
|
||||||
|
HIDDEN = '-'
|
||||||
|
else:
|
||||||
|
HIDDEN = '+'
|
||||||
|
numdisk, numpart = DiskLib.ogDevToDisk (parthidden).split()
|
||||||
|
numdisk = int (numdisk)
|
||||||
|
numpart = int (numpart)
|
||||||
|
TEXT = f'\tparttool (hd{numdisk-1},{parttabletype}{numpart}) hidden{hidden} \n{text}'
|
||||||
|
subprocess.run (['sed', '-i', f'{line}a\\ {text}', cfgfile])
|
||||||
|
# Activamos la particion que se inicia en todas las entradas de windows.
|
||||||
|
subprocess.run (['sed', '-i', '/chainloader/i\\\tparttool ${root} boot+', cfgfile])
|
||||||
#/**
|
#/**
|
||||||
# ogGrubDeleteEntry num_disk num_part num_disk_delete num_part_delete
|
# ogGrubDeleteEntry num_disk num_part num_disk_delete num_part_delete
|
||||||
#@brief ver ogBootLoaderDeleteEntry
|
#@brief ver ogBootLoaderDeleteEntry
|
||||||
|
@ -788,7 +866,6 @@ def ogGrubOgliveDefaultEntry (disk, par):
|
||||||
#*/ ##
|
#*/ ##
|
||||||
def ogBootLoaderOgliveDefaultEntry (disk, par):
|
def ogBootLoaderOgliveDefaultEntry (disk, par):
|
||||||
func = inspect.stack()[1][3]
|
func = inspect.stack()[1][3]
|
||||||
print (f'nati func ({func})')
|
|
||||||
|
|
||||||
PART = FileSystemLib.ogMount (disk, par)
|
PART = FileSystemLib.ogMount (disk, par)
|
||||||
if not PART: return None
|
if not PART: return None
|
||||||
|
|
|
@ -9,7 +9,6 @@ import ogGlobals
|
||||||
import SystemLib
|
import SystemLib
|
||||||
import DiskLib
|
import DiskLib
|
||||||
import FileSystemLib
|
import FileSystemLib
|
||||||
import CacheLib
|
|
||||||
|
|
||||||
#/**
|
#/**
|
||||||
# ogCreateCache [int_ndisk] int_partsize
|
# ogCreateCache [int_ndisk] int_partsize
|
||||||
|
@ -240,8 +239,7 @@ def ogFormatCache():
|
||||||
os.makedirs (j, exist_ok=True)
|
os.makedirs (j, exist_ok=True)
|
||||||
|
|
||||||
# Incluir kernel e Initrd del ogLive
|
# Incluir kernel e Initrd del ogLive
|
||||||
## como lo llamo sin especificar el path entero?
|
subprocess.run ([f'{ogGlobals.OGSCRIPTS}/updateBootCache.py'])
|
||||||
#subprocess.run (['scripts/updateBootCache.py']) ## TODO
|
|
||||||
|
|
||||||
|
|
||||||
#/**
|
#/**
|
||||||
|
@ -365,5 +363,5 @@ def ogUnmountCache():
|
||||||
#@return lo mismo que devuelve initCache
|
#@return lo mismo que devuelve initCache
|
||||||
#*/ ##
|
#*/ ##
|
||||||
def initCache (*args):
|
def initCache (*args):
|
||||||
p = subprocess.run (['/opt/opengnsys/images/nati/client/shared/scripts/initCache.py'] + list(args))
|
p = subprocess.run ([f'{ogGlobals.OGSCRIPTS}/initCache.py'] + list(args))
|
||||||
return p.returncode
|
return p.returncode
|
||||||
|
|
|
@ -14,7 +14,6 @@ import ogGlobals
|
||||||
import SystemLib
|
import SystemLib
|
||||||
import DiskLib
|
import DiskLib
|
||||||
import CacheLib
|
import CacheLib
|
||||||
import FileSystemLib
|
|
||||||
|
|
||||||
|
|
||||||
#/**
|
#/**
|
||||||
|
|
|
@ -13,7 +13,6 @@ from contextlib import redirect_stdout, redirect_stderr
|
||||||
|
|
||||||
import ogGlobals
|
import ogGlobals
|
||||||
import StringLib
|
import StringLib
|
||||||
import SystemLib
|
|
||||||
|
|
||||||
#NODEBUGFUNCTIONS, OGIMG, OG_ERR_CACHESIZE, OG_ERR_NOTCACHE, OG_ERR_NOTWRITE, OG_ERR_FILESYS
|
#NODEBUGFUNCTIONS, OGIMG, OG_ERR_CACHESIZE, OG_ERR_NOTCACHE, OG_ERR_NOTWRITE, OG_ERR_FILESYS
|
||||||
#OG_ERR_REPO, OG_ERR_NOTOS, OG_ERR_NOGPT, OG_ERR_OUTOFLIMIT, OG_ERR_IMAGE, OG_ERR_CACHE
|
#OG_ERR_REPO, OG_ERR_NOTOS, OG_ERR_NOGPT, OG_ERR_OUTOFLIMIT, OG_ERR_IMAGE, OG_ERR_CACHE
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
import ogGlobals
|
import ogGlobals
|
||||||
|
@ -34,29 +35,34 @@ if not CacheLib.ogMountCache():
|
||||||
|
|
||||||
os.makedirs (ogbcache, exist_ok=True)
|
os.makedirs (ogbcache, exist_ok=True)
|
||||||
|
|
||||||
|
servervmlinuz = serverinitrd = cachevmlinuz = cacheinitrd = ''
|
||||||
# comparamos los del server
|
# comparamos los del server
|
||||||
with open (f'{ogbtftp}/ogvmlinuz.sum', 'rb') as fd: servervmlinuz = fd.read()
|
if os.path.exists (f'{ogbtftp}/ogvmlinuz.sum'):
|
||||||
with open (f'{ogbtftp}/oginitrd.img.sum', 'rb') as fd: serverinitrd = fd.read()
|
with open (f'{ogbtftp}/ogvmlinuz.sum', 'r') as fd: servervmlinuz = fd.read().strip()
|
||||||
|
if os.path.exists (f'{ogbtftp}/oginitrd.img.sum'):
|
||||||
|
with open (f'{ogbtftp}/oginitrd.img.sum', 'r') as fd: serverinitrd = fd.read().strip()
|
||||||
|
|
||||||
#comparamos los de la cache
|
#comparamos los de la cache
|
||||||
with open (f'{ogbcache}/ogvmlinuz.sum', 'rb') as fd: cachevmlinuz = fd.read()
|
if os.path.exists (f'{ogbcache}/ogvmlinuz.sum'):
|
||||||
with open (f'{ogbcache}/oginitrd.img.sum', 'rb') as fd: cacheinitrd = fd.read()
|
with open (f'{ogbcache}/ogvmlinuz.sum', 'r') as fd: cachevmlinuz = fd.read().strip()
|
||||||
|
if os.path.exists (f'{ogbcache}/oginitrd.img.sum'):
|
||||||
|
with open (f'{ogbcache}/oginitrd.img.sum', 'r') as fd: cacheinitrd = fd.read().strip()
|
||||||
|
|
||||||
print (f'MD5 on SERVER: {servervmlinuz} {serverinitrd}')
|
print (f'MD5 on SERVER: {servervmlinuz} {serverinitrd}')
|
||||||
print (f'MD5 on CACHE: {cachevmlinuz} {cacheinitrd}')
|
print (f'MD5 on CACHE: {cachevmlinuz} {cacheinitrd}')
|
||||||
|
|
||||||
do_reboot = '0'
|
do_reboot = ''
|
||||||
if cachevmlinuz != servervmlinuz:
|
if cachevmlinuz != servervmlinuz:
|
||||||
print ('ogvmlinuz updating')
|
print ('ogvmlinuz updating')
|
||||||
shutil.copy2 (f'{ogbtftp}/ogvmlinuz', f'{ogbcache}/ogvmlinuz')
|
shutil.copy2 (f'{ogbtftp}/ogvmlinuz', f'{ogbcache}/ogvmlinuz')
|
||||||
shutil.copy2 (f'{ogbtftp}/ogvmlinuz.sum', f'{ogbcache}/ogvmlinuz.sum')
|
shutil.copy2 (f'{ogbtftp}/ogvmlinuz.sum', f'{ogbcache}/ogvmlinuz.sum')
|
||||||
do_reboot = '1'
|
do_reboot = 'true'
|
||||||
|
|
||||||
if cacheinitrd != serverinitrd:
|
if cacheinitrd != serverinitrd:
|
||||||
print ('oginitrd updating')
|
print ('oginitrd updating')
|
||||||
shutil.copy2 (f'{ogbtftp}/oginitrd.img', f'{ogbcache}/oginitrd.img')
|
shutil.copy2 (f'{ogbtftp}/oginitrd.img', f'{ogbcache}/oginitrd.img')
|
||||||
shutil.copy2 (f'{ogbtftp}/oginitrd.img.sum', f'{ogbcache}/oginitrd.img.sum')
|
shutil.copy2 (f'{ogbtftp}/oginitrd.img.sum', f'{ogbcache}/oginitrd.img.sum')
|
||||||
do_reboot = '1'
|
do_reboot = 'true'
|
||||||
|
|
||||||
print (do_reboot)
|
print (do_reboot)
|
||||||
os.exit (0)
|
sys.exit (0)
|
||||||
|
|
Loading…
Reference in New Issue