From cdee8b86523d0c381c9615761c0d54730a4a6448 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 15 Aug 2011 15:43:18 -0400 Subject: Search PATH for programs, rather than checking hardcoded locations. Generally a good idea, but specifically FreeBSD does not keep gunzip in /bin/ --- debian/changelog | 1 + debootstrap | 11 +++++------ functions | 24 ++++++++++++++++++------ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/debian/changelog b/debian/changelog index 39afeac..72ca0a8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,7 @@ debootstrap (1.0.36) UNRELEASED; urgency=low * Fix support for running debootstrap on a FreeBSD host to create a kFreeBSD chroot or jail. * Clarify "target" in usage message. + * Search PATH for programs, rather than checking hardcoded locations. -- Joey Hess Mon, 15 Aug 2011 14:14:29 -0400 diff --git a/debootstrap b/debootstrap index a0d54b8..278ed64 100755 --- a/debootstrap +++ b/debootstrap @@ -391,10 +391,10 @@ fi ########################################################################### -if [ -x /usr/bin/dpkg ] && \ - /usr/bin/dpkg --print-architecture >/dev/null 2>&1; then +if in_path dpkg && \ + dpkg --print-architecture >/dev/null 2>&1; then HOST_ARCH=`/usr/bin/dpkg --print-architecture` -elif type udpkg >/dev/null 2>&1 && \ +elif in_path udpkg && \ udpkg --print-architecture >/dev/null 2>&1; then HOST_ARCH=`/usr/bin/udpkg --print-architecture` elif [ -e $DEBOOTSTRAP_DIR/arch ]; then @@ -447,8 +447,7 @@ fi if [ -z "$SHA_SIZE" ]; then SHA_SIZE=256 fi -if ! [ -x "/usr/bin/sha${SHA_SIZE}sum" ] && \ - ! [ -x "/bin/sha${SHA_SIZE}sum" ]; then +if ! in_path "sha${SHA_SIZE}sum"; then SHA_SIZE=1 fi DEBOOTSTRAP_CHECKSUM_FIELD="SHA$SHA_SIZE" @@ -456,7 +455,7 @@ DEBOOTSTRAP_CHECKSUM_FIELD="SHA$SHA_SIZE" export ARCH SUITE TARGET CHROOT_CMD SHA_SIZE DEBOOTSTRAP_CHECKSUM_FIELD if am_doing_phase first_stage second_stage; then - if [ -x /usr/bin/id ] && [ `id -u` -ne 0 ]; then + if in_path id && [ `id -u` -ne 0 ]; then error 1 NEEDROOT "debootstrap can only run as root" fi # Ensure that we can create working devices and executables on the target. diff --git a/functions b/functions index d33939e..4399707 100644 --- a/functions +++ b/functions @@ -524,9 +524,9 @@ download_release_indices () { local i= if [ "$normi" != "" ]; then i="$normi" - elif [ -x /bin/bunzip2 ] && [ "$bz2i" != "" ]; then + elif in_path bunzip2 && [ "$bz2i" != "" ]; then i="$bz2i" - elif [ -x /bin/gunzip ] && [ "$gzi" != "" ]; then + elif in_path gunzip && [ "$gzi" != "" ]; then i="$gzi" fi if [ "$i" != "" ]; then @@ -552,11 +552,11 @@ download_release_indices () { ext="$ext $normi ." i="$normi" fi - if [ -x /bin/bunzip2 ] && [ "$bz2i" != "" ]; then + if in_path bunzip2 && [ "$bz2i" != "" ]; then ext="$ext $bz2i bz2" i="${i:-$bz2i}" fi - if [ -x /bin/gunzip ] && [ "$gzi" != "" ]; then + if in_path gunzip && [ "$gzi" != "" ]; then ext="$ext $gzi gz" i="${i:-$gzi}" fi @@ -690,7 +690,7 @@ download_main_indices () { for c in $COMPONENTS; do local path="dists/$SUITE/$c/binary-$ARCH/Packages" local pkgdest="$TARGET/$($DLDEST pkg "$SUITE" "$c" "$ARCH" "$m" "$path")" - if [ -x /bin/gunzip ] && get "$m/${path}.gz" "${pkgdest}.gz"; then + if in_path gunzip && get "$m/${path}.gz" "${pkgdest}.gz"; then rm -f "$pkgdest" gunzip "$pkgdest.gz" elif get "$m/$path" "$pkgdest"; then @@ -1028,7 +1028,7 @@ setup_dselect_method () { # For the debootstrap udeb, pkgdetails is provided by the bootstrap-base # udeb, so the pkgdetails API needs to be kept in sync with that. -if [ -x /usr/bin/perl ]; then +if in_path perl; then PKGDETAILS=pkgdetails_perl pkgdetails_field () { @@ -1292,6 +1292,18 @@ on_exit () { N_EXIT_THINGS="$(( $N_EXIT_THINGS + 1 ))" } +in_path () { + IFS=":" _in_path "$1" +} +_in_path () { + for dir in $PATH; do + if [ -x "$dir/$1" ]; then + return 0 + fi + done + return 1 +} + ############################################################## fakechroot tools install_fakechroot_tools () { -- cgit v0.12