# steal/backport code from upstream to ensure that proxy settings are respected
# when building ltsp chroot.

if [ -f /usr/share/ltsp/plugins/ltsp-build-client/Debian/010-http-proxy ]; then
    # use upstream plugin if present
    . /usr/share/ltsp/plugins/ltsp-build-client/Debian/010-http-proxy
else

case "$MODE" in
    commandline)
        add_option "http-proxy" "`eval_gettext "use specified http proxy"`" "advanced" "true"
        add_option "no-guess-proxy" "`eval_gettext "do not autodetect apt proxy configuration"`" "advanced" "false"
        ;;
    configure)
        if [ -n "$option_http_proxy_value" ]; then
		export http_proxy="$option_http_proxy_value"
        fi
	if [ -z "$option_no_guess_proxy_value" ]; then
 		if [ -z "$http_proxy" ]; then
			eval $(apt-config shell http_proxy acquire::http::proxy)
			export http_proxy
		fi
	fi
        ;;
    after-install)
	if [ -n "$http_proxy" ]; then
		mkdir -p $ROOT/etc/apt/apt.conf.d
		cat << EOF > $ROOT/etc/apt/apt.conf.d/00proxy-guess
acquire::http::proxy "$http_proxy";
EOF
	fi
        ;;
esac

fi
