switch patterns
[svn42.git] / raspberrypi_gpio_relay_licht / rc.local
1 #!/bin/sh -e
2 #
3 # rc.local
4 #
5 # This script is executed at the end of each multiuser runlevel.
6 # Make sure that the script will "exit 0" on success or any other
7 # value on error.
8 #
9 # In order to enable or disable this script just change the execution
10 # bits.
11 #
12 # By default this script does nothing.
13
14 for gpio in 4 17 18 21 22 23; do
15  echo $gpio > /sys/class/gpio/export
16  echo out > /sys/class/gpio/gpio$gpio/direction
17  chown www-data /sys/class/gpio/gpio$gpio/value
18 done
19
20
21 # Print the IP address
22 _IP=$(hostname -I) || true
23 if [ "$_IP" ]; then
24   printf "My IP address is %s\n" "$_IP"
25 fi
26
27 MAX_TRIES=20
28 if ! ifconfig eth0 && ifconfig wlan0 ; then
29   sleep 6
30   while ((MAX_TRIES-- > 0)) && ! /sbin/wpa_cli status | grep -q wpa_state=COMPLETED; do
31     /sbin/wpa_cli status
32     ifdown wlan0
33     ifup wlan0
34   done
35 fi
36
37 su realraum -s /bin/sh -c "sleep 10 && /home/realraum/play-sound-status.py /home/realraum/play-sound-status.cfg &>/dev/null &" &
38 su realraum -s /bin/sh -c "sleep 10 && /home/realraum/stuff.py &>/dev/null &" &
39
40 exit 0