#!/bin/bash

. ${TOOLKIT}-functions.sh


# get rid of idiotic installation settings, we use the
# apt.conf.d directory for this
#
file="apt.conf"
dest="/etc/apt"

[ -f $file ] && {
    grep -q "^Acquire::http::Proxy" "$dest/$file" && {
	echo "  removing proxy definition from $dest/$file ... "
	sed -e '/^Acquire::http::Proxy/d' "$dest/$file" >$MODRUNDIR/$file.noproxy
	installfile $MODRUNDIR/$file.noproxy $dest/$file root:root 644
    }
}

file="50-kusa-proxy"
dest="/etc/apt/apt.conf.d"

proxy=`jtconf service.proxy 2>/dev/null` || :

case "$proxy" in
	*:*)	# definizione server:port, ok
		installfile "$file" "$dest/" root:root 644
		;;

	"")	uninstallfiles "$dest/$file"

		;;

	*)	echo "
	ERROR: proxy definition must be servername:port (port usually is 3128)
	'service.proxy' config variable is now: $proxy
	"
		exit 1
		;;
esac

$SOMETHING_CHANGED && {
	getconfirm common.use_proxy && {
		echo "
	Proxy definitions changed, relaunch to continue
	"
		exit 1
	}
}
exit 0
