nice new tool to show version of feisty meow
[feisty_meow.git] / scripts / archival / test_arch.sh
1 #!/bin/bash
2
3 ##############
4 # Name   : test_arch
5 # Author : Chris Koeritz
6 # Rights : Copyright (C) 2012-$now by Feisty Meow Concerns, Ltd.
7 ##############
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 ]
11 ##############
12 #
13 # An arbitrary format archive tester, although really we are mainly supporting
14 # tar and zip currently, including compressed formats.
15
16 archive_file="$1"; shift
17 if [ -z "$archive_file" ]; then
18   echo "This script takes one archive name (in .tar.gz, .zip, etc. formats) and"
19   echo "tests the archive with the appropriate tool."
20   exit 1
21 fi
22 if [ ! -f "$archive_file" ]; then
23   echo "The file specified cannot be located: $archive_file"
24   exit 1
25 fi
26
27 # save where we started out.
28 ORIGINATING_FOLDER="$( \pwd )"
29
30 if [ ! -f "$archive_file" ]; then
31   # we're assuming we left it behind in our previous directory.
32   archive_file="$ORIGINATING_FOLDER/$archive_file"
33   if [ ! -f "$archive_file" ]; then
34     echo "Could not find file to unpack after shifting directories.  Sorry."
35     echo "Tried to locate it as: $archive_file"
36     exit 1
37   fi
38 fi
39
40 save_err=1
41 if [[ $archive_file =~ .*\.tar$ \
42     || $archive_file =~ .*\.tar\.gz$ \
43     || $archive_file =~ .*\.tar\.bz2$ \
44     || $archive_file =~ .*\.iar$ \
45     || $archive_file =~ .*\.oar$ \
46     || $archive_file =~ .*\.tgz$ \
47     || $archive_file =~ .*\.ova$ \
48     || $archive_file =~ .*\.snarf$ \
49     ]]; then
50   tar -tf $archive_file &>/dev/null
51   save_err=$?
52 elif [[ $archive_file =~ .*\.zip$ \
53     || $archive_file =~ .*\.epub$ \
54     || $archive_file =~ .*\.odt$ \
55     || $archive_file =~ .*\.jar$ \
56     || $archive_file =~ .*\.war$ \
57     ]]; then
58   unzip -t $archive_file &>/dev/null
59   save_err=$?
60 elif [[ "$archive_file" =~ .*\.7z$ ]]; then
61   7z t "$archive_file" &>/dev/null
62   save_err=$?
63 elif [[ "$archive_file" =~ .*\.rar$ ]]; then
64   rar t "$archive_file" &>/dev/null
65   save_err=$?
66 fi
67
68 if [ $save_err -ne 0 ]; then
69   echo "** failure while testing: $archive_file"
70   exit 1
71 else
72   echo "good: $archive_file"
73 fi
74