i think i might have something that works here...
This commit is contained in:
parent
27ac49a065
commit
7249d88bad
23
bootsync.py
23
bootsync.py
@ -65,7 +65,7 @@ class BootSync(object):
|
|||||||
self.schema = url.read()
|
self.schema = url.read()
|
||||||
self.schema = etree.XMLSchema(etree.XML(self.schema))
|
self.schema = etree.XMLSchema(etree.XML(self.schema))
|
||||||
self.schema.assertValid(self.xml)
|
self.schema.assertValid(self.xml)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def chkMounts(self, dryrun = False):
|
def chkMounts(self, dryrun = False):
|
||||||
if not dryrun:
|
if not dryrun:
|
||||||
@ -87,20 +87,20 @@ class BootSync(object):
|
|||||||
stderr = devnull)
|
stderr = devnull)
|
||||||
elif c.returncode == 32: # Already mounted
|
elif c.returncode == 32: # Already mounted
|
||||||
pass
|
pass
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def chkReboot(self):
|
def chkReboot(self):
|
||||||
self._getInstalledKernel()
|
self._getInstalledKernel()
|
||||||
if not self.kernelFile:
|
if not self.kernelFile:
|
||||||
return() # No isKernel="true" was specified in the config.
|
return() # No 'isKernel="true"' attribute was specified in the config.
|
||||||
if self.installedKernVer != self.currentKernVer:
|
if self.installedKernVer != self.currentKernVer:
|
||||||
self.RequireReboot = True
|
self.RequireReboot = True
|
||||||
# TODO: logger instead?
|
# TODO: logger instead?
|
||||||
print(('NOTE: REBOOT REQUIRED. '
|
print(('NOTE: REBOOT REQUIRED. '
|
||||||
'New kernel is {0}. '
|
'New kernel is {0}. '
|
||||||
'Running kernel is {1}.').format(self.installedKernVer,
|
'Running kernel is {1}.').format(self.installedKernVer,
|
||||||
self.currentKernVer))
|
self.currentKernVer))
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def getBlkids(self):
|
def getBlkids(self):
|
||||||
cmd = ['/usr/bin/blkid',
|
cmd = ['/usr/bin/blkid',
|
||||||
@ -129,12 +129,10 @@ class BootSync(object):
|
|||||||
cmd = ['/usr/bin/findmnt',
|
cmd = ['/usr/bin/findmnt',
|
||||||
'--json',
|
'--json',
|
||||||
'-T', '/boot']
|
'-T', '/boot']
|
||||||
# if os.geteuid() != 0:
|
|
||||||
# cmd.insert(0, 'sudo')
|
|
||||||
c = subprocess.run(cmd,
|
c = subprocess.run(cmd,
|
||||||
stdout = subprocess.PIPE)
|
stdout = subprocess.PIPE)
|
||||||
self.dummy_uuid = self.blkids[json.loads(c.stdout.decode('utf-8'))['filesystems'][0]['source']]
|
self.dummy_uuid = self.blkids[json.loads(c.stdout.decode('utf-8'))['filesystems'][0]['source']]
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def getChecks(self):
|
def getChecks(self):
|
||||||
# Get the default hashtype (if one exists)
|
# Get the default hashtype (if one exists)
|
||||||
@ -155,7 +153,7 @@ class BootSync(object):
|
|||||||
if rel_fpath not in self.syncs:
|
if rel_fpath not in self.syncs:
|
||||||
self.syncs[rel_fpath] = []
|
self.syncs[rel_fpath] = []
|
||||||
self.syncs[rel_fpath].append(mount)
|
self.syncs[rel_fpath].append(mount)
|
||||||
return()
|
return(None)
|
||||||
|
|
||||||
def sync(self, dryrun = False, *args, **kwargs):
|
def sync(self, dryrun = False, *args, **kwargs):
|
||||||
if not dryrun:
|
if not dryrun:
|
||||||
@ -206,7 +204,6 @@ class BootSync(object):
|
|||||||
shutil.copy2(bootsource, bootfile)
|
shutil.copy2(bootsource, bootfile)
|
||||||
return()
|
return()
|
||||||
|
|
||||||
|
|
||||||
def writeConfs(self, dryrun = False, *args, **kwargs):
|
def writeConfs(self, dryrun = False, *args, **kwargs):
|
||||||
if not dryrun:
|
if not dryrun:
|
||||||
if os.geteuid() != 0:
|
if os.geteuid() != 0:
|
||||||
@ -231,12 +228,12 @@ class BootSync(object):
|
|||||||
# If the array is in a degraded state, this will still let us at LEAST boot.
|
# If the array is in a degraded state, this will still let us at LEAST boot.
|
||||||
line = re.sub(r'\s+--hint=[\'"]?mduuid/[a-f0-9]{32}[\'"]?', '', line)
|
line = re.sub(r'\s+--hint=[\'"]?mduuid/[a-f0-9]{32}[\'"]?', '', line)
|
||||||
line = re.sub(r'^(\s*set\s+root=){0}$'.format(self.dummy_uuid),
|
line = re.sub(r'^(\s*set\s+root=){0}$'.format(self.dummy_uuid),
|
||||||
self.blkids[disk],
|
r'\g<1>{0}'.format(self.blkids[disk]),
|
||||||
line)
|
line)
|
||||||
line = re.sub(r'(?<!\=UUID\=){0}'.format(self.dummy_uuid),
|
line = re.sub(r'(?<!\=UUID\=){0}'.format(self.dummy_uuid),
|
||||||
self.blkids[disk],
|
self.blkids[disk],
|
||||||
line)
|
line)
|
||||||
line = re.sub('(^\s*|\s+)/boot', '', line)
|
line = re.sub(r'(^\s*|\s+)/boot', '', line)
|
||||||
f.write('{0}\n'.format(line))
|
f.write('{0}\n'.format(line))
|
||||||
return()
|
return()
|
||||||
|
|
||||||
@ -252,7 +249,7 @@ class BootSync(object):
|
|||||||
_hash = hasher()
|
_hash = hasher()
|
||||||
with open(fpathname, 'rb') as fh:
|
with open(fpathname, 'rb') as fh:
|
||||||
_hash.update(fh.read())
|
_hash.update(fh.read())
|
||||||
return (_hash.hexdigest())
|
return(_hash.hexdigest())
|
||||||
|
|
||||||
def _getRunningKernel(self):
|
def _getRunningKernel(self):
|
||||||
_vers = []
|
_vers = []
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||||
targetNamespace="http://git.square-r00t.net/OpTools/tree/sys/BootSync/"
|
targetNamespace="http://git.square-r00t.net/BootSync/"
|
||||||
xmlns="http://git.square-r00t.net/OpTools/tree/sys/BootSync/"
|
xmlns="http://git.square-r00t.net/BootSync/"
|
||||||
xmlns:bootsync="http://git.square-r00t.net/OpTools/tree/sys/BootSync/"
|
xmlns:bootsync="http://git.square-r00t.net/BootSync/"
|
||||||
elementFormDefault="qualified"
|
elementFormDefault="qualified"
|
||||||
attributeFormDefault="unqualified">
|
attributeFormDefault="unqualified">
|
||||||
|
|
||||||
@ -120,4 +120,4 @@
|
|||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:schema>
|
</xs:schema>
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
SEE prep.txt FOR WHAT MUST BE DONE BEFORE RUNNING BOOTSYNC.
|
SEE prep.txt FOR WHAT MUST BE DONE BEFORE RUNNING BOOTSYNC.
|
||||||
-->
|
-->
|
||||||
<bootsync xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<bootsync xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns="http://git.square-r00t.net/OpTools/tree/sys/BootSync/"
|
xmlns="http://git.square-r00t.net/BootSync/"
|
||||||
xsi:schemaLocation="http://git.square-r00t.net/OpTools/plain/sys/BootSync/bootsync.xsd">
|
xsi:schemaLocation="http://git.square-r00t.net/BootSync/plain/bootsync.xsd">
|
||||||
<!-- The actual EFI System Partitions (ESP). At least two are required. -->
|
<!-- The actual EFI System Partitions (ESP). At least two are required. -->
|
||||||
<!-- Each drive should be prepared ahead of time with efibootmgr and grub-install (see prep.txt). -->
|
<!-- Each drive should be prepared ahead of time with efibootmgr and grub-install (see prep.txt). -->
|
||||||
<partitions>
|
<partitions>
|
||||||
@ -84,7 +84,10 @@ SEE prep.txt FOR WHAT MUST BE DONE BEFORE RUNNING BOOTSYNC.
|
|||||||
<path source="/usr/lib/grub/x86_64-efi" target="grub/x86_64-efi" pattern="^.*\.(mod|lst|sh)$"/>
|
<path source="/usr/lib/grub/x86_64-efi" target="grub/x86_64-efi" pattern="^.*\.(mod|lst|sh)$"/>
|
||||||
<!-- And these are ISO files, in case you're like me and do loop mounting in Grub for rescue situations.
|
<!-- And these are ISO files, in case you're like me and do loop mounting in Grub for rescue situations.
|
||||||
(e.g. https://wiki.archlinux.org/index.php/Multiboot_USB_drive#Using_GRUB_and_loopback_devices) -->
|
(e.g. https://wiki.archlinux.org/index.php/Multiboot_USB_drive#Using_GRUB_and_loopback_devices) -->
|
||||||
|
<!-- You can do this yourself easily via https://git.square-r00t.net/RelChk/ -->
|
||||||
<!-- <path hashtype="false" source="/boot/iso" target="iso" pattern="^.*\.(iso|img)$"/> -->
|
<!-- <path hashtype="false" source="/boot/iso" target="iso" pattern="^.*\.(iso|img)$"/> -->
|
||||||
<path hashtype="md5" source="/boot/iso" target="iso" pattern=".*"/>
|
<!-- I use RelChk (see above), so I also copy over the .json files that contain easily accessible information
|
||||||
|
about the ISO images. -->
|
||||||
|
<path hashtype="md5" source="/boot/iso" target="iso" pattern="^.*\.(iso|img|json)$"/>
|
||||||
</syncPaths>
|
</syncPaths>
|
||||||
</bootsync>
|
</bootsync>
|
||||||
|
Loading…
Reference in New Issue
Block a user