#!/bin/bash -e
# reboot system (kernel upgrade, set chmod +x by 95secupdates)
# will be skipped if running live or REBOOT set to SKIP

chmod -x $0 # self-deactivating

. /etc/default/inithooks
[ -e $INITHOOKS_CONF ] && . $INITHOOKS_CONF

grep -qs boot=casper /proc/cmdline && exit 2

[ "$REBOOT" == "SKIP" ] && exit 0

reboot() {
    init 6
}

if [ "$SEC_UPDATES" == "FORCE" ]; then
    echo "rebooting due to kernel security upgrade..."
    reboot
else
    $INITHOOKS_PATH/bin/reboot-ask.py && reboot
fi
