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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#!@STARTUPSHELL@
#####
# This file is the default startup script used by ledcontrol. It tests
# the conditions and sets the LEDs accordingly.
#
# NOTE: Previously this file also contained the configuration, now it
# has been moved to a separate file, @sysconfdir_int@/ledcontrol.conf
#####
# Read the configuration
if [ ! -r @sysconfdir_int@/ledcontrol.conf ]; then
echo "Unable to read configuration file @sysconfdir_int@" >&2
exit 1
fi
source @sysconfdir_int@/ledcontrol.conf
# Source the scripts...
LEDDSCRIPTS="@datadir_int@"
# All scripts ending in .sh in ${LEDDSCRIPTS} are executed.
for SCRIPT in ${LEDDSCRIPTS}/*.sh ; do
# Don't re-execute myself!
if test "`basename $SCRIPT`" = "`basename $0`"; then
continue;
fi
if test -r ${SCRIPT}; then
source ${SCRIPT}
fi
done
### Check bash version...
# Disable backgrounding if using bash 2.xx.xx
if echo "${BASH_VERSION}" | grep -q "^2\." ; then
if test "${USE_BACKGROUNDING}" = YES -o "${USE_BACKGROUNDING}" = yes; then
echo "bash 2.xx.xx detected, disabling backgrounding" >&2
fi
USE_BACKGROUNDING=NO
fi
### Find out how many tests are to be done
# Also tests that SUCCESS_n is defined.
MAX_TESTS=0;
while eval 'test -n "$COMMAND_'$[${MAX_TESTS}+1]'"'; do
MAX_TESTS=$[${MAX_TESTS}+1]
# Set the next execution time (immediately)
eval 'TIME_'${MAX_TESTS}'=`date +%s`'
if eval 'test -z "$SUCCESS_'${MAX_TESTS}'"' ; then
echo "SUCCESS_${MAX_TESTS} not defined" >&2
exit 1
fi
if eval 'test -z "$FAILURE_'${MAX_TESTS}'"' ; then
echo "FAILURE_${MAX_TESTS} not defined" >&2
exit 1
fi
done
### Number of tests >= 1
if test ${MAX_TESTS} -lt 1; then
echo "no tests defined" >&2
exit 1
fi
### Do the animation if requested.
# DELAY is delay between each LED setting in ms. Total delay of animation
# will be about 6 times this.
# Don't do it is DISPLAY defined (in X).
DELAY=100
if test "$STARTUP_ANIM" = "YES" -o "$STARTUP_ANIM" = "yes"; then
if test -z "$DISPLAY"; then
echo "anim ${DELAY} S ${DELAY} C ${DELAY} N ${DELAY} xs ${DELAY} xc ${DELAY} xn ${DELAY}"
sleep 1
fi
fi
### Set the default settings
if test -n "${DEFAULT_SETTINGS}" ; then
echo "${DEFAULT_SETTINGS}"
fi
### Do the infinite loop
while : ; do
for COUNT in `seq 1 ${MAX_TESTS}`; do
if test "`eval 'echo $TIME_'$COUNT`" -le `date +%s`; then
eval COMMAND='$COMMAND_'$COUNT
# The built-in functions can change these:
eval SUCCESS='$SUCCESS_'$COUNT
eval FAILURE='$FAILURE_'$COUNT
if eval "$COMMAND" ; then
echo "$SUCCESS"
else
echo "$FAILURE"
fi
# Set the next execution time
eval 'TIME_'$COUNT'=$[`date +%s`+0$DELAY_'$COUNT']'
fi
done
sleep $MINIMUM_DELAY
done
|