Refactor preset generation
This commit is contained in:
parent
a08f5cf1f7
commit
540bc4cd32
3 changed files with 66 additions and 24 deletions
|
@ -4,6 +4,13 @@ Operation = Install
|
||||||
Operation = Upgrade
|
Operation = Upgrade
|
||||||
Target = usr/lib/modules/*/vmlinuz
|
Target = usr/lib/modules/*/vmlinuz
|
||||||
|
|
||||||
|
[Trigger]
|
||||||
|
Type = Package
|
||||||
|
Operation = Install
|
||||||
|
Target = mkinitcpio
|
||||||
|
Target = mkinitcpio-git
|
||||||
|
Target = eos-systemd-boot
|
||||||
|
|
||||||
[Action]
|
[Action]
|
||||||
Description = Installing mkinitcpio presets...
|
Description = Installing mkinitcpio presets...
|
||||||
When = PostTransaction
|
When = PostTransaction
|
||||||
|
|
35
src/usr/bin/gen-mkinitcpio-preset
Executable file
35
src/usr/bin/gen-mkinitcpio-preset
Executable file
|
@ -0,0 +1,35 @@
|
||||||
|
#/usr/bin/env bash
|
||||||
|
|
||||||
|
# Check to ensure we have the correct number of input parameters
|
||||||
|
if [[ -z $1 || -z $2 || -z $3 ]]; then
|
||||||
|
echo "Usage: gen-mkinitcpio-preset <version> <kernel> <packagename>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# parse the input
|
||||||
|
version=${1}
|
||||||
|
vmlinuz=${2}
|
||||||
|
packagename=${3}
|
||||||
|
|
||||||
|
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 ":: Generating ${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}
|
|
@ -1,6 +1,15 @@
|
||||||
#!/bin/bash -e
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
all=0
|
||||||
|
|
||||||
while read -r line; do
|
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 ! read -r pkgbase > /dev/null 2>&1 < "${line%/vmlinuz}/pkgbase"; then
|
||||||
# if the kernel has no pkgbase, we skip it
|
# if the kernel has no pkgbase, we skip it
|
||||||
|
@ -12,27 +21,18 @@ while read -r line; do
|
||||||
vmlinuz="/${line}"
|
vmlinuz="/${line}"
|
||||||
packagename=$(cat ${line%/vmlinuz}/pkgbase)
|
packagename=$(cat ${line%/vmlinuz}/pkgbase)
|
||||||
|
|
||||||
preset_file="/etc/mkinitcpio.d/${packagename}.preset"
|
echo /usr/bin/gen-mkinitcpio-preset ${version} ${vmlinuz} ${packagename}
|
||||||
|
|
||||||
# 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
|
done
|
||||||
|
|
||||||
|
if [[ $all == 0 ]]; then
|
||||||
|
# Run gen-mkinitcpio-preset for all the installed kernels
|
||||||
|
while read -r pkgbasefile; do
|
||||||
|
version=$(basename "${pkgbasefile%/pkgbase}")
|
||||||
|
vmlinuz="${pkgbasefile%/pkgbase}/vmlinuz"
|
||||||
|
packagename=$(cat ${pkgbasefile})
|
||||||
|
echo /usr/bin/gen-mkinitcpio-preset ${version} ${vmlinuz} ${packagename}
|
||||||
|
done < <(find /usr/lib/modules -maxdepth 2 -type f -name pkgbase)
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue