and we need to enforce the root FS UUID. i think.

this should work. probably.
This commit is contained in:
2021-01-20 04:33:51 -05:00
parent be03c6bce8
commit 26c3da0bd2
3 changed files with 43 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
import hashlib
import json
import os
import pathlib
import shutil
@@ -43,6 +44,7 @@ class BaseUpdater(object):
self.do_update = False
self.force_update = False
self.iso_url = None
self.boot_uuid = None
self.hash_type = hash_type
self.dest_iso = os.path.join(self.dest_dir, self.dest_file)
self.dest_ver = os.path.join(self.dest_dir, self.ver_file)
@@ -108,7 +110,30 @@ class BaseUpdater(object):
return(False)
return(True)
def getUUID(self):
disk_cmd = subprocess.run(['findmnt',
'-T', '/boot',
'--json'],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
if (disk_cmd.returncode != 0) or disk_cmd.stderr.decode('utf-8').strip() != '':
raise RuntimeError('Could not get disk UUID: {0}'.format(disk_cmd.stderr.decode('utf-8')))
disk_dict = json.loads(disk_cmd.stdout.decode('utf-8'))
disk_dev = disk_dict['filesystems']['source']
info_cmd = subprocess.run(['blkid',
'-o', 'export',
disk_dev],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
if (info_cmd.returncode != 0) or info_cmd.stderr.decode('utf-8').strip() != '':
raise RuntimeError('Could not get disk UUID: {0}'.format(info_cmd.stderr.decode('utf-8')))
info_dict = {i.split('=', 1)[0].lower():i.split('=', 1)[1]
for i in info_cmd.stdout.decode('utf-8').splitlines()}
self.boot_uuid = info_dict.get('uuid')
return(None)
def grub(self):
self.getUUID()
import jinja2
loader = jinja2.FileSystemLoader(searchpath = self._tpl_dir)
tplenv = jinja2.Environment(loader = loader)
@@ -117,7 +142,8 @@ class BaseUpdater(object):
fh.write(tpl.render(iso_path = os.path.abspath(
os.path.expanduser(
os.path.join(self.grub_iso_dir,
self.dest_file)))))
self.dest_file))),
disk_uuid = self.boot_uuid))
os.chmod(self.grub_cfg, 0o0755)
cmd = subprocess.run(['grub-mkconfig',
'-o', '{0}/grub/grub.cfg'.format(self.boot_dir)],