#!/bin/sh -e

THIS=`basename $0`

# include common stuff
. /usr/share/synce/synce-serial-common

exit_if_not_root

uname=`uname -n`

# 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_setup "/dev/$DEVTTY"

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

# Put the important parts of the environment into the remover
( synce_dumpenv
  echo "$BINDIR/synce-serial-abort-device"
) >$REMOVER
chmod +x $REMOVER

exec $BINDIR/synce-serial-start-device
