--- debian/iso-scan.postinst	2005-12-07 12:06:46.370147200 +0100
+++ debian/iso-scan.postinst	2005-12-14 10:28:38.456891200 +0100
@@ -83,6 +83,31 @@
 	fi
 }
 
+# compare two lists and return those entries in the second list
+# that are not in the first list
+compare_lists () {
+	first=$1
+	second=$2
+
+  # for each item in the second list, check if it's in the first
+	for sec in $second; do
+		seen=0;
+		
+		for fir in $first; do
+			if [ $sec == $fir ]; then
+				# this device is in the first list
+				seen=1;
+				break;
+			fi
+		done
+		
+		if [ $seen == 0 ]; then
+		  # this device is not in the first list, "return" it
+			echo $sec;
+		fi
+	done
+}
+
 # Try to unmount anything that was previously mounted.
 umount /cdrom 2>/dev/null || true
 umount /hd-media 2>/dev/null || true
@@ -90,16 +115,6 @@
 # Hopefully this will find the drive.
 hw-detect iso-scan/detect_progress_title || true
 
-# Find all block devices, and get a count of them, for use in progress bar.
-DEVS=$(block_devices)
-DEV_COUNT=0
-for dev in $DEVS; do
-	DEV_COUNT=$(expr $DEV_COUNT + 1)
-done
-
-log "Searching for Debian installation media..."
-db_progress START 0 $DEV_COUNT iso-scan/progress_title
-
 # Load up every filesystem known to man. The drive could have anything.
 FS="ext2 ext3 reiserfs fat vfat xfs iso9660 hfs hfsplus ntfs"
 for fs in $FS; do
@@ -110,8 +125,45 @@
 mkdir /cdrom 2>/dev/null || true
 mkdir /hd-media 2>/dev/null || true
 
+log "Searching for Debian installation media..."
 log "First pass: Look for ISOs near top-level of each filesystem."
-for dev in $DEVS; do
+
+
+# pseudo code:
+# Do the following two times, to accomodate devices that need some time to initialize, like USB devices
+# 1) Try to find block devices we haven't seen yet
+# 2) Count the devices we need to search, make a progress bar
+# 3) Try every device:
+#   a) Try to mount
+#   b) Try to find an ISO in the top of the filesystem
+#   c) If found, find out if it's a Debian ISO
+#   d) If so, we are done
+
+for i in 1 2; do
+
+	# Find all block devices
+	DEVSFOUND=$(block_devices)
+	
+	# Filter those we have seen
+	# DEVS now holds all devices we yet need to check
+	if [ -z $SEEN ]; then
+		DEVS=$DEVSFOUND
+	else
+		DEVS=$(compare_lists $SEEN $DEVSFOUND)
+	fi
+
+	# Get a count of new block devices, for use in progress bar.
+	DEV_COUNT=0
+	for dev in $DEVS; do
+		DEV_COUNT=$(expr $DEV_COUNT + 1)
+	done
+
+	db_progress START 0 $DEV_COUNT iso-scan/progress_title
+
+  # Process devices we haven't processed yet
+	for dev in $DEVS; do
+	
+		# Mount device
 	if ! mount_device $dev; then
 		log "Waiting for $dev to possibly get ready.."
 		sleep 3
@@ -150,6 +202,10 @@
 	try_iso $dev $dev
 
 	db_progress STEP 1
+	done
+	
+	# wait for more devices to possibly appear
+	sleep 2;
 done
 
 db_progress STOP
