pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/mk/scripts - Added "set -e" at the top of the file to ...
details: https://anonhg.NetBSD.org/pkgsrc/rev/18cd5f06a4e4
branches: trunk
changeset: 507578:18cd5f06a4e4
user: rillig <rillig%pkgsrc.org@localhost>
date: Sat Feb 04 18:06:47 2006 +0000
description:
- 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:
mk/scripts/extract | 45 +++++++++++++++++++++++++++++----------------
1 files changed, 29 insertions(+), 16 deletions(-)
diffs (142 lines):
diff -r b0bc5a614ddd -r 18cd5f06a4e4 mk/scripts/extract
--- a/mk/scripts/extract Sat Feb 04 18:03:57 2006 +0000
+++ b/mk/scripts/extract Sat Feb 04 18:06:47 2006 +0000
@@ -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,10 +108,11 @@
: ${SH:=sh}
: ${TAR:=tar}
: ${TEST:=test}
+: ${UNRAR:=unrar}
+: ${UNZIP_CMD:=unzip}
+: ${UNZOO:=unzoo}
+
: ${TMPDIR:=/tmp}
-: ${UNRAR:=unrar}
-: ${UNZIP:=unzip}
-: ${UNZOO:=unzoo}
self="${0##*/}"
@@ -116,8 +120,6 @@
${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 @@
${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 @@
tar)
case "$extract_using" in
*pax)
+ : ${EXTRACT_OPTS_PAX=}
case "$extract_using" in
/*) paxprog="$extract_using" ;;
*) paxprog="${PAX}" ;;
@@ -212,9 +223,10 @@
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 @@
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 @@
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 @@
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 @@
;;
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 @@
;;
esac
-exit $exitcode
+exit 0
Home |
Main Index |
Thread Index |
Old Index