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 # Check running as root
8 if [ "$(whoami)" != "root" ]; then
9 (echo "Run $0 as root.") 1>&2
13 # Check existence of program
14 if [ ! -e "server" ]; then
15 (echo "Rebuild server.") 1>&2;
19 # Identify cape-manager slots
20 slot=$(echo /sys/devices/bone_capemgr.*/slots | awk '{print $1}')
24 (echo am33xx_pwm > $slot) 1>&2 >> /dev/null
25 for port in P9_21 P9_22 P9_14 P9_16 P9_29 P9_31 P9_42 P8_13 P8_19 P8_34 P8_36 P8_45 P8_46; do
26 echo bone_pwm_$port > $slot
30 (echo cape-bone-iio > $slot) 1>&2 >> /dev/null
31 # Find adc_device_path
32 # NOTE: This has to be passed as a parameter, because it is not always the same. For some unfathomable reason. Hooray.
33 adc_device_path=$(dirname $(find /sys -name *AIN0))
36 # Run the program with parameters
37 # TODO: Can tell spawn-fcgi to run the program as an unprivelaged user?
38 # But first will have to work out how to set PWM/GPIO as unprivelaged user
40 while [ $fails -lt 10 ]; do
41 spawn-fcgi -p9005 -n -- ./server -a "$adc_device_path"
42 if [ "$?" == "0" ]; then
45 fails=$(( $fails + 1 ))
46 (echo "Restarting server after Fatal Error #$fails") 1>&2
49 (echo "Server had too many Fatal Errors ($fails)") 1>&2