First pass at a script that replaces many of the variables, loops and
logic in bsd.pkg.extract.mk. This script "knows" how to extract files depending on their file extension.
This commit is contained in:
parent
93888253ec
commit
348fa15438
1 changed files with 190 additions and 0 deletions
190
mk/scripts/extract
Executable file
190
mk/scripts/extract
Executable file
|
@ -0,0 +1,190 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# $NetBSD: extract,v 1.1 2006/01/20 18:00:45 jlam Exp $
|
||||
#
|
||||
# Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This code is derived from software contributed to The NetBSD Foundation
|
||||
# by Johnny C. Lam.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. All advertising materials mentioning features or use of this software
|
||||
# must display the following acknowledgement:
|
||||
# This product includes software developed by the NetBSD
|
||||
# Foundation, Inc. and its contributors.
|
||||
# 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
######################################################################
|
||||
#
|
||||
# NAME
|
||||
# extract -- extract distfile, regardless of format
|
||||
#
|
||||
# SYNOPSIS
|
||||
# extract [-t tarprog] [-x] distfile [file ...]
|
||||
#
|
||||
# DESCRIPTION
|
||||
# extract will unpack the contents of the named distfile into the
|
||||
# current working directory. If any optional files are specified
|
||||
# then only they will be extracted from the distfile, provided that
|
||||
# the underlying tool supports this ability. If the -x option is
|
||||
# specified, then the optional files are excluded from extraction
|
||||
# instead.
|
||||
#
|
||||
# OPTIONS
|
||||
# -t tarprog This specifies the tool to use to extract tar/ustar
|
||||
# archives, and may be either "tar" or "pax", or the
|
||||
# full path to the program.
|
||||
#
|
||||
# -x This causes the optional files listed on the
|
||||
# command line to be excluded from extraction,
|
||||
# provided the underlying tool supports this
|
||||
# ability.
|
||||
#
|
||||
# ENVIRONMENT
|
||||
# EXTRACT_OPTS_LHA
|
||||
# EXTRACT_OPTS_RAR
|
||||
# EXTRACT_OPTS_PAX
|
||||
# EXTRACT_OPTS_TAR
|
||||
# EXTRACT_OPTS_ZIP
|
||||
# EXTRACT_OPTS_ZOO
|
||||
# These variables set additional arguments passed to the
|
||||
# underlying extraction tool to unpack their respective
|
||||
# archive formats.
|
||||
#
|
||||
######################################################################
|
||||
|
||||
: ${BZCAT:=bzcat}
|
||||
: ${CAT:=cat}
|
||||
: ${ECHO:=echo}
|
||||
: ${GZCAT:=gzcat}
|
||||
: ${LHA:=lha}
|
||||
: ${PAX:=pax}
|
||||
: ${SH:=sh}
|
||||
: ${TAR:=tar}
|
||||
: ${TEST:=test}
|
||||
: ${UNRAR:=unrar}
|
||||
: ${UNZIP:=unzip}
|
||||
: ${UNZOO:=unzoo}
|
||||
|
||||
self="${0##*/}"
|
||||
|
||||
usage() {
|
||||
${ECHO} 1>&2 "usage: $self [-t tarprog] [-x] distfile [file ...]"
|
||||
}
|
||||
|
||||
decompress_cat="${CAT}"
|
||||
exclude=no
|
||||
exclude_flag=
|
||||
extract_using=tar
|
||||
|
||||
# Process optional arguments
|
||||
while ${TEST} $# -gt 0; do
|
||||
case "$1" in
|
||||
-t) extract_using="$1"; shift 2 ;;
|
||||
-x) exclude=yes; shift ;;
|
||||
--) shift; break ;;
|
||||
-*) ${ECHO} 1>&2 "$self: unknown option -- ${1#-}"
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
*) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
case "$extract_using" in
|
||||
/*tar|/*pax) tarprog="$extract_using" ;;
|
||||
*tar) tarprog="${TAR}" ;;
|
||||
*pax) tarprog="${PAX}" ;;
|
||||
esac
|
||||
|
||||
# Process required arguments
|
||||
${TEST} $# -gt 0 || { usage; exit 1; }
|
||||
distfile="$1"; shift
|
||||
|
||||
# Set the command to decompress the file and write the contents to stdout.
|
||||
case "$distfile" in
|
||||
*.gz|*.tgz) decompress_cat="${GZCAT}" ;;
|
||||
*.bz2|*.tbz|*.tbz2) decompress_cat="${BZCAT}" ;;
|
||||
*.Z) decompress_cat="${GZCAT}" ;;
|
||||
esac
|
||||
|
||||
# Main extraction section -- this maps the suffix on the specified distfile
|
||||
# the correct tool and extraction procedure to perform the extraction.
|
||||
#
|
||||
case "$distfile" in
|
||||
*.tar.gz|*.tgz|*_tar.gz|*.tar.bz2|*.tbz|*.tbz2|*.tar.Z|*.tar)
|
||||
case "$extract_using" in
|
||||
*pax)
|
||||
distfile="$1"; shift
|
||||
case "$extract_using" in
|
||||
/*) paxprog="$extract_using" ;;
|
||||
*) paxprog="${PAX}" ;;
|
||||
esac
|
||||
${TEST} "$exclude" = no || exclude_flag="-c"
|
||||
$decompress_cat "$distfile" |
|
||||
$paxprog ${EXTRACT_OPTS_PAX} $exclude_flag -O -r "$@"
|
||||
;;
|
||||
*tar)
|
||||
case "$extract_using" in
|
||||
/*) tarprog="$extract_using" ;;
|
||||
*) tarprog="${TAR}" ;;
|
||||
esac
|
||||
$decompress_cat "$distfile" |
|
||||
$tarprog ${EXTRACT_OPTS_TAR} -xf - "$@"
|
||||
;;
|
||||
*)
|
||||
${ECHO} 1>&2 "$self: unknown tar program: $extract_using"
|
||||
exit 1
|
||||
esac
|
||||
;;
|
||||
*.shar.gz|*.shar.bz2|*.shar.Z|*.shar)
|
||||
$decompress_cat "$distfile" | ${SH}
|
||||
;;
|
||||
*.zip)
|
||||
: ${EXTRACT_OPTS_ZOO=-Laqo}
|
||||
${TEST} "$exclude" = "no" || exclude_flag="-x"
|
||||
${UNZIP} ${EXTRACT_OPTS_ZOO} "$distfile" $exclude_flag "$@"
|
||||
;;
|
||||
*.lha|*.lzh)
|
||||
: ${EXTRACT_OPTS_LHA=q}
|
||||
${LHA} x$extract_options "$distfile" "$@"
|
||||
;;
|
||||
*.Z|*.bz2|*.gz)
|
||||
target="${distfile##*/}"; target="${target%.*}"
|
||||
$decompress_cat "$distfile" > "$target"
|
||||
;;
|
||||
*.zoo)
|
||||
${UNZOO} -x ${EXTRACT_OPTS_ZOO} "$distfile" "$@"
|
||||
;;
|
||||
*.rar)
|
||||
: ${EXTRACT_OPTS_RAR=-inul}
|
||||
${UNRAR} -x ${EXTRACT_OPTS_RAR} "$distfile" "$@"
|
||||
;;
|
||||
*)
|
||||
${ECHO} 1>&2 "$self: unable to extract: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
Loading…
Reference in a new issue