Commit 8d4cf26c authored by Otavio Salvador's avatar Otavio Salvador

* Refactor deb extractors into two new functions.

* Use dpkg-deb if available instead of ar (closes: #557296).
* Add an --extractor option to override the automatic extractor selection.

r61537
parent d48c8e45
debootstrap (1.0.21) UNRELEASED; urgency=low
[ Otavio Salvador ]
* Apply patch from Clint Adams <schizo@debian.org> to add support for
gz/bz2/xz data.tar (closes: #458663).
[ Guillem Jover ]
* Refactor deb extractors into two new functions.
* Use dpkg-deb if available instead of ar (closes: #557296).
* Add an --extractor option to override the automatic extractor selection.
-- Otavio Salvador <otavio@debian.org> Mon, 16 Nov 2009 15:20:09 -0200
debootstrap (1.0.20) unstable; urgency=low
......
......@@ -9,7 +9,7 @@ Vcs-Svn: svn://svn.debian.org/d-i/trunk/packages/debootstrap
Package: debootstrap
Architecture: all
Depends: wget, binutils
Depends: wget
Recommends: gnupg
Description: Bootstrap a basic Debian system
debootstrap is used to create a Debian base system from scratch,
......
......@@ -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"
......@@ -517,6 +537,8 @@ if am_doing_phase maketarball; then
fi
if am_doing_phase first_stage; then
choose_extractor
# first stage sets up the chroot -- no calls should be made to
# "chroot $TARGET" here; but they should be possible by the time it's
# finished
......
......@@ -717,27 +717,95 @@ get_debs () {
################################################################ extraction
EXTRACTORS_SUPPORTED="dpkg-deb ar"
# Native dpkg-deb based extractors
extract_dpkg_deb_field () {
local pkg="$1"
local field="$2"
dpkg-deb -f "$pkg" "$field"
}
extract_dpkg_deb_data () {
local pkg="$1"
dpkg-deb --fsys-tarfile "$pkg" | tar -xf -
}
# Raw .deb extractors
extract_ar_deb_field () {
local pkg="$1"
local field="$2"
ar -p "$pkg" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i "^$field:" | sed -e 's/[^:]*: *//' | head -n 1
}
extract_ar_deb_data () {
local pkg="$1"
local tarball=$(ar -t "$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
ar -p "$pkg" data.tar.gz | $cat_cmd | tar -xf -
else
error 1 UNPACKCMDUNVL "The $cat_cmd is not available on the system"
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 [ -n "$EXTRACTOR_OVERRIDE" ]; then
extractor="$EXTRACTOR_OVERRIDE"
elif type dpkg-deb >/dev/null 2>&1; then
extractor="dpkg-deb"
else
extractor="ar"
fi
info CHOSENEXTRACTOR "Chosen extractor for .deb packages: %s" "$extractor"
case "$extractor" in
dpkg-deb)
extract_deb_field () { extract_dpkg_deb_field "$@"; }
extract_deb_data () { extract_dpkg_deb_data "$@"; }
;;
ar)
extract_deb_field () { extract_ar_deb_field "$@"; }
extract_deb_data () { extract_ar_deb_data "$@"; }
;;
esac
}
extract () { (
cd "$TARGET"
local p=0 tarball cat_cmd
local p=0 cat_cmd
for pkg in $(debfor "$@"); do
p="$(($p + 1))"
progress "$p" "$#" EXTRACTPKGS "Extracting packages"
packagename="$(echo "$pkg" | sed 's,^.*/,,;s,_.*$,,')"
info EXTRACTING "Extracting %s..." "$packagename"
tarball=$(ar -t "./$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
ar -p "./$pkg" data.tar.gz | $cat_cmd | tar -xf -
else
error 1 UNPACKCMDUNVL "The $cat_cmd is not available on the system"
fi
extract_deb_data "./$pkg"
done
); }
......
......@@ -43,11 +43,7 @@ first_stage_install () {
x_feign_install () {
local pkg=$1
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -111,11 +111,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -72,11 +72,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -77,11 +77,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -59,11 +59,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -97,11 +97,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -72,11 +72,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -49,11 +49,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -56,11 +56,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -66,11 +66,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -66,11 +66,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -66,11 +66,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -70,11 +70,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -66,11 +66,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -58,11 +58,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
......@@ -66,11 +66,7 @@ first_stage_install () {
x_feign_install () {
local pkg="$1"
local deb="$(debfor $pkg)"
local ver="$(
ar -p "$TARGET/$deb" control.tar.gz | zcat |
tar -O -xf - control ./control 2>/dev/null |
grep -i ^Version: | sed -e 's/[^:]*: *//' | head -n 1
)"
local ver="$(extract_deb_field "$TARGET/$deb" Version)"
mkdir -p "$TARGET/var/lib/dpkg/info"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment