5 # Author : Chris Koeritz
6 # Rights : Copyright (C) 2012-$now by Feisty Meow Concerns, Ltd.
8 # This script is free software; you can modify/redistribute it under the terms
9 # of the GNU General Public License. [ http://www.gnu.org/licenses/gpl.html ]
10 # Feel free to send updates to: [ fred@gruntose.com ]
13 # An arbitrary format archive unpacker, although really we are mainly supporting
14 # tar and zip currently, including compressed formats.
16 unpack_file="$1"; shift
17 if [ -z "$unpack_file" ]; then
18 echo "This script takes one archive name (in .tar.gz, .zip, etc. formats) and"
19 echo "unpacks the archive with the appropriate tool."
22 if [ ! -f "$unpack_file" ]; then
23 echo "The file specified for unpacking cannot be located: $unpack_file"
26 unpack_dir="$1"; shift
27 if [ -z "$unpack_dir" ]; then
28 unpack_dir=$(echo unpacked_$(basename $unpack_file) | sed -e 's/^\([^\.]*\)\..*/\1/')
31 if [ ! -d "$unpack_dir" ]; then
34 echo "Could not create the unpacking directory: $unpack_dir"
39 # save where we started out.
40 ORIGINATING_FOLDER="$( \cd "$(\dirname "$0")" && \pwd )"
42 pushd "$unpack_dir" &>/dev/null
44 if [ ! -f "$unpack_file" ]; then
45 # we're assuming we left it behind in our previous directory.
46 unpack_file="$ORIGINATING_FOLDER/$unpack_file"
47 if [ ! -f "$unpack_file" ]; then
48 echo "Could not find file to unpack after shifting directories. Sorry."
49 echo "Tried to locate it as: $unpack_file"
54 if [[ $unpack_file =~ .*\.tar\.gz \
55 || $unpack_file =~ .*\.tar\.bz2 \
56 || $unpack_file =~ .*\.tgz ]]; then
58 elif [[ $unpack_file =~ .*\.zip ]]; then
63 if [ $save_err -ne 0 ]; then
64 echo "There was a failure reported while unpacking: $unpack_file"
65 echo "into the directory: $unpack_dir"
69 echo "Unpacked file $(basename $unpack_file) into folder: $unpack_dir"