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:
Oliver Smith 2017-06-13 00:55:49 +02:00
parent 7c0c813610
commit c076fcf9c2
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
3 changed files with 48 additions and 20 deletions

View File

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

View File

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

View File

@ -21,8 +21,8 @@ DIR="$(cd "$(dirname "$0")" && pwd -P)"
cd "$DIR"/..
# Shell: shellcheck
sh_files="test/static_code_analysis.sh"
echo "Test $sh_files with shellcheck..."
sh_files="test/static_code_analysis.sh $(find . -name '*.trigger')"
echo "Test with shellcheck: $sh_files"
for file in ${sh_files}; do
shellcheck "${file}"
done
@ -31,7 +31,7 @@ done
# E501: max line length
# F401: imported, but not used, does not make sense in __init__ files
# E402: module import not on top of file, not possible for testcases
echo "Test *.py files with flake8..."
echo "Test with flake8: *.py"
echo "NOTE: Run 'autopep8 -ria $PWD' to fix code style issues"
py_files="$(find . -name '*.py')"
_ignores="E501,E402"