Commit 4763a1db authored by Mathias BOCQUET's avatar Mathias BOCQUET

initial commit

parents
#!/bin/bash
PID_FILE="/run/shm/$(basename $0)"
do_start() {
# are we already running ?
if [ -f $PID_FILE ]
then
printf "we are already running or badly terminated !\n"
exit 1
else
echo $$ > $PID_FILE
echo [$(date '+%Y-%m-%d %H:%M:%S')] start >> ~/recording.log
blink_loop
fi
}
cleanup() {
# Restore initial values (BRIGHTNESS and TRIGGER) of the red led
echo $LED0_INITIAL_BRIGHTNESS > /sys/class/leds/led0/brightness
echo $LED0_INITIAL_TRIGGER > /sys/class/leds/led0/trigger
# Remove pid file if present
[ -f $PID_FILE ] && rm $PID_FILE
exit 0
}
blink_loop() {
# Get initial values (BRIGHTNESS and TRIGGER) of the red led to restore it at
# exit time
LED0_INITIAL_BRIGHTNESS=$(cat /sys/class/leds/led0/brightness)
LED0_INITIAL_TRIGGER=$(sed 's/.*\[\(.*\)\].*/\1/' < /sys/class/leds/led0/trigger)
# Define blinking delays in seconds
ON_DELAY=2.0
OFF_DELAY=1.0
trap 'cleanup' EXIT HUP INT QUIT TERM
while true
do
echo default-on > /sys/class/leds/led0/trigger
sleep $ON_DELAY
echo none > /sys/class/leds/led0/trigger
sleep $OFF_DELAY
done
}
do_stop() {
echo [$(date '+%Y-%m-%d %H:%M:%S')] stop >> ~/recording.log
# kill the process otherwise, previous led states are unknown unless writed
# to a file before blink loop
pkill $(basename $0)
}
print_syntax() {
printf "Syntax : $(basename $0) <start|stop>\n"
}
if [ "$#" -ge "1" ]
then
case $1 in
start)
do_start
;;
stop)
do_stop
;;
*)
print_syntax
exit 1
;;
esac
else
print_syntax
exit 1
fi
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment