#!/bin/sh
#	Start ppp connection to host

if [ "`whoami`" != "root" ]; then
	echo "You must be root to modify ppp connections."
	exit 1;
fi


# Set up location and speed of tty...
PPPTTYDEV=/dev/cufa
PPPTTYSPEED=19200

if [ "$#" != 2 ]; then
	echo "Usage: $0 host {up,down,status}";
	exit 1;
fi

ID=`ps awwx | grep '/usr/local/bin/pppd connect /etc/ppp/hosts/'"${1}"'/../../chat.sh' | grep -v grep | awk '{print $1}'`


case "$2" in
	up)
		if [ "${ID}" != "" ]; then
			echo "PPP connection to $1 has already been started."
			exit 1;
		fi

		echo "Starting PPP connection to ${1}..."

		/usr/local/bin/pppd connect /etc/ppp/hosts/${1}/../../chat.sh \
			"${PPPTTYDEV}" "${PPPTTYSPEED}"
		;;
	down)
		if [ "${ID}" = "" ]; then
			echo "No PPP connection to host $1 has been made yet."
			exit 1;
		fi

		echo "Killing PPP connection to ${1}..."

		kill -INT ${ID};
		;;
	status)
		echo -n "PPP connection to host ${1} is "
		if [ "${ID}" = "" ]; then
			echo -n "down";
		else
			echo -n "up";
		fi
		echo "."
		;;
	*)
		echo "Usage: $0 host {up,down,status}";
		exit 1;
		;;
esac

exit 0;
