#!/bin/sh # # wrapper around a lot of packers # # Copyright (c) 2003 Mathias Gumz # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ACTION="unpack" CMDLINE="" GUNZIP="gunzip" BUNZIP2="bunzip2" TAR="tar" UNACE="unace" UNRAR="unrar" UNZIP="unzip" rec() { suf=${1##*.} case "$suf" in tar | tgz | tbz | gz | bz2 | zip | ace | rar | z ) tmp=`rec \${1%.*}` [ -n "$tmp" ] && suf=$tmp.$suf echo $suf ;; esac } unpack() { case "$2" in gz | z) CMDLINE="$GUNZIP $1";; bz2) CMDLINE="$BUNZIP2 $1";; rar) CMDLINE="$UNRAR x $1";; zip) CMDLINE="$UNZIP $1";; tar.bz2 | tbz | tbz2) CMDLINE="$TAR xvfj $1";; tar.gz | tgz) CMDLINE="$TAR xvfz $1";; ace) CMDLINE="$UNACE x $1";; *) echo "unrecognized format for [$1]" exit 1 ;; esac } list() { case "$2" in tar ) CMDLINE="$TAR tvf $1";; tar.bz2 | tbz | tbz2 ) CMDLINE="$TAR tvfj $1";; tar.gz | tgz ) CMDLINE="$TAR tvfz $1";; zip ) CMDLINE="$UNZIP -l $1";; rar ) CMDLINE="$UNRAR l $1";; ace ) CMDLINE="$UNACE l $1";; *) echo "unrecognized format for [$1]" exit 1 ;; esac } display_help() { cat << EOF NAME unpacksh - wrapper around a number of unpackers SYNOPSIS unpacksh [-h] [-t] [-l] file1 file2 file3 ... OPTIONS -h display help -l list content -t test run (recog format) AUTHOR mathias gumz EOF } while getopts ":htl" opts do case "$opts" in h)display_help;exit 0;; t)ACTION="test";; l)ACTION="list";; esac done case "$ACTION" in test ) for file in $@ do if [ -f $file ]; then f=`echo $file | tr [:upper:] [:lower:]` suf=`rec \$f` [ -n "$suf" ] && unpack $file $suf echo "$file => $suf | $CMDLINE" fi done ;; unpack ) for file in $@ do if [ -f $file ]; then f=`echo $file | tr [:upper:] [:lower:]` suf=`rec \$f` [ -n $suf ] && unpack $file $suf eval $CMDLINE fi done ;; list ) for file in $@ do if [ -f $file ]; then f=`echo $file | tr [:upper:] [:lower:]` suf=`rec \$f` [ -n $suf ] && list $file $suf eval $CMDLINE fi done ;; esac