From 9b0dfc9fbed73c9a70fa9ad7aea58c3b4f47ad0c Mon Sep 17 00:00:00 2001 From: Giancarlo Razzolini Date: Tue, 29 Oct 2019 09:52:45 -0300 Subject: libalpm/scripts: Add a remove script Add a remove script that cleans up kernels, images and presets upon kernel removals. It also handles mkinitcpio removal, by cleaning up presets. --- libalpm/scripts/mkinitcpio-remove | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 libalpm/scripts/mkinitcpio-remove (limited to 'libalpm') diff --git a/libalpm/scripts/mkinitcpio-remove b/libalpm/scripts/mkinitcpio-remove new file mode 100644 index 0000000..dbce860 --- /dev/null +++ b/libalpm/scripts/mkinitcpio-remove @@ -0,0 +1,39 @@ +#!/bin/bash -x + +package=0 + +while read -r line; do + if [[ $line != */vmlinuz ]]; then + # triggers when it's a change to usr/lib/initcpio/* + package=1 + continue + fi + + if ! read -r pkgbase > /dev/null 2>&1 < "${line%/vmlinuz}/pkgbase"; then + # if the kernel has no pkgbase, we skip it + continue + fi + + # remove the actual kernel and images for the package being removed + kernel="/boot/vmlinuz-${pkgbase}" + preset="/etc/mkinitcpio.d/${pkgbase}.preset" + initramfs="/boot/initramfs-${pkgbase}.img" + fallback_initramfs="/boot/initramfs-${pkgbase}-fallback.img" + if [[ -e $kernel ]]; then + # remove the installed kernel + rm $kernel + fi + if [[ -e $preset ]]; then + # remove the preset + rm $preset + fi + if [[ -e $initramfs && -e $fallback_initramfs ]]; then + # remove the images + rm $initramfs $fallback_initramfs + fi +done + +if (( package )) && compgen -G /etc/mkinitcpio.d/"*.preset" > /dev/null; then + # remove all presets + rm /etc/mkinitcpio.d/*.preset +fi -- cgit v1.2.3-24-g4f1b