new method to identify system packages on gentoo

System packages are now:
* Anything in sys-boot/ category
* sys-libs/glibc and sys-libs/musl
* any ebuild that uses one of these eclasses:
    - dist-kernel-utils
    - linux-mod-r1
    - kernel-install
This commit is contained in:
Fredrik Eriksson 2024-07-20 16:57:24 +02:00
parent 29e5f865d0
commit 08c308277f
Signed by: feffe
GPG Key ID: E6B5580B853D322B

View File

@ -14,9 +14,9 @@ EMAINT_PATH='/usr/sbin/emaint'
GRUB_MKCONFIG='/usr/sbin/grub-mkconfig' GRUB_MKCONFIG='/usr/sbin/grub-mkconfig'
# parsing output from eix -Ttnc # parsing output from eix -Ttnc
package_re = re.compile('^\[([^\]])\] ([^ ]*) \((.*)\): .*$') package_re = re.compile(r'^\[([^\]])\] ([^ ]*) \((.*)\): .*$')
# parsing version information from substrings of the above # parsing version information from substrings of the above
slot_re = re.compile('^(\(~\))?([^\(]+)(\([^\)]+\))$') slot_re = re.compile(r'^(\(~\))?([^\(]+)(\([^\)]+\))$')
def identify_service_from_bin(exe): def identify_service_from_bin(exe):
log = logging.getLogger(sau.LOGNAME) log = logging.getLogger(sau.LOGNAME)
@ -109,6 +109,45 @@ def _sync_portage():
for line in err.splitlines(): for line in err.splitlines():
log.warning("stderr: {}".format(line)) log.warning("stderr: {}".format(line))
def is_system_package(atom):
name=re.sub(r'^[<=>]*(.*?)(?:-\d)?(?:::\w+)?$', r'\1', atom)
# sys-boot/ category should probably always be considered
# system-packages
if name.split('/')[0] == 'sys-boot':
return True
# libc-packages should be considered system-packages as they generally
# requires the system to be restarted. Not sure if there is a better way
# then just checking for specific packages here, but as far as I know there
# are not many of them anyway...
if re.search(r'^sys-libs/(glibc|musl)', name):
return True
# anything that requires boot-partition to be mounted should be considered
# system packages. So far I've identified these eclasses that touches
# boot/kernel:
# * dist-kernel-utils
# * linux-mod-r1
# * kernel-install
test_re = re.compile(r'^\s*inherit\s+(dist-kernel-utils|linux-mod|kernel-install)')
cmd=[ EQUERY_PATH, 'w', name ]
ret, out, err = sau.helpers.exec_cmd(cmd)
if not ret == 0:
log.warning(f'Unable to locate ebuild for {atom}')
# better safe than sorry; if we don't know, let's pretend it's a system
# package
return True
path = out.strip()
if not os.path.isfile(path):
log.warning(f"This path doesn't look lika a path to the ebuild for {name}: {path}")
return True
with open(path, 'r', encoding='utf-8') as f:
for line in f.readlines():
if re.search(test_re, line):
return True
return False
@ -161,11 +200,12 @@ def pkg_upgrade():
else: else:
log.error('{} -- {} -> {} configured level {} > pkg level {}'.format(name, old, new, sens, common)) log.error('{} -- {} -> {} configured level {} > pkg level {}'.format(name, old, new, sens, common))
do_rebuild = False do_rebuild = False
if name.startswith('sys-kernel/'):
if is_system_package(f'{name}-{new}'):
if do_system_upgrade: if do_system_upgrade:
do_grub = True do_grub = True
else: else:
raise sau.errors.UpgradeError(f"Kernel package {name} has an update, but system upgrade is disabled") raise sau.errors.UpgradeError(f"System package {name} has an update, but system upgrade is disabled")
if not do_rebuild: if not do_rebuild:
raise sau.errors.UpgradeError('Some packages require manual attention, did not upgrade') raise sau.errors.UpgradeError('Some packages require manual attention, did not upgrade')