#!/bin/sh
# Set up and enable ppp so that it can use used to download packages
# a little later on.
set -e
. /usr/share/debconf/confmodule

db_capb backup

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

if [ -e /usr/bin/pon ]; then
	# Should ppp be used?
	db_fset base-config/use-ppp seen false
	db_input high base-config/use-ppp || true
	db_go || exit 30 # to main menu
	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
