From 85b85ac4a37ce9d77ad24bfd9b50a73001d4ffd2 Mon Sep 17 00:00:00 2001 From: dalto Date: Thu, 25 Feb 2021 08:46:24 -0600 Subject: [PATCH] Create mkinitcpio presets --- PKGBUILD | 7 +--- .../pacman.d/hooks/60-mkinitcpio-remove.hook | 10 +++++ .../pacman.d/hooks/90-mkinitcpio-install.hook | 11 ++++++ .../scripts/kernel-install-mkinitcpio-install | 38 +++++++++++++++++++ .../scripts/kernel-install-mkinitcpio-remove | 14 +++++++ 5 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 src/etc/pacman.d/hooks/60-mkinitcpio-remove.hook create mode 100644 src/etc/pacman.d/hooks/90-mkinitcpio-install.hook create mode 100644 src/usr/share/libalpm/scripts/kernel-install-mkinitcpio-install create mode 100644 src/usr/share/libalpm/scripts/kernel-install-mkinitcpio-remove diff --git a/PKGBUILD b/PKGBUILD index d3c0b64..1d485b6 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,5 +1,5 @@ pkgname=eos-systemd-boot -pkgver=0.03 +pkgver=0.1 pkgrel=1 pkgdesc='Enables systemd-boot automation using kernel-install on EndeavourOS' arch=(any) @@ -20,9 +20,4 @@ package() # mask the default loaderentry creator mkdir -p "${pkgdir}/etc/kernel/install.d" touch "${pkgdir}/etc/kernel/install.d/90-loaderentry.install" - - # mask the mkinitcpio hooks - mkdir -p "${pkgdir}/etc/pacman.d/hooks" - touch "${pkgdir}/etc/pacman.d/hooks/90-mkinitcpio-install.hook" - touch "${pkgdir}/etc/pacman.d/hooks/60-mkinitcpio-remove.hook" } diff --git a/src/etc/pacman.d/hooks/60-mkinitcpio-remove.hook b/src/etc/pacman.d/hooks/60-mkinitcpio-remove.hook new file mode 100644 index 0000000..19af1b1 --- /dev/null +++ b/src/etc/pacman.d/hooks/60-mkinitcpio-remove.hook @@ -0,0 +1,10 @@ +[Trigger] +Type = Path +Operation = Remove +Target = usr/lib/modules/*/vmlinuz + +[Action] +Description = Removing mkinitcpio presets... +When = PreTransaction +Exec = /usr/share/libalpm/scripts/kernel-install-mkinitcpio-remove +NeedsTargets diff --git a/src/etc/pacman.d/hooks/90-mkinitcpio-install.hook b/src/etc/pacman.d/hooks/90-mkinitcpio-install.hook new file mode 100644 index 0000000..4653c7c --- /dev/null +++ b/src/etc/pacman.d/hooks/90-mkinitcpio-install.hook @@ -0,0 +1,11 @@ +[Trigger] +Type = Path +Operation = Install +Operation = Upgrade +Target = usr/lib/modules/*/vmlinuz + +[Action] +Description = Installing mkinitcpio presets... +When = PostTransaction +Exec = /usr/share/libalpm/scripts/kernel-install-mkinitcpio-install +NeedsTargets diff --git a/src/usr/share/libalpm/scripts/kernel-install-mkinitcpio-install b/src/usr/share/libalpm/scripts/kernel-install-mkinitcpio-install new file mode 100644 index 0000000..7383549 --- /dev/null +++ b/src/usr/share/libalpm/scripts/kernel-install-mkinitcpio-install @@ -0,0 +1,38 @@ +#!/bin/bash -e + +while read -r line; do + + if ! read -r pkgbase > /dev/null 2>&1 < "${line%/vmlinuz}/pkgbase"; then + # if the kernel has no pkgbase, we skip it + continue + fi + + # parse the input + version=$(basename "${line%/vmlinuz}") + vmlinuz="/${line}" + packagename=$(cat ${line%/vmlinuz}/pkgbase) + + preset_file="/etc/mkinitcpio.d/${packagename}.preset" + + # get the machine-id + machineid=$(cat /etc/machine-id) + if [[ -z ${machineid} ]]; then + echo "Failed to get the machine ID" + exit + fi + + # Find the configured esp + esp=$(bootctl -p) + + # create a preset compatible with kernel-install + preset_file="/etc/mkinitcpio.d/${packagename}.preset" + echo ":: Modifying ${preset_file}" + + echo 'ALL_config="/etc/mkinitcpio.conf"' > ${preset_file} + echo 'ALL_kver="'"${esp}/${machineid}/${version}/linux"'"' >> ${preset_file} + echo 'PRESETS=('default' 'fallback')' >> ${preset_file} + echo 'default_image="'"${esp}/${machineid}/${version}/initrd"'"' >> ${preset_file} + echo 'fallback_image="'"${esp}/${machineid}/${version}/initrd-fallback"'"' >> ${preset_file} + echo 'fallback_options="-S autodetect"' >> ${preset_file} + +done diff --git a/src/usr/share/libalpm/scripts/kernel-install-mkinitcpio-remove b/src/usr/share/libalpm/scripts/kernel-install-mkinitcpio-remove new file mode 100644 index 0000000..79151e3 --- /dev/null +++ b/src/usr/share/libalpm/scripts/kernel-install-mkinitcpio-remove @@ -0,0 +1,14 @@ +#!/bin/bash -e + +while read -r line; do + 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 preset for the package being removed + preset="/etc/mkinitcpio.d/${pkgbase}.preset" + if [[ -e ${preset} ]]; then + rm ${preset} + fi +done