| #!/bin/sh |
| cd /app/client |
| |
| update_config() |
| { |
| if [ -e /tmp/config ] ; then |
| . /tmp/config |
| mv /tmp/config /tmp/configold |
| fi |
| export VIDEO_OUTPUT |
| export VIDEO_RESOLUTION |
| export AUDIO_OUTPUT |
| export VIDEO_SUPPORTED_MODES |
| export CACHED_AUTH |
| export SERVER_NAME |
| } |
| |
| export LD_LIBRARY_PATH=/app/client:/usr/local/lib:$LD_LIBRARY_PATH |
| export SERIALNUMBER=$(hnvram -qr 1ST_SERIAL_NUMBER) |
| [ -z "$SERIALNUMBER" ] && SERIALNUMBER=$(hnvram -qr SERIAL_NO) |
| |
| ulimit -c 49152 |
| |
| SERVER_MAC= |
| opts= |
| if is-tv-box; then |
| # TV box starts in powered-off mode |
| mode=waitpower |
| if [ -e /tmp/runapp ] ; then |
| mode=app |
| read appname opts </tmp/runapp |
| # For now don't let opts through |
| opts= |
| if [ "$appname" = "miniclient" ]; then |
| mode=miniclient |
| mv /tmp/runapp /tmp/runappold |
| fi |
| fi |
| else |
| opts="$opts --encodemode" |
| mode=miniclient |
| fi |
| |
| SERVER=127.0.0.1 |
| SERVER_MAC= |
| |
| while :; do |
| update_config # may change $SERVER or other things |
| echo "$0: mode: '$mode'" |
| case "$mode" in |
| miniclient) |
| rm -f /tmp/gpio/ledcontrol/waitpower |
| [ -n "$SERVER_MAC" ] && [ ! -e /tmp/goalone ] && ether-wake $SERVER_MAC |
| ./miniclient $opts "$SERVER" |
| mcstate=$? |
| SERVER=127.0.0.1 |
| if [ "$mcstate" != "0" ]; then |
| echo "Unexpected exit, miniclient restarting after a delay" |
| sleep 10 # prevent high-speed spinning in a loop |
| elif [ -e /tmp/runapp ] ; then |
| mode=app |
| else |
| mode=waitpower |
| fi |
| ;; |
| app) |
| mv /tmp/runapp /tmp/runappold |
| rm -f /tmp/gpio/ledcontrol/waitpower |
| ./run-app |
| if [ -e /tmp/poweroff ] ; then |
| mode=waitpower |
| rm -f /tmp/poweroff |
| else |
| mode=miniclient |
| fi |
| ;; |
| waitpower) |
| echo > /tmp/gpio/ledcontrol/waitpower |
| ./waitpower 2>&1 | logos waitpower |
| mode=miniclient |
| ;; |
| esac |
| done |