12-16-2023, 03:00 PM
Code:
#!/bin/sh
# This script installs RockPro64 devicetree files into /boot when new kernels
# are installed. It should be copied into /etc/kernel/{postinst.d,postrm.d}/
# and named with a "zz-" prefix (e.g. zz-rockpro64-dtbs).
# https://www.debian.org/doc/manuals/debian-kernel-handbook/ch-update-hooks.html
set -e
exec </dev/null >&2 # Don't use stdin or stdout
version="$1"
pkgname=${DPKG_MAINTSCRIPT_PACKAGE:-kernel package}
if [ -z "$version" ]; then
echo "W: $pkgname did not pass a version number; exiting."
exit 0
fi
eval set -- "$DEB_MAINT_PARAMS"
action="$1"
srcdir=/usr/lib/linux-image-${version}/rockchip
fname=rk3399-rockpro64-v2.dtb
dirname=dtbs-${version}
destsubdir=/boot/$dirname/rockchip
if [ "$action" = configure ]; then
if ! [ -f "$srcdir/$fname" ]; then
echo "W: $pkgname did not provide $srcdir/$fname; exiting."
exit 0
fi
echo "I: installing $destsubdir/$fname"
mkdir -p "$destsubdir"
cp "$srcdir/$fname" "$destsubdir/$fname"
if [ -L /boot/dtbs ] && [ "$(readlink /boot/dtbs)" != "$dirname" ]; then
#echo "I: moving /boot/dtbs symlink to /boot/dtbs.old"
rm -f /boot/dtbs.old
mv /boot/dtbs /boot/dtbs.old
fi
if ! [ -L /boot/dtbs ]; then
#echo "I: creating /boot/dtbs symlink"
ln -s "$dirname" /boot/dtbs
fi
fi
if [ "$action" = remove ]; then
if [ -L /boot/dtbs ] && [ "$(readlink /boot/dtbs)" = "$dirname" ]; then
#echo "I: removing /boot/dtbs symlink"
rm /boot/dtbs
if [ -L /boot/dtbs.old ]; then
#echo "I: moving /boot/dtbs.old symlink to /boot/dtbs"
mv /boot/dtbs.old /boot/dtbs
fi
#todo: look for candidates to become .old, so removing two new kernels
# in a row won't leave the system without a dtbs symlink
fi
if [ -f "$destsubdir/$fname" ]; then
echo "I: removing $destsubdir/$fname"
rm "$destsubdir/$fname"
rmdir "$destsubdir" || true
rmdir "/boot/$dirname" || true
fi
fi