pmaports/postmarketos-mkinitfs/postmarketos-mkinitfs.trigger
Oliver Smith af7c03c959 Fix #76: Rebuild initramfs, when installing a initramfs hook
Also shellcheck all *.trigger files from now on in the static code analysis.
2017-06-13 00:55:49 +02:00

55 lines
1.3 KiB
Bash

#!/bin/sh
# $1: kernel flavor
rebuild_initfs_flavor()
{
abi_release=$(cat /usr/share/kernel/"$1"/kernel.release)
mkinitfs -o /boot/initramfs-"$1" "$abi_release"
}
# Each argument to this shell script is a path, that caused the trigger to
# execute. When a hook was changed, rebuild all flavors. When only one flavor
# was changed, find out if it has been installed or uninstalled, and rebuild
# it or delete the left-overs.
rebuild_all="false"
for i in "$@"; do
case "$i" in
# Hook change
/etc/postmarketos-mkinitfs/hooks*)
rebuild_all="true"
break ;;
# Kernel flavor change
/usr/share/kernel/*)
flavor=${i##*/}
if [ -f "$i"/kernel.release ]; then
# installed
[ "$rebuild_all" = "true" ] || rebuild_initfs_flavor "$flavor"
else
# uninstalled
rm -f "$( readlink -f /boot/initramfs-"$flavor" )" \
/boot/initramfs-"$flavor" /boot/vmlinuz-"$flavor" \
/boot/"$flavor" /boot/"$flavor".gz /"$flavor" /"$flavor".gz
fi
break ;;
esac
done
# Rebuild all flavors, if necessary
if [ "$rebuild_all" = "true" ]; then
for i in /usr/share/kernel/*; do
[ -d "$i" ] && rebuild_initfs_flavor "${i##*/}"
done
fi
# Cleanup unused initramfs
for i in /boot/initramfs-[0-9]*; do
[ -f "$i" ] || continue
if ! [ -f /boot/vmlinuz-"${i#/boot/initramfs-}" ]; then
rm "$i"
fi
done
sync
exit 0