1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#!/bin/sh
# Wrapper script for qcontrol to execute single commands
# If called with -t, it only tests if the device is supported
# Test if device is supported
device=$(grep "Hardware[[:space:]]*:" /proc/cpuinfo 2>/dev/null | \
head -n1 | sed "s/^[^:]*: //")
case $device in
"QNAP TS-109/TS-209" | "QNAP TS-409")
# Success or continue
[ "$1" = "-t" ] && exit 0 || true ;;
*)
# Failure or silently exit
[ "$1" = "-t" ] && exit 1 || exit 0 ;;
esac
# qcontrol should not be running already; silently exit
[ -z "$(pidof qcontrol)" ] || exit 0
SOCKET=/var/run/qcontrol.sock
qcontrol_start() {
rm -f $SOCKET
qcontrol -d >/dev/null &
# allow time to startup (read config)
sleep 1
pid=$(pidof qcontrol)
if [ "$pid" ]; then
if [ -S $SOCKET ]; then
echo $pid
return 0
else
kill -TERM $pid
fi
fi
return 1
}
# The gpio_keys character device is required with the default
# Debian configuration file.
test_event_dev() {
[ -c /dev/input/by-path/platform-gpio-keys-event ] || return 1
}
case $device in
"QNAP TS-409")
if [ "$1" = powerled ]; then
exit 0
fi ;;
esac
test_event_dev || exit 0
if pid=$(qcontrol_start); then
# Returns 1 even on success
qcontrol "$@" || true
# Kill the control process
kill -TERM $pid
rm -f $SOCKET
fi
exit 0
|