diff options
author | rillig <rillig@pkgsrc.org> | 2006-02-04 18:06:47 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2006-02-04 18:06:47 +0000 |
commit | ca9f69aa7be0db97944e698a70263d98b3bf8a76 (patch) | |
tree | b7da25c846ab40e9240270380438494dd1c160cc /mk/scripts | |
parent | f9c335d67b7e63880b4074ef8e4f4d52c9f6b34d (diff) | |
download | pkgsrc-ca9f69aa7be0db97944e698a70263d98b3bf8a76.tar.gz |
- Added "set -e" at the top of the file to prevent uncontrolled execution.
- Added "set -u" at the top of the file to prevent spelling errors.
- Renamed UNZIP to UNZIP_CMD, since that is used by the rest of pkgsrc.
- Found a singleton use of $extract_options and replaced it with
${EXTRACT_OPTS_LHA}.
- Took the default assignment for TMPDIR out of the block. All other
entries are tools.
- Removed unnecessary variables.
- Make sure that distfile can always be resolved, even if the current
working directory is changed.
- Provide default values for all EXTRACT_OPTS_* variables, as close as
possible to the point where they are used.
- Replaced all "$@" with ${1+"$@"} to avoid errors when no parameters are
given.
- Made the removal of the temporary file for .tar extraction more robust.
Diffstat (limited to 'mk/scripts')
-rwxr-xr-x | mk/scripts/extract | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/mk/scripts/extract b/mk/scripts/extract index f34a0271e4c..0f632218898 100755 --- a/mk/scripts/extract +++ b/mk/scripts/extract @@ -1,6 +1,6 @@ #!/bin/sh # -# $NetBSD: extract,v 1.18 2006/02/03 11:22:12 joerg Exp $ +# $NetBSD: extract,v 1.19 2006/02/04 18:06:47 rillig Exp $ # # Copyright (c) 2006 The NetBSD Foundation, Inc. # All rights reserved. @@ -93,6 +93,9 @@ # ###################################################################### +set -e # exit on errors +set -u # treat undefined variables as errors + : ${BZCAT:=bzcat} : ${CAT:=cat} : ${CP:=cp} @@ -105,19 +108,18 @@ : ${SH:=sh} : ${TAR:=tar} : ${TEST:=test} -: ${TMPDIR:=/tmp} : ${UNRAR:=unrar} -: ${UNZIP:=unzip} +: ${UNZIP_CMD:=unzip} : ${UNZOO:=unzoo} +: ${TMPDIR:=/tmp} + self="${0##*/}" usage() { ${ECHO} 1>&2 "usage: $self [-d dir] [-f format] [-t tarprog] [-X excludefile | -x] distfile [file ...]" } -exitcode=0 -decompress_cat="${CAT}" exclude=no exclude_file= exclude_flag= @@ -158,6 +160,14 @@ fi ${TEST} $# -gt 0 || { usage; exit 1; } distfile="$1"; shift +# Make distfile an absolute path, because we will change the current +# directory soon. +case "$distfile" in +/*) ;; +*) distfile=`exec pwd`/"$distfile" + ;; +esac + # Set the command to decompress the file and write the contents to stdout. case "$distfile" in *.gz|*.tgz|*.z) decompress_cat="${GZCAT}" ;; @@ -202,6 +212,7 @@ case "$format" in tar) case "$extract_using" in *pax) + : ${EXTRACT_OPTS_PAX=} case "$extract_using" in /*) paxprog="$extract_using" ;; *) paxprog="${PAX}" ;; @@ -212,9 +223,10 @@ tar) fi ${TEST} "$exclude" = no || exclude_flag="-c" $decompress_cat "$distfile" | - $paxprog ${EXTRACT_OPTS_PAX} $exclude_flag -O -r "$@" + $paxprog ${EXTRACT_OPTS_PAX} $exclude_flag -O -r ${1+"$@"} ;; *tar) + : ${EXTRACT_OPTS_TAR=} case "$extract_using" in /*) tarprog="$extract_using" ;; *) tarprog="${TAR}" ;; @@ -223,7 +235,8 @@ tar) if ${TEST} "$exclude" = "yes"; then tmpfile="${TMPDIR}/$self.$$" ${RM} -f "$tmpfile" - for i in "$@"; do + trap "\${RM} -f \"\$tmpfile\"" 0 + for i in ${1+"$@"}; do ${ECHO} "$i" >> "$tmpfile" done exclude_file="$tmpfile" @@ -233,9 +246,7 @@ tar) set -- dummy; shift fi $decompress_cat "$distfile" | - $tarprog ${EXTRACT_OPTS_TAR} $exclude_flag -xf - "$@" - exitcode=$? - ${TEST} "$exclude" = "no" || ${RM} -f "$tmpfile" + $tarprog ${EXTRACT_OPTS_TAR} $exclude_flag -xf - ${1+"$@"} ;; *) ${ECHO} 1>&2 "$self: unknown tar program: $extract_using" @@ -253,12 +264,12 @@ zip) if ${TEST} -n "$exclude_file"; then set -- dummy `${CAT} "$exclude_file"`; shift fi - ${UNZIP} ${EXTRACT_OPTS_ZIP} "$distfile" $exclude_flag "$@" + ${UNZIP_CMD} ${EXTRACT_OPTS_ZIP} "$distfile" $exclude_flag ${1+"$@"} ;; lha) : ${EXTRACT_OPTS_LHA=q} - ${LHA} x$extract_options "$distfile" "$@" + ${LHA} x${EXTRACT_OPTS_LHA} "$distfile" ${1+"$@"} ;; compressed) @@ -267,15 +278,17 @@ compressed) ;; zoo) - ${UNZOO} -x ${EXTRACT_OPTS_ZOO} "$distfile" "$@" + : ${EXTRACT_OPTS_ZOO=} + ${UNZOO} -x ${EXTRACT_OPTS_ZOO} "$distfile" ${1+"$@"} ;; rar) : ${EXTRACT_OPTS_RAR=-inul} - ${UNRAR} x ${EXTRACT_OPTS_RAR} "$distfile" "$@" + ${UNRAR} x ${EXTRACT_OPTS_RAR} "$distfile" ${1+"$@"} ;; jre-bin) + : ${EXTRACT_OPTS_BIN=} ${ECHO} yes | "$distfile" ${EXTRACT_OPTS_BIN} >/dev/null ;; @@ -290,4 +303,4 @@ none) ;; esac -exit $exitcode +exit 0 |