aboutsummaryrefslogtreecommitdiff
path: root/Tools/scripts/ardiff
blob: 1840ec0d4001e8dc51c8a97819ab3955f033885f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh

#
# ardiff tries to make it easy for you to compare two archives. It makes no
# claims about originality, correctness or usefulness, but it saved a lot of
# time for at least one port maintainer.
#
# DEPS: vim, p7zip
# TODO: word-by-word, more intelligent diffs
#

usage () {
	if [ "$#" -gt 0 ]; then
		echo "Error: $*" >&2
	fi
	echo "Usage: $0 <archive1> <archive2>" >&2
	exit 0
}

debug () {
	echo "Debug: $*" >&2
}

die () {
	echo "Fatal: $*" >&2
	exit 2
}

extract () {
	if [ "$#" != 2 ]; then
		die "extract () miscalled" >&2
	fi
	cd $2
	if tar tf $1 >&-; then
		debug "file $1 looks like a good tar archive"
		tar xf $1 && debug "file $1 untar'ed successfully" || die "file $1 failed to untar"
	elif 7z t $1 >&-; then
		debug "file $1 looks like a good non-tar archive"
		7z x $1 >&- && debug "file $1 un7z'ed successfully" || die "file $1 failed to un7z"
	else
		die "file $1 was not recognized"
	fi
}

if [ "$#" != "2" ]; then
	usage
fi

ar1=`realpath $1`
ar2=`realpath $2`

for i in $ar1 $ar2;do if [ ! -r $i ]; then
	usage "file \"$i\" unreadable"
fi;done

for i in tar 7z;do if [ ! -x `which $i` ]; then
	die "missing a decompressor, please make sure tar and 7z are available"
fi;done
if [ ! -x `which vim` ]; then
	die "missing vim, please install it"
fi

art1=`mktemp -d -t /tmp` && debug "created tmp dir $art1" || usage "could not create a tmp dir"
art2=`mktemp -d -t /tmp` && debug "created tmp dir $art2" || usage "could not create a tmp dir"

extract $ar1 $art1
extract $ar2 $art2

if [ "`ls $art1|wc -l`" -eq 1 ]; then
	dart1=$art1/`ls $art1|head -n1`
else
	dart1=$art1
fi
if [ "`ls $art2|wc -l`" -eq 1 ]; then
	dart2=$art2/`ls $art2|head -n1`
else
	dart2=$art2
fi
#if [ "`ls $art1|wc -l`" -eq 1 ]&&[ "`ls $art2|wc -l`" -eq 1 ]; then
#	dart1=$art1/`ls $art1|head -n1`
#	dart2=$art2/`ls $art2|head -n1`
#else
#	dart1=$art1
#	dart2=$art2
#fi

{
	echo "====== Appeared and disappeared ======"
	diff -urq $dart1 $dart2|sed -e "s|$art1|OLD|;s|$art2|NEW|"|grep '^Only'
	echo "====== Modified ======"
	diff -urq $dart1 $dart2|sed -e "s|$art1|OLD|;s|$art2|NEW|"|grep -v '^Only'
	echo "====== Modifications ======"
	diff -ur $dart1 $dart2|sed -e "s|$art1|OLD|;s|$art2|NEW|"
}|vim -R -c "syntax on" -c "set syntax=diff" -c "set nowrap" \
	-c 'let @/="^--- "' -c "set so=20" -

rm -rf $art1 $art2 && debug "removed tmp dirs"