Fix #76: Rebuild initramfs, when installing a initramfs hook
Also shellcheck all *.trigger files from now on in the static code analysis.
This commit is contained in:
parent
5d4f279362
commit
af7c03c959
2 changed files with 45 additions and 17 deletions
|
@ -1,11 +1,11 @@
|
|||
pkgname=postmarketos-mkinitfs
|
||||
pkgver=0.0.5
|
||||
pkgrel=3
|
||||
pkgrel=4
|
||||
pkgdesc="Tool to generate initramfs images for postmarketOS"
|
||||
url="https://github.com/postmarketOS"
|
||||
# multipath-tools: kpartx
|
||||
depends="busybox-extras lddtree cryptsetup kmod multipath-tools"
|
||||
triggers="$pkgname.trigger=/usr/share/kernel/*"
|
||||
triggers="$pkgname.trigger=/etc/postmarketos-mkinitfs/hooks:/usr/share/kernel/*"
|
||||
source="init.sh.in init_functions.sh mkinitfs.sh 10-usb-unlock.sh splash1.ppm.gz splash2.ppm.gz"
|
||||
arch="noarch"
|
||||
license="GPL2"
|
||||
|
|
|
@ -1,24 +1,52 @@
|
|||
#!/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
|
||||
# get last element in path
|
||||
flavor=${i##*/}
|
||||
if ! [ -f "$i"/kernel.release ]; then
|
||||
# kernel was uninstalled
|
||||
rm -f $( readlink -f /boot/initramfs-$flavor ) \
|
||||
/boot/initramfs-$flavor /boot/vmlinuz-$flavor \
|
||||
/boot/$flavor /boot/$flavor.gz /$flavor /$flavor.gz
|
||||
continue
|
||||
fi
|
||||
abi_release=$(cat "$i"/kernel.release)
|
||||
initfs=initramfs-$flavor
|
||||
mkinitfs -o /boot/$initfs $abi_release
|
||||
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
|
||||
|
||||
# cleanup unused initramfs
|
||||
# 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
|
||||
[ -f "$i" ] || continue
|
||||
if ! [ -f /boot/vmlinuz-"${i#/boot/initramfs-}" ]; then
|
||||
rm "$i"
|
||||
fi
|
||||
done
|
||||
|
|
Loading…
Reference in a new issue