diff options
author | Giancarlo Razzolini <grazzolini@archlinux.org> | 2019-10-29 14:40:58 +0100 |
---|---|---|
committer | Giancarlo Razzolini <grazzolini@archlinux.org> | 2019-10-29 14:40:58 +0100 |
commit | 7f81f51a5b813343fe55253f60a865e75f42be52 (patch) | |
tree | be882a1dc6994eb353b33a9255e34cd0866c7067 /libalpm | |
parent | 9ae6b1f928ef11e277437740908871ab535b655d (diff) | |
parent | c0ae6a74f30a586c91fb4a4f2ad773f1c018d8b6 (diff) | |
download | mkinitcpio-27.tar.gz mkinitcpio-27.tar.xz |
Merge branch 'alpm-hook'v27
Diffstat (limited to 'libalpm')
-rw-r--r-- | libalpm/hooks/60-mkinitcpio-remove.hook | 16 | ||||
-rw-r--r-- | libalpm/hooks/90-mkinitcpio-install.hook | 12 | ||||
-rw-r--r-- | libalpm/scripts/mkinitcpio-install | 44 | ||||
-rw-r--r-- | libalpm/scripts/mkinitcpio-remove | 39 |
4 files changed, 111 insertions, 0 deletions
diff --git a/libalpm/hooks/60-mkinitcpio-remove.hook b/libalpm/hooks/60-mkinitcpio-remove.hook new file mode 100644 index 0000000..ab71ed6 --- /dev/null +++ b/libalpm/hooks/60-mkinitcpio-remove.hook @@ -0,0 +1,16 @@ +[Trigger] +Type = File +Operation = Remove +Target = usr/lib/modules/*/vmlinuz + +[Trigger] +Type = Package +Operation = Remove +Target = mkinitcpio +Target = mkinitcpio-git + +[Action] +Description = Removing linux initcpios... +When = PreTransaction +Exec = /usr/share/libalpm/scripts/mkinitcpio-remove +NeedsTargets diff --git a/libalpm/hooks/90-mkinitcpio-install.hook b/libalpm/hooks/90-mkinitcpio-install.hook new file mode 100644 index 0000000..48e6a1e --- /dev/null +++ b/libalpm/hooks/90-mkinitcpio-install.hook @@ -0,0 +1,12 @@ +[Trigger] +Type = File +Operation = Install +Operation = Upgrade +Target = usr/lib/modules/*/vmlinuz +Target = usr/lib/initcpio/* + +[Action] +Description = Updating linux initcpios... +When = PostTransaction +Exec = /usr/share/libalpm/scripts/mkinitcpio-install +NeedsTargets diff --git a/libalpm/scripts/mkinitcpio-install b/libalpm/scripts/mkinitcpio-install new file mode 100644 index 0000000..d2e5041 --- /dev/null +++ b/libalpm/scripts/mkinitcpio-install @@ -0,0 +1,44 @@ +#!/bin/bash -e + +args=() +all=0 + +while read -r line; do + if [[ $line != */vmlinuz ]]; then + # triggers when it's a change to usr/lib/initcpio/* + all=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 + + preset="/etc/mkinitcpio.d/${pkgbase}.preset" + if [[ ! -e $preset ]]; then + if [[ -e $preset.pacsave ]]; then + # move the pacsave to the template + mv "${preset}.pacsave" "$preset" + else + # create the preset from the template + sed "s|%PKGBASE%|${pkgbase}|g" /usr/share/mkinitcpio/hook.preset \ + | install -Dm644 /dev/stdin "$preset" + fi + fi + + # always install the kernel + install -Dm644 "${line}" "/boot/vmlinuz-${pkgbase}" + + # compound args for each kernel + args+=(-p "${pkgbase}") +done + +if (( all )) && compgen -G /etc/mkinitcpio.d/"*.preset" > /dev/null; then + # change to use all presets + args=(-P) +fi + +if (( ${#args[@]} )); then + mkinitcpio "${args[@]}" +fi diff --git a/libalpm/scripts/mkinitcpio-remove b/libalpm/scripts/mkinitcpio-remove new file mode 100644 index 0000000..86838e4 --- /dev/null +++ b/libalpm/scripts/mkinitcpio-remove @@ -0,0 +1,39 @@ +#!/bin/bash -e + +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 |