diff -Naurd base-config-2.35/apt-setup base-config-2.35ubuntu14/apt-setup
--- base-config-2.35/apt-setup	2004-06-29 17:49:59.000000000 +0200
+++ base-config-2.35ubuntu14/apt-setup	2004-07-23 10:27:34.000000000 +0200
@@ -172,6 +172,8 @@
 # scanned. It prompts the user if there are more cd's to scan and
 # scans them. Pass in the device that is known to be the cd drive.
 handle_rest_cds () {
+	# Warty specific change: we will never ship "another CD". (See #355)
+	if [ -e $TMPFILE ]; then return 0; fi
 	LOOP=1
 	while [ "$LOOP" ]; do
 		# Make sure the cd is unmounted, we may be prompting
@@ -267,15 +269,28 @@
 		# Unable to mount it, or the cd was bad. Make sure that cdrom
 		# is the default, and just go on to ask them where they want
 		# apt to install from.
-		db_set apt-setup/uri_type "cdrom"
+		# Warty change: no need to set a default if we are guessing
+		if [ ! -e $TMPFILE ]; then
+			db_set apt-setup/uri_type "cdrom"
+		fi
 		db_subst apt-setup/uri_type note $(gettext 'You probably used a CD to install the Debian base system, but it is not currently in the drive. You should probably just insert it and select "cdrom".')
 	fi
 fi
 
 while [ "$MAINLOOP" ] || add_another; do
 	# Ask what source apt should install from.
+	# Warty change: dynamically choose priority to hide questions (See: #296 and #353)
+	promptpri="critical"
+	if [ -e "$TMPFILE" ]; then
+		# try to be sure that $TMPFILE hasn't been mangled
+		URI="`cat "$TMPFILE" | grep "^Uritype: " | awk '{print $2}'`"
+		if [ "$URI" != "unknown" ] && [ "x$URI" != "x" ]; then
+			promptpri="medium"
+			db_set apt-setup/uri_type "$URI"
+		fi
+	fi
 	db_fset apt-setup/uri_type seen false
-	db_input critical apt-setup/uri_type || true
+	db_input "$promptpri" apt-setup/uri_type || true
 	db_go || exit 30
 	db_get apt-setup/uri_type
 	URI="$RET"
@@ -310,6 +325,28 @@
 
 	case "$URI" in
 	ftp|http)
+		# Warty change: Automatically detect mirror (See: #296)
+		promptpri="critical"
+		if [ -e $TMPFILE ]; then
+			# Check if we autodetected a mirror
+			MIRROR="`cat "$TMPFILE" | grep "^Mirror: " | awk '{print $2}'`"
+			if [ "x$MIRROR" != "x" ]; then
+				# This compare the mirror with the official list.
+				# if it is an official mirror it is safe not to ask anything
+				# otherwise we will ask.
+				if [ "`mirror_dir $URI $MIRROR`" ]; then
+					promptpri="medium"
+					db_set apt-setup/hostname "$MIRROR"
+					db_set apt-setup/directory "`mirror_dir $URI $MIRROR`"
+				fi
+			fi
+		fi
+
+	    # Warty change: skip questions if we autodetected (See: #353)
+	    # NOTE: 4 spaces ident to left. I know it's hugly but it makes
+	    #       things easier to merge later on
+	    if [ "$promptpri" = "critical" ]; then
+
 		# Ask them which country they're in.
 		db_subst apt-setup/country countries "`country_list $URI`"
 		db_fget apt-setup/country seen
@@ -377,13 +414,15 @@
 			db_endblock
 			db_go || continue
 		fi
+	    fi
 
 		# Ask about a proxy if no proxy is yet defined.
 		if [ "$URI" = "http" ] && [ -z "$http_proxy" ]; then
 			if [ ! -e "$APTETC/apt.conf" ] || \
 			   ! grep -iq 'Acquire::http::Proxy' $APTETC/apt.conf; then
 				db_fset mirror/http/proxy seen false
-				db_input high mirror/http/proxy || true
+				# Warty change: lower priority if we are autodetecting (See: #353)
+				db_input $promptpri mirror/http/proxy || true
 				db_go || continue
 			fi
 		fi
diff -Naurd base-config-2.35/lib/menu/apt-setup base-config-2.35ubuntu14/lib/menu/apt-setup
--- base-config-2.35/lib/menu/apt-setup	2004-04-19 05:32:24.000000000 +0200
+++ base-config-2.35ubuntu14/lib/menu/apt-setup	2004-07-23 10:35:05.000000000 +0200
@@ -6,8 +6,31 @@
 # no longer br true; debootstrap generates a pretty decent sources.list).
 # Anyway apt-setup generates a better one. Touch the file in any case, because
 # apt-setup requires it exist.
+
+export TMPFILE="$TMPDIR/.apt-src-info.$$"
+
 touch /etc/apt/sources.list
 if [ "$1" = "new" ]; then
+	# Warty change: Attempt to guess the uri type from d-i first stage (See: #296 #353 #355)
+	line="`grep -v "^#" /etc/apt/sources.list | grep "^deb " | head -n 1`"
+	uritype="`echo "$line" | sed -e 's/deb\ //g' -e 's/:.*//g'`"
+	# if uritype is unknow, we need to tell it to apt-setup that will prompt with higher priority
+	case "$uritype" in
+		http|ftp)
+			url="`echo $line | sed -e 's/.*http\:\/\///' -e 's/\/.*//' -e 's/\ .*//'`"
+		;;
+		cdrom|file)
+			# cdrom install from d-i is a special case
+			if [ "`echo "$line" | grep "///cdrom"`" ]; then
+				uritype="cdrom"
+			fi
+		;;
+		*)
+			uritype="unknown"
+		;;
+	esac
+	echo "Uritype: $uritype" > "$TMPFILE"
+	if [ "x$url" != "x" ]; then echo "Mirror: $url" >> "$TMPFILE"; fi
 	sed 's/^\([^#]\)/#\1/' /etc/apt/sources.list > /etc/apt/sources.list.new
 	mv -f /etc/apt/sources.list.new /etc/apt/sources.list
 fi
@@ -15,6 +38,9 @@
 # Probe for cd's in the drive prior to setting up apt.
 apt-setup probe
 
+# Clean after us (in an ideal world it would be .$$)
+rm -f "$TMPDIR/.apt-src-info.*"
+
 clear
 
 # Update available file; tasksel and dselect need it later.

