#!/bin/sh export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/mod/sbin:/mod/bin:/mod/usr/sbin:/mod/usr/bin export LD_LIBRARY_PATH=/mod/lib:/mod/usr/lib DAEMON=hd-idle case "$1" in ""|load|start|restart|status) if [ ! -r "/mod/etc/conf/$DAEMON.cfg" ]; then echo "Error[$DAEMON]: not configured" 1>&2 exit 1 fi . /mod/etc/conf/$DAEMON.cfg; ;; esac checksysfs() { ## hd-idle needs sysfs to do what it should SYSFS="$(grep sysfs /proc/mounts | head -n 1 | awk '{print $2}')" if [ -z "$SYSFS" ]; then echo -n "Trying to mount sysfs..." mkdir -p /var/sys mount sysfs /var/sys -t sysfs exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else [ ! -d /sys ] && echo "failed (backup mountpoint not available)." && exit 1 mount sysfs /sys -t sysfs exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi fi fi } start() { checksysfs echo -n "Starting $DAEMON..." $DAEMON $HD_IDLE_DEVICE -l $HD_IDLE_IDLETIME & exitval=$? sleep 1 if [ "$(pidof hd-idle)" != "" ]; then echo 'done.' else echo 'failed.' exit $exitval fi } stop() { echo -n "Stopping $DAEMON...(" for I in $(pidof hd-idle); do kill $I > /dev/null 2>&1 exitval=$? if [ "$exitval" -eq 0 ]; then echo -n 'v' else echo -n 'x' fi done echo ") done." } case "$1" in ""|load) modreg cgi 'hd-idle' 'HD-Idle' if [ $HD_IDLE_ENABLED != yes ]; then echo "hd-idle is disabled" 1>&2 exit 1 fi start ;; unload) stop modunreg cgi 'hd-idle' ;; start) start ;; stop) stop ;; restart) stop sleep 1 start ;; status) if [ "$(pidof hd-idle)" != "" ]; then echo 'running' else echo 'stopped' fi ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0