From da12bc4babc06a03a41ef75626fd47e2d2891048 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Fri, 28 Sep 2012 11:35:55 -0400 Subject: [PATCH] new script for listing out archives. --- scripts/archival/listarch.sh | 55 ++++++++++++++++++++++++++++++++++++ scripts/archival/unpack.sh | 48 +++++++++++++++---------------- 2 files changed, 79 insertions(+), 24 deletions(-) create mode 100644 scripts/archival/listarch.sh diff --git a/scripts/archival/listarch.sh b/scripts/archival/listarch.sh new file mode 100644 index 00000000..6c621611 --- /dev/null +++ b/scripts/archival/listarch.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +############## +# Name : listarch +# Author : Chris Koeritz +# Rights : Copyright (C) 2012-$now by Feisty Meow Concerns, Ltd. +############## +# This script is free software; you can modify/redistribute it under the terms +# of the GNU General Public License. [ http://www.gnu.org/licenses/gpl.html ] +# Feel free to send updates to: [ fred@gruntose.com ] +############## +# +# An arbitrary format archive lister, although really we are mainly supporting +# tar and zip currently, including compressed formats. + +archive_file="$1"; shift +if [ -z "$archive_file" ]; then + echo "This script takes one archive name (in .tar.gz, .zip, etc. formats) and" + echo "lists the archive with the appropriate tool." + exit 1 +fi +if [ ! -f "$archive_file" ]; then + echo "The file specified for listing cannot be located: $archive_file" + exit 1 +fi + +# save where we started out. +ORIGINATING_FOLDER="$( \pwd )" + +if [ ! -f "$archive_file" ]; then + # we're assuming we left it behind in our previous directory. + archive_file="$ORIGINATING_FOLDER/$archive_file" + if [ ! -f "$archive_file" ]; then + echo "Could not find file to unpack after shifting directories. Sorry." + echo "Tried to locate it as: $archive_file" + exit 1 + fi +fi + +if [[ $archive_file =~ .*\.tar$ \ + || $archive_file =~ .*\.tar\.gz$ \ + || $archive_file =~ .*\.tar\.bz2$ \ + || $archive_file =~ .*\.iar$ \ + || $archive_file =~ .*\.oar$ \ + || $archive_file =~ .*\.tgz$ \ + ]]; then + tar -tf $archive_file +elif [[ $archive_file =~ .*\.zip$ \ + || $archive_file =~ .*\.epub$ \ + || $archive_file =~ .*\.odt$ \ + || $archive_file =~ .*\.jar$ \ + || $archive_file =~ .*\.war$ \ + ]]; then + unzip -v $archive_file +fi diff --git a/scripts/archival/unpack.sh b/scripts/archival/unpack.sh index 4fbe1820..103ec193 100644 --- a/scripts/archival/unpack.sh +++ b/scripts/archival/unpack.sh @@ -13,19 +13,19 @@ # An arbitrary format archive unpacker, although really we are mainly supporting # tar and zip currently, including compressed formats. -unpack_file="$1"; shift -if [ -z "$unpack_file" ]; then +archive_file="$1"; shift +if [ -z "$archive_file" ]; then echo "This script takes one archive name (in .tar.gz, .zip, etc. formats) and" echo "unpacks the archive with the appropriate tool." exit 1 fi -if [ ! -f "$unpack_file" ]; then - echo "The file specified for unpacking cannot be located: $unpack_file" +if [ ! -f "$archive_file" ]; then + echo "The file specified for unpacking cannot be located: $archive_file" exit 1 fi unpack_dir="$1"; shift if [ -z "$unpack_dir" ]; then - unpack_dir=$(echo unpacked_$(basename $unpack_file) | sed -e 's/^\([^\.]*\)\..*/\1/') + unpack_dir=$(echo unpacked_$(basename $archive_file) | sed -e 's/^\([^\.]*\)\..*/\1/') fi if [ ! -d "$unpack_dir" ]; then @@ -41,42 +41,42 @@ ORIGINATING_FOLDER="$( \pwd )" pushd "$unpack_dir" &>/dev/null -if [ ! -f "$unpack_file" ]; then +if [ ! -f "$archive_file" ]; then # we're assuming we left it behind in our previous directory. - unpack_file="$ORIGINATING_FOLDER/$unpack_file" - if [ ! -f "$unpack_file" ]; then + archive_file="$ORIGINATING_FOLDER/$archive_file" + if [ ! -f "$archive_file" ]; then echo "Could not find file to unpack after shifting directories. Sorry." - echo "Tried to locate it as: $unpack_file" + echo "Tried to locate it as: $archive_file" exit 1 fi fi -if [[ $unpack_file =~ .*\.tar$ \ - || $unpack_file =~ .*\.tar\.gz$ \ - || $unpack_file =~ .*\.tar\.bz2$ \ - || $unpack_file =~ .*\.iar$ \ - || $unpack_file =~ .*\.oar$ \ - || $unpack_file =~ .*\.tgz$ \ +if [[ $archive_file =~ .*\.tar$ \ + || $archive_file =~ .*\.tar\.gz$ \ + || $archive_file =~ .*\.tar\.bz2$ \ + || $archive_file =~ .*\.iar$ \ + || $archive_file =~ .*\.oar$ \ + || $archive_file =~ .*\.tgz$ \ ]]; then - tar -xf $unpack_file &>/dev/null -elif [[ $unpack_file =~ .*\.zip$ \ - || $unpack_file =~ .*\.epub$ \ - || $unpack_file =~ .*\.odt$ \ - || $unpack_file =~ .*\.jar$ \ - || $unpack_file =~ .*\.war$ \ + tar -xf $archive_file &>/dev/null +elif [[ $archive_file =~ .*\.zip$ \ + || $archive_file =~ .*\.epub$ \ + || $archive_file =~ .*\.odt$ \ + || $archive_file =~ .*\.jar$ \ + || $archive_file =~ .*\.war$ \ ]]; then - unzip $unpack_file &>/dev/null + unzip $archive_file &>/dev/null fi save_err=$? popd &>/dev/null if [ $save_err -ne 0 ]; then - echo "There was a failure reported while unpacking: $unpack_file" + echo "There was a failure reported while unpacking: $archive_file" echo "into the directory: $unpack_dir" exit 1 else - echo "Unpacked file $(basename $unpack_file) into folder: $unpack_dir" + echo "Unpacked file $(basename $archive_file) into folder: $unpack_dir" fi -- 2.34.1