#!/bin/sh

if [ $2 != "POST-DEINSTALL" ] ; then
exit 0
fi

if [ `uname -r` = "5.1-RELEASE" ] ; then
exit 0
fi

grep -q hint\.sk\.refcount /boot/device.hints
if [ $? != 0 ] ; then
exit 0
fi

ref_count=`cat /boot/device.hints | awk -F \" '/hint.sk.refcount/{print $2}'`
if [ $ref_count = 1 ] ; then
cat /boot/device.hints | sed -e "/hint.sk.refcount=\"1\"/d" > /boot/new.device.hints
mv /boot/new.device.hints /boot/device.hints

if [ -e /boot/kernel/kernel.sk ] ; then
cp /boot/kernel/kernel.sk /boot/kernel/kernel
rm /boot/kernel/kernel.sk
fi

exit 0
fi

let dec_ref_count=$ref_count-1 >> /dev/null
cat /boot/device.hints | sed -e "s/hint.sk.refcount=\"$ref_count\"/hint.sk.refcount=\"$dec_ref_count\"/" > /boot/new.device.hints
mv /boot/new.device.hints /boot/device.hints

