2 # Copyright (C) 2014 Ian Kelling
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 local help="Usage: isdiff [--help|-h] [-v] [-x] FILE1 FILE2
18 Test if FILE1 and FILE2 have the same contents
20 Returns 0 for same, 1 for diff, 2 for error.
23 -r use most reliable checksum available, ie. sha instead of md5"
27 if [[ $1 == --help ]] ||
[[ $1 == -[^
-]* && $1 == *h
* ]]; then
30 elif [[ $1 == -[^
-]* && $1 == *v
* ]]; then
33 elif [[ $1 == -[^
-]* && $1 == *r
* ]]; then
41 x
=($
(type -p sha512sum
) $
(type -p sha256sum
) $
(type -p sha1sum) $
(type -p md5sum))
42 if [[ $reliable ]]; then
45 sumbinary
=${x[${#x[@]}-1]}
49 echo "Need 1 of sha512sum sha256sum sha1sum or md5sum for sum() function"
52 if [[ $# != 2 ]]; then
53 [[ $v ]] && echo Error
: need
2 arguments.
57 x
=$
($sumbinary < "$1" ) ||
return 2
58 y
=$
($sumbinary < "$2" ) ||
return 2
60 { x
=$
($sumbinary < "$1" ) ;} 2>/dev
/null ||
return 2
61 { y
=$
($sumbinary < "$2" ) ;} 2>/dev
/null ||
return 2
63 if [[ $x == "$y" ]]; then
66 [[ $v ]] && echo "$1" "$2" different.