#!/bin/sh

# Uncomment the following line to get debug info
#set -x

if [ ${#} != 1 -o "${1}" -eq 0 ]; then
    echo "Usage: $(basename ${0}) grace_delay"
    exit 1
fi

# Send USR1 signal to the running FunKey process to warn about
# impending shutdown
pkill -USR1 -F /var/run/funkey.pid > /dev/null 2>&1

# Delay for the given grace period seconds to catch signal USR2.
# If the signal is caught, then it means the running FunKey process
# canceled this shutdown and will handle it by itself.
sleep ${1}

# Delay expired, initiate shutdown
shutdown_funkey

