#! /bin/bash # vim: set tabstop=4 shiftwidth=4 noexpandtab filetype=sh: # ADTPro - *nix startup shell script # # Note: # Invoke with the name of the communications button to push # in order to start with that mode active (i.e. './adtpro.sh ethernet') # # You can set two variables here: # 1. $MY_JAVA_HOME - to pick a particular java to run under # 2. $ADTPRO_HOME - to say where you installed ADTPro # # Set default ADTPRO_HOME to be the fully qualified # current working directory. #export ADTPRO_HOME="`dirname \"$0\"`" #cd "$ADTPRO_HOME" #export ADTPRO_HOME=`pwd` # Uncomment and modify one or both of the lines below if you # want to specify a particular location for Java or ADTPro. # NOTE: be sure to include a trailing slash on MY_JAVA_HOME, # but not on ADTPRO_HOME. # # export MY_JAVA_HOME=/usr/local/java/bin/ # export ADTPRO_HOME=~/myuser/adtpro usageExit () { echo "usage:" 1>&2 echo "adtpro.sh [headless] [serial|ethernet|audio|localhost] [serialPortName]" 1>&2 exit 1 } export ADTPRO_HOME=/usr/local/adtpro cd "$ADTPRO_HOME" OS=`uname` OS_ARCH=`uname -m` [[ $1 == "headless" ]] && { headless=1; shift; } || headless= if [[ $1 && ( $1 != "serial" && $1 != "ethernet" && $1 != "audio" && $1 != "localhost" ) ]]; then usageExit fi # For Linux, use this: if [ "$OS" = "Linux" ]; then serialPortName= if [[ $1 == "serial" ]]; then if [[ $2 ]]; then serialPortName="$2" [[ ${serialPortName:0:5} == "/dev/" ]] && serialPortName=${serialPortName:5} if [[ ! -c /dev/$serialPortName ]]; then echo "Serial port $serialPortName not found." 1>&2 usageExit fi elif [[ -c /dev/ttyUSBlower ]]; then serialPortName=ttyUSBlower elif [[ $(ls -1 /dev/ttyUSBlower_hub* 2> /dev/null | wc -l) -gt 0 ]]; then serialPortName=$(ls -1 /dev/ttyUSBlower_hub* 2> /dev/null | head -1 | cut -c 6-) elif [[ $(ls -1 /dev/ttyUSBupper_hub* 2> /dev/null | wc -l) -gt 1 ]]; then serialPortName=$(ls -1 /dev/ttyUSBupper_hub* 2> /dev/null | head -1 | cut -c 6-) else echo "No eligible USB-to-serial adapter found." 1>&2 echo "Possible ports:" 1>&2 echo " lower USB port" echo " any port on lower USB hub with no other adapters" echo " lowest port on USB hub on upper or lower USB port with multiple adapters" usageExit fi fi if [[ $(grep CommPort= /usr/local/adtpro/disks/ADTPro.properties) ]]; then if [[ $serialPortName ]]; then sed -i "s/^CommPort=.*$/CommPort=\/dev\/$serialPortName/" /usr/local/adtpro/disks/ADTPro.properties &> /dev/null else serialPortName=$(grep 'CommPort=/dev/' /usr/local/adtpro/disks/ADTPro.properties 2> /dev/null | cut -f 3 -d '/') fi else echo -e "#ADTPro.properties\n#$(date)\nCommPortSpeed=115200\nCommPortBootstrapSpeed=2400\nCommPort=/dev/$serialPortName\nCommPortBootstrapPacing=250\nHardwareHandshaking=false\nSerialIPHost=localhost\nSerialIPPort=1977" > /usr/local/adtpro/disks/ADTPro.properties chmod ugo+w /usr/local/adtpro/disks/ADTPro.properties fi ADTPRO_EXTRA_JAVA_PARMS="-Dgnu.io.rxtx.SerialPorts=/dev/$serialPortName" if [ -f /usr/bin/raspi-config ]; then export RXTXLIB=lib/rxtx/rxtx-2.2pre2-local/arm elif [ "$OS_ARCH" = "i686" ]; then export RXTXLIB=lib/rxtx/rxtx-2.2pre2-local/i686-pc-linux-gnu else if [ "$OS_ARCH" = "i386" ]; then export RXTXLIB=lib/rxtx/rxtx-2.2pre2-local/i686-pc-linux-gnu else export RXTXLIB=lib/rxtx/rxtx-2.2pre2-local/x86_64-unknown-linux-gnu fi fi fi # For OSX, use this: if [ "$OS" = "Darwin" ]; then if [ "$OS_ARCH" = "powerpc" ]; then export RXTXLIB=lib/rxtx/rxtx-2.1-7-bins-r2/Mac_OS_X else export RXTXLIB=lib/rxtx/rxtx-2.2pre2-local/mac-10.5 fi fi # For Solaris, use this: if [ "$OS" = "SunOS" ]; then export RXTXLIB=lib/rxtx/rxtx-2.2pre2-local/sparc-sun-solaris2.10-32 fi # Set up the library location. export TWEAK1="-Djava.library.path=" export TWEAK=$TWEAK1$ADTPRO_HOME/$RXTXLIB if [[ $headless ]]; then if [[ ! $1 || ! -f /usr/bin/xvfb-run ]]; then if [[ ! -f /usr/bin/xvfb-run ]]; then echo "Headless operation requires xvfb." usageExit else echo "Headless operation requires a communication mode (e.g. serial)." usageExit fi exit 1 else HEADLESS="xvfb-run --auto-servernum " fi fi if [[ $serialPortName && $(ps aux | grep "/sbin/getty.*$serialPortName") ]]; then sudo pkill -f "/sbin/getty.*$serialPortName" fi sudo pkill -f [A]DTPro cd "$ADTPRO_HOME"/disks $HEADLESS"$MY_JAVA_HOME"java -Xms256m -Xmx512m "$TWEAK" $ADTPRO_EXTRA_JAVA_PARMS -cp ../lib/ADTPro.jar:../"$RXTXLIB"/../RXTXcomm.jar:../lib/AppleCommander/AppleCommander-ac.jar org.adtpro.ADTPro $* & if [[ $1 == "serial" ]]; then echo "Starting up on interface $serialPortName. Please wait..." fi if [ -t 0 ]; then sleep 30 fi