#!/bin/sh -e
# Set up and enable ppp so that it can use used to download packages
# a little later on.
# TODO: should be in ppp and/or wvdial packages.
. /usr/share/debconf/confmodule

# s/390 has no ppp
machine=`uname -m`
if [ $machine = s390 ]; then
	exit 0
fi

db_title 'Debian System Configuration'

if [ -e /usr/bin/pon ]; then
	# Should ppp be used?
	# Re-ask this question every time, because circumstances change..
	db_fset base-config/use-ppp seen false
	db_input critical base-config/use-ppp || true
	db_go || true
	db_get base-config/use-ppp
	if [ "$RET" = true ]; then
		# Set up ppp if not already set up.
		# /usr/share/ppp/provider.peer is the new location, but
		# /usr/share/doc/ppp/examples/provider.peer is used by the
		# version in testing at the time this is written.
		RECONFIGPPP=0
		if [ ! -e /etc/ppp/peers/provider ]; then
			RECONFIGPPP=1
		elif [ -e /usr/share/ppp/provider.peer ] &&
		     cmp -s /etc/ppp/peers/provider /usr/share/ppp/provider.peer; then
		     	RECONFIGPPP=1
		elif [ -e /usr/share/doc/ppp/examples/provider.peer ] &&
		     cmp -s /etc/ppp/peers/provider /usr/share/doc/ppp/examples/provider.peer; then
			RECONFIGPPP=1
		fi
		if [ "$RECONFIGPPP" = 1 ]; then
			pppconfig --noname </dev/tty >/dev/tty || true
		fi
		# redirect 3 so it goes to background w/o
		# hanging debconf later..
		pon </dev/tty >/dev/tty 2>/dev/tty 3>/dev/tty || true
		# TODO: this should be much more robust. What if ppp
		# fails to dial?
	fi
fi
