This allows debootstrap to work on non-debian-based live boot instances that
don't have binutils installed.

Example: Arch Linux LiveCD
---
 functions | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/functions b/functions
index 4e3955a..bbb1d41 100644
--- a/functions
+++ b/functions
@@ -785,7 +785,7 @@ get_debs () {
 
 ################################################################ extraction
 
-EXTRACTORS_SUPPORTED="dpkg-deb ar"
+EXTRACTORS_SUPPORTED="dpkg-deb ar bsdtar"
 
 # Native dpkg-deb based extractors
 extract_dpkg_deb_field () {
@@ -829,6 +829,33 @@ extract_ar_deb_data () {
        fi
 }
 
+extract_bsdtar_deb_field () {
+       local pkg="$1"
+       local field="$2"
+
+       bsdtar -O -xf "$pkg" control.tar.gz | zcat |
+           bsdtar -O -xf - control ./control 2>/dev/null |
+           grep -i "^$field:" | sed -e 's/[^:]*: *//' | head -n 1
+}
+
+extract_bsdtar_deb_data () {
+       local pkg="$1"
+       local tarball=$(bsdtar tf "$pkg" | grep "^data.tar.[bgx]z")
+
+       case "$tarball" in
+               data.tar.gz) cat_cmd=zcat ;;
+               data.tar.bz2) cat_cmd=bzcat ;;
+               data.tar.xz) cat_cmd=xzcat ;;
+               *) error 1 UNKNOWNDATACOMP "Unknown compression type for %s in 
%s" "$tarball" "$pkg" ;;
+       esac
+
+       if type $cat_cmd >/dev/null 2>&1; then
+               bsdtar -O -xf "$pkg" "$tarball" | $cat_cmd | bsdtar -xf -
+       else
+               error 1 UNPACKCMDUNVL "Extracting %s requires the %s command, 
which is not available" "$pkg" "$cat_cmd"
+       fi
+}
+
 valid_extractor () {
        local extractor="$1"
 
@@ -848,8 +875,10 @@ choose_extractor () {
                extractor="$EXTRACTOR_OVERRIDE"
        elif type dpkg-deb >/dev/null 2>&1; then
                extractor="dpkg-deb"
-       else
+       elif type ar >/dev/null 2>&1; then
                extractor="ar"
+       else
+               extractor="bsdtar"
        fi
 
        info CHOSENEXTRACTOR "Chosen extractor for .deb packages: %s" 
"$extractor"
@@ -862,6 +891,10 @@ choose_extractor () {
                extract_deb_field () { extract_ar_deb_field "$@"; }
                extract_deb_data () { extract_ar_deb_data "$@"; }
                ;;
+       bsdtar)
+               extract_deb_field () { extract_bsdtar_deb_field "$@"; }
+               extract_deb_data () { extract_bsdtar_deb_data "$@"; }
+               ;;
        esac
 }
 
-- 
1.9.2


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]
Archive: 
https://lists.debian.org/[email protected]

Reply via email to