Import upstream version 1.29
[debian/tar] / tests / star / quicktest.sh
1 #! /bin/sh
2 # This file is part of GNU tar testsuite.
3 # Copyright 2004-2005, 2007, 2013-2014, 2016 Free Software Foundation,
4 # Inc.
5
6 # This file is part of GNU tar.
7
8 # GNU tar is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12
13 # GNU tar is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 PWD=`pwd`
22 P=`expr $0 : '\(.*\)/.*'`
23 DIR=`cd $P; pwd`/../../src
24 if [ -d $DIR ]; then
25         PATH=`cd $DIR;pwd`:$PATH
26 fi
27
28 # Usage: quicktest FILELIST ARCHIVE-NAME
29 quicktest() {
30         DIR=quicktest.$$
31         mkdir $DIR
32         cd $DIR
33
34         TAR_OPTIONS=""
35         export TAR_OPTIONS
36
37         tar xf $2
38         tar -cf ../archive -H ustar -T $1
39         cd ..
40
41         ${TARTEST:-tartest} -v < $2 > $DIR/old.out
42         ${TARTEST:-tartest} -v < archive > $DIR/new.out
43
44         if cmp $DIR/old.out $DIR/new.out; then
45                 echo "PASS"
46                 rm -r $DIR
47                 exit 0
48         else
49                 echo "FAIL. Examine $DIR for details"
50                 exit 1
51         fi
52 }
53
54 test_access() {
55         if [ -r $1 ]; then
56                 :
57         else
58                 echo "$1 does not exist or is unreadable"
59                 echo 77
60         fi
61 }
62
63 check_environ() {
64         if [ "$STAR_TESTSCRIPTS" = "" ]; then
65                 echo "STAR_TESTSCRIPTS not set"
66                 exit 77
67         fi
68
69         if [ -d $STAR_TESTSCRIPTS ]; then
70                 :
71         else
72                 echo "STAR_TESTSCRIPTS is not a directory"
73                 exit 77
74         fi
75
76         ARCHIVE=$STAR_TESTSCRIPTS/ustar-all-quicktest.tar
77         test_access $ARCHIVE
78         FILELIST=$STAR_TESTSCRIPTS/quicktest.filelist
79         test_access $FILELIST
80
81         ${TARTEST:-tartest} < /dev/null > /dev/null 2>&1
82         if [ $? -eq 127 ]; then
83                 echo "tartest not in your path"
84                 exit 77
85         fi
86         tar --version
87 }
88
89 getargs() {
90         for option
91         do
92                 case $option in
93                 *=*)  eval $option;;
94                 *)    echo "Unknown option: $option" >&2
95                       exit 77;;
96                 esac
97         done
98 }
99
100 if [ -w / ]; then
101         getargs $*
102         check_environ
103         quicktest $FILELIST $ARCHIVE
104 else
105         echo "You need to be root to run this test"
106         exit 77
107 fi
108
109 # End of quicktest.sh