Here are the scripts I've been using for serial connections and
hotplug.  Their chief advantage is that they easily support multiple
PDAs connected at the same time (when used with vdccm).  They're also
very simple, and avoid the config/start two-step that's currently
required.

This synce-serial-start puts all of the PPP options on the
command-line, rather than using a config file.  It also adds the
"updetach" option if stdin is a terminal, to make it easier to tell
when the device is connected.  It's configured through the
environment.  Important options:

        SYNCE_DEV: Device to connect to (default /dev/ttyUSB0)
    SYNCE_LOCALIP: IP address of PC (default 192.168.131.102)
   SYNCE_REMOTEIP: IP address of PDA (default 192.168.131.201)
    SYNCE_DEVNAME: Device name to use in abort script (default synce-device)
   
You can see some other less-important options in the script.

synce-serial-abort takes the device name either in the SYNCE_DEVNAME
environment variable, or on the command-line.  If specified, it must
match the one used with synce-serial-start; as above, default is
synce-device.

The hotplug script can go into /etc/hotplug/usb/synce.  If dccm/vdccm
is running, and if you have the right magic in your usb.usermap file
(this is mine:

    # PocketPC ActiveSync devices
    synce   0x0003  0x413c  0x4003  0x00    0x00    0x00    0x00    0x00        
0x00    0x00    0x00    0x00
    synce   0x0003  0x413c  0x4004  0x00    0x00    0x00    0x00    0x00        
0x00    0x00    0x00    0x00

), the PDA will come up on its own, regardless of which USB TTY it's
assigned.

I have been using these scripts for the last two weeks, along with
vdccm, to connect up to 20 PDAs to my computer at once, and copy
identical configurations to them.

Comments are welcome.  I'd love to get these scripts in the main synce
distribution, or any other scripts that easily support multiple
devices.

---Scott.

#!/bin/bash


PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:$PATH"
pppopts="nodefaultroute noauth local crtscts"
if [ -t 1 ]; then
  echo "stdout is a terminal."
  pppopts="$pppopts updetach"
fi

exec ${SYNCE_PPP:-pppd} ${SYNCE_DEV:-/dev/ttyUSB0} ${SYNCE_DEVSPEED:-115200} connect "${SYNCE_PPP_CONNECT:-/usr/local/bin/synce-serial-chat}" ${SYNCE_LOCALIP:-192.168.131.102}:${SYNCE_REMOTEIP:-192.168.131.201} ms-dns ${SYNCE_LOCALIP:-192.168.131.102} linkname ${SYNCE_DEVNAME:-synce-device} $pppopts $SYNCE_PPP_OPTIONS
#!/bin/sh

THIS=`basename $0`

# include common stuff
. /usr/local/share/synce/synce-serial-common
if [ -n "$1" ]
then
  SYNCE_DEVNAME="$1"
elif [ -z "$SYNCE_DEVNAME" ]
then
  SYNCE_DEVNAME="synce-device"
fi

exit_if_not_root

PIDFILE="/var/run/ppp-$SYNCE_DEVNAME.pid"

if ! [ -f "$PIDFILE" ]; then
  echo "
${THIS} was unable find a running SynCE connection. Will do nothing.
" >&2
  exit 0
fi

while [ -f "$PIDFILE" ]; do
  PID="`head -1 /var/run/ppp-$SYNCE_DEVNAME.pid`"

  if [ -z "${PID}" ]; then
  	echo "
${THIS} found invalid PID in ppp-$SYNCE_DEVNAME; giving up.
" >&2
	exit 1
  fi

  ${INFO} "Killing process with PID ${PID}"

  if kill ${PID}; then
  	  echo "
${THIS} has requested shutdown of $SYNCE_DEVNAME.
"
  else
	  echo "
${THIS} was unable stop the SynCE connection with PID ${PID}.
" >&2
	  exit 1
  fi
  sleep 3
done

#!/bin/bash

# Uncomment to stop this from running, to bring everything up by hand.
# exit 0
 
# Log all output
exec >>/var/log/synce 2>&1

PATH="/usr/local/sbin:/usr/local/bin:$PATH"
SYSFS="/sys"
uname=`uname -n`

function log() {
  echo "`date +"%b %d %X"` $uname[$$] $0 $@"
}

log started

# Debug script
#set -x

# OK, first find our TTY.
DEVTTY="`ls "$SYSFS$DEVPATH" |grep tty |head -1`"
if [ -z "$DEVTTY" ]; then
  log "Couldn't find TTY for '$DEVPATH'"
  exit 1
fi

# Set up the environment
SYNCE_DEV="/dev/$DEVTTY"
SYNCE_DEVNUM="`echo "$SYNCE_DEV" |sed -e 's/^[^0-9]*\([0-9][0-9]*\)$/\1/'`"
SYNCE_LOCALIP="192.168.141.`expr 1 + $SYNCE_DEVNUM`"
SYNCE_REMOTEIP="192.168.141.`expr 129 + $SYNCE_DEVNUM`"
SYNCE_DEVNAME="synce-device$SYNCE_DEVNUM" 
export SYNCE_DEV SYNCE_DEVNUM SYNCE_LOCALIP SYNCE_REMOTEIP SYNCE_DEVNAME 

# Debug environment
#env


# Abort any connections on the current port, even if this isn't an add
# event.
synce-serial-abort >> /dev/null 2>&1

if [ "$ACTION" != "add" ]; then
  exit 0
fi

log "iPAQ added to $SYNCE_DEV #$SYNCE_DEVNUM" 
log "Remover is '$REMOVER'"

# Put the important parts of the environment into the remover
env |egrep 'SYNCE|PATH' |sed -e 's/^/export /' >$REMOVER

cat >>$REMOVER <<EOF
  exec >>/var/log/synce 2>&1
  # For debugging
  #set -x
  export uname=\`uname -n\`
  function log() {
    echo "\`date +"%b %d %X"\` \$uname[\$\$] \$0 \$@"
  }
  log "iPAQ removed from \$SYNCE_DEV #\$SYNCE_DEVNUM"
  my-synce-serial-abort
  log "synce stopped for \$SYNCE_DEV #\$SYNCE_DEVNUM"
EOF
chmod +x $REMOVER

# Debug PPP
#export SYNCE_PPP_OPTIONS=debug

my-synce-start-serial

log "synce started for $SYNCE_DEV"

exit 0

Reply via email to