2 # Use this to quickly test run the server in valgrind
3 #spawn-fcgi -p9005 -n ./valgrind.sh
4 # Use this to run the server normally
7 if [[ "$(uname -m)" != *arm* ]]; then
8 echo Not running on the BBB
9 # Use this to quickly test run the server in valgrind
10 spawn-fcgi -p9005 -n ./valgrind.sh
11 # Use this to run the server normally
16 # Check running as root
17 if [ "$(whoami)" != "root" ]; then
18 (echo "Run $0 as root.") 1>&2
22 # Check existence of program
23 if [ ! -e "server" ]; then
24 (echo "Rebuild server.") 1>&2;
28 # Identify cape-manager slots
29 slot=$(echo /sys/devices/bone_capemgr.*/slots | awk '{print $1}')
33 if [ $(cat $slot | grep am33xx_pwm -c) -gt 0 ]; then
34 echo am33xx_pwm already loaded, not loading again;
36 echo Enabling PWM driver am33xx_pwm
37 echo am33xx_pwm > $slot
40 # Safe pins that won't interfere with one another
41 #ports=(P9_22 P9_42 P9_16 P8_13 P9_28);
42 #portnumbers=(0 2 4 6 7);
43 #Full correspondence from pwm0-pwm7
44 ports=(P9_22 P9_21 P9_42 P9_14 P9_16 P8_19 P8_13 P9_28);
45 portnumbers=(0 1 2 3 4 5 6 7);
47 # They must be exported at this stage, before the device tree
48 # overlay for that pin is enabled.
49 for ((c=0; c < ${#ports[*]}; c++)); do
50 if [ ! -d $pwm/pwm${portnumbers[$c]} ]; then
51 echo Exporting PWM ${portnumbers[$c]} \(${ports[$c]}\)
52 echo ${portnumbers[$c]} > $pwm/export
54 echo PWM ${portnumbers[$c]} already enabled
57 if [ $(cat $slot | grep ${ports[$c]} -c) -gt 0 ]; then
58 echo PWM pin ${ports[$c]} already enabled, not enabling again
60 (echo bone_pwm_${ports[$c]} > $slot) 1>&2 >> /dev/null
65 if [ $(cat $slot | grep BB-ADC -c) -gt 0 ]; then
66 echo BB-ADC already loaded, not loading again;
69 (echo BB-ADC > $slot) 1>&2 >> /dev/null
72 # Find adc_device_path
73 # NOTE: This has to be passed as a parameter, because it is not always the same. For some unfathomable reason. Hooray.
74 #adc_device_path=$(dirname $(find /sys -name *AIN0))
77 # Run the program with parameters
78 # TODO: Can tell spawn-fcgi to run the program as an unprivelaged user?
79 # But first will have to work out how to set PWM/GPIO as unprivelaged user
81 while [ $fails -lt 10 ]; do
82 spawn-fcgi -p9005 -n -- ./server #-a "$adc_device_path"
83 if [ "$?" == "0" ]; then
86 fails=$(( $fails + 1 ))
87 (echo "Restarting server after Fatal Error #$fails") 1>&2
90 (echo "Server had too many Fatal Errors ($fails)") 1>&2
91 exit $fails
\0\0\0\0\0\0