63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
#!/usr/bin/python3
|
|
|
|
import os
|
|
import shutil
|
|
|
|
import ogGlobals
|
|
import SystemLib
|
|
import CacheLib
|
|
|
|
#/**
|
|
# updateBootCache
|
|
#@brief acelerador arranque pxe. incorpora a la cache el initrd y el kernel.
|
|
#@param 1
|
|
#@param ejemplo:
|
|
#@return
|
|
#@exception OG_ERR_NOTCACHE # 15 si cache no existe 15
|
|
#@exception OG_ERR_NOTFOUND=2 # Fichero o dispositivo no encontrado.
|
|
#@note
|
|
#@todo:
|
|
#*/ ##
|
|
|
|
oglivedir = os.environ.get ('oglivedir', 'ogLive')
|
|
ogbtftp = f'/opt/oglive/tftpboot/{oglivedir}'
|
|
ogbcache = f'{ogGlobals.OGCAC}/boot/{oglivedir}'
|
|
|
|
#control de errores
|
|
if not os.path.isdir (ogbtftp):
|
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, ogbtftp)
|
|
os.exit (1)
|
|
|
|
if not CacheLib.ogMountCache():
|
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTCACHE, 'CACHE')
|
|
os.exit (1)
|
|
|
|
os.makedirs (ogbcache, exist_ok=True)
|
|
|
|
# comparamos los del server
|
|
with open (f'{ogbtftp}/ogvmlinuz.sum', 'rb') as fd: servervmlinuz = fd.read()
|
|
with open (f'{ogbtftp}/oginitrd.img.sum', 'rb') as fd: serverinitrd = fd.read()
|
|
|
|
#comparamos los de la cache
|
|
with open (f'{ogbcache}/ogvmlinuz.sum', 'rb') as fd: cachevmlinuz = fd.read()
|
|
with open (f'{ogbcache}/oginitrd.img.sum', 'rb') as fd: cacheinitrd = fd.read()
|
|
|
|
print (f'MD5 on SERVER: {servervmlinuz} {serverinitrd}')
|
|
print (f'MD5 on CACHE: {cachevmlinuz} {cacheinitrd}')
|
|
|
|
do_reboot = '0'
|
|
if cachevmlinuz != servervmlinuz:
|
|
print ('ogvmlinuz updating')
|
|
shutil.copy2 (f'{ogbtftp}/ogvmlinuz', f'{ogbcache}/ogvmlinuz')
|
|
shutil.copy2 (f'{ogbtftp}/ogvmlinuz.sum', f'{ogbcache}/ogvmlinuz.sum')
|
|
do_reboot = '1'
|
|
|
|
if cacheinitrd != serverinitrd:
|
|
print ('oginitrd updating')
|
|
shutil.copy2 (f'{ogbtftp}/oginitrd.img', f'{ogbcache}/oginitrd.img')
|
|
shutil.copy2 (f'{ogbtftp}/oginitrd.img.sum', f'{ogbcache}/oginitrd.img.sum')
|
|
do_reboot = '1'
|
|
|
|
print (do_reboot)
|
|
os.exit (0)
|