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 if [ $(cat $slot | grep am33xx_pwm -c) -gt 0 ]; then
25 echo am33xx_pwm already loaded, not loading again;
27 echo Enabling PWM driver am33xx_pwm
28 echo am33xx_pwm > $slot
31 #Full correspondence from pwm0-pwm7
32 ports=(P9_22 P9_21 P9_42 P9_14 P9_16 P8_19 P8_13 P9_28);
33 portnumbers=(0 1 2 3 4 5 6 7);
35 #Don't use pwm1/3/5 to overcome issue with separate channel not being
36 #allowed to change frequency
37 #ports=(P9_22 P9_42 P9_16 P8_13 P9_28);
38 #portnumbers=(0 2 4 6 7);
40 for ((c=0; c < ${#ports[*]}; c++)); do
41 if [ ! -d $pwm/pwm${portnumbers[$c]} ]; then
42 echo Exporting PWM ${portnumbers[$c]} \(${ports[$c]}\)
43 echo ${portnumbers[$c]} > $pwm/export
45 echo PWM ${portnumbers[$c]} already enabled
48 if [ $(cat $slot | grep ${ports[$c]} -c) -gt 0 ]; then
49 echo PWM pin ${ports[$c]} already enabled, not enabling again
51 (echo bone_pwm_${ports[$c]} > $slot) 1>&2 >> /dev/null
56 if [ $(cat $slot | grep BB-ADC -c) -gt 0 ]; then
57 echo BB-ADC already loaded, not loading again;
60 (echo BB-ADC > $slot) 1>&2 >> /dev/null
63 # Find adc_device_path
64 # NOTE: This has to be passed as a parameter, because it is not always the same. For some unfathomable reason. Hooray.
65 #adc_device_path=$(dirname $(find /sys -name *AIN0))
68 # Run the program with parameters
69 # TODO: Can tell spawn-fcgi to run the program as an unprivelaged user?
70 # But first will have to work out how to set PWM/GPIO as unprivelaged user
72 while [ $fails -lt 10 ]; do
73 spawn-fcgi -p9005 -n -- ./server #-a "$adc_device_path"
74 if [ "$?" == "0" ]; then
77 fails=$(( $fails + 1 ))
78 (echo "Restarting server after Fatal Error #$fails") 1>&2
81 (echo "Server had too many Fatal Errors ($fails)") 1>&2
82 exit $fails
\0\0\0\0\0\0