Create mkinitcpio presets

This commit is contained in:
dalto 2021-02-25 08:46:24 -06:00
parent 5b44ed0eeb
commit 85b85ac4a3
5 changed files with 74 additions and 6 deletions

View file

@ -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"
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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