forked from zeroleaf/groovy-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmp.sh
executable file
·61 lines (50 loc) · 1.12 KB
/
cmp.sh
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
#!/bin/bash
suffix="_filelist"
todolist="todolist"
function filesToText() {
if [ ! -z $2 ]; then
find $1 -type f | sed "s/^$1\///" > $1$suffix
else
find $1 -type f -name "*.adoc" | sed "s/^$1\///" > $1$suffix
fi
sort $1$suffix -o $1$suffix
}
function fileCompare() {
cur_sha1=$(shasum "$current/$1" | sed "s/\s.*//")
nxt_sha1=$(shasum "$next/$1" | sed "s/\s.*//")
if [ $cur_sha1 != $nxt_sha1 ]; then
echo "M $1" >> $todolist
fi
}
next="next"
current="current"
# Get agrument from user input.
while getopts "d:f" arg
do
case $arg in
d)
next=$OPTARG
;;
f)
fullList="true"
;;
esac
done
# Check if the new doc dir exists.
if [ ! -d $next ]; then
echo "Error, directory contain new doc does not exists."
exit 0
fi
filesToText $current $fullList
filesToText $next $filesToText
# New
comm $next$suffix $current$suffix -2 -3 | sed "s/^/A /" > $todolist
# Delete
comm $next$suffix $current$suffix -1 -3 | sed "s/^/D /" >> $todolist
cfiles=$(comm $next$suffix $current$suffix -1 -2)
for file in $cfiles
do
fileCompare $file
done
sort $todolist -o $todolist
rm *$suffix