From 6eca98330e91eda672c5fa89610a423deda64798 Mon Sep 17 00:00:00 2001
Package: debootstrap
Version: 1.0.21
From: Guillem Jover <guillem@hadrons.org>
Date: Fri, 27 Nov 2009 19:00:39 +0100
Status: applied
Subject: [PATCH 3/3] Add an --extractor option to override the automatic extractor selection

---
 debootstrap |   20 ++++++++++++++++++++
 functions   |   18 +++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/debootstrap b/debootstrap
index 54ae85d..171a5ef 100755
--- a/debootstrap
+++ b/debootstrap
@@ -90,6 +90,8 @@ usage()
                              Run second stage in a subdirectory instead of root
                                (can be used to create a foreign chroot)
                                (requires --second-stage)
+      --extractor=TYPE       override automatic .deb extractor selection
+                               (supported: $EXTRACTORS_SUPPORTED)
       --boot-floppies        used for internal purposes by boot-floppies
       --debian-installer     used for internal purposes by debian-installer
 EOF
@@ -201,6 +203,24 @@ if [ $# != 0 ] ; then
 			error 1 NEEDARG "option requires an argument %s" "$1"
 		fi
 		;;
+	    --extractor|--extractor=?*)
+		if [ "$1" = "--extractor" -a -n "$2" ] ; then
+			EXTRACTOR_OVERRIDE="$2"
+			shift 2
+		elif [ "$1" != "${1#--extractor=}" ]; then
+			EXTRACTOR_OVERRIDE="${1#--extractor=}"
+			shift
+		else
+			error 1 NEEDARG "option requires an argument %s" "$1"
+		fi
+		if valid_extractor "$EXTRACTOR_OVERRIDE"; then
+			if ! type "$EXTRACTOR_OVERRIDE" >/dev/null 2>&1; then
+				error 1 MISSINGEXTRACTOR "The selected extractor cannot be found: %s" "$EXTRACTOR_OVERRIDE"
+			fi
+		else
+			error 1 BADEXTRACTOR "%s: unknown extractor" "$EXTRACTOR_OVERRIDE"
+		fi
+		;;
 	    --unpack-tarball|--unpack-tarball=?*)
 		if [ "$1" = "--unpack-tarball" -a -n "$2" ] ; then
 			UNPACK_TARBALL="$2"
diff --git a/functions b/functions
index e2a9f73..33b5a46 100644
--- a/functions
+++ b/functions
@@ -717,6 +717,8 @@ get_debs () {
 
 ################################################################ extraction
 
+EXTRACTORS_SUPPORTED="dpkg-deb ar"
+
 # Native dpkg-deb based extractors
 extract_dpkg_deb_field () {
 	local pkg="$1"
@@ -759,10 +761,24 @@ extract_ar_deb_data () {
 	fi
 }
 
+valid_extractor () {
+	local extractor="$1"
+
+	for E in $EXTRACTORS_SUPPORTED; do
+		if [ "$extractor" = "$E" ]; then
+			return 0
+		fi
+	done
+
+	return 1
+}
+
 choose_extractor () {
 	local extractor
 
-	if type dpkg-deb >/dev/null 2>&1; then
+	if [ -n "$EXTRACTOR_OVERRIDE" ]; then
+		extractor="$EXTRACTOR_OVERRIDE"
+	elif type dpkg-deb >/dev/null 2>&1; then
 		extractor="dpkg-deb"
 	else
 		extractor="ar"
-- 
1.6.5.3

