#!/bin/bash
### BEGIN INIT INFO
# Provides:          nx1led
# Required-Start:    $remote_fs loadcpufreq
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# X-Start-Before:    hddbootflush
# Short-Description: nx1 boot sequence
# Description:       Provides the ability to boot up automatically depending on available
#                    boot devices and ability to override boot using the boot menu.
### END INIT INFO
# VERSION: 4.0.0.29987

stop_led () {
    if [ -f /tmp/nx1led.pid ]; then
        kill -9 `cat /tmp/nx1led.pid`
        rm /tmp/nx1led.pid
    fi
}

case "$1" in
    start)
        exit 0
        ;;
    restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
    stop)
        # No-op
        stop_led
        ;;
    boot_sd)
        stop_led
        nohup python /root/tools/gpio/led/nx1led-sd.py 2>&1&
        echo $! > /tmp/nx1led.pid
        ;;
    boot_hdd)
        stop_led
        nohup python /root/tools/gpio/led/nx1led-hdd.py 2>&1&
        echo $! > /tmp/nx1led.pid
        ;;
    restore)
        stop_led
        nohup python /root/tools/gpio/led/nx1led-restore.py 2>&1&
        echo $! > /tmp/nx1led.pid
        ;;
    *)
        echo "Usage: nx1boot [start|stop|boot_sd|boot_hdd|restore]" >&2
        exit 3
        ;;
esac
