#!/bin/sh

# If /dev/pilot already exists then set the default port
# to whatever that links to, other use ttyS1 as the default.
defport=$(perl -e 'print readlink("/dev/pilot");')

if [ "$1" == "--no-ask" -a -L /dev/pilot ]
then
   echo "/dev/pilot is already a symlink to $defport.  Not changing."
   exit 0
fi

# Note that I tried to account for the different serial cards out there.
# Considering that I've got a Cyclades, pilotconfig used to do the wrong
# thing for me.  -DS
#
# These are all the supported serial cards under 2.0.36.  Got more?
# send a bug report.
#
# ttyS* == normal serial port
# ttyC* == Cyclades
# ttyD* == Digiboard
# ttyE* == Stallion
# ttyF* == Computone IntelliPort II
# ttyH* == Chase
# ttyL* == SDL RISCom
# ttyP* == Hayes ESP
# ttyR* == Rocketport
# ttyV* == Control VS-1000
# ttyW* == Specialix IO8+
# ttyX* == Specialix

# echo $defport
case $defport in
/dev/*) defport=$(echo $defport | sed s_^/dev/__);;
tty[SCDEFHLPRVWX]*) defport=$(echo $defport | sed s_^/dev/__);;
*) defport="ttyS1";;
esac

echo "What serial port do you have the cradle connected to [$defport]? "
echo -n "> "
read answer
if [ -n "$answer" ]
then
   port=$(echo $answer | sed s_^/dev/__)
else
   port="$defport"
fi

echo "Setting /dev/pilot to point to /dev/$port"

# Set up a link for /dev/pilot to point to the serial port
rm -f /dev/pilot
ln -s $port /dev/pilot

exit 0
