-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-md5
executable file
·76 lines (69 loc) · 2.09 KB
/
check-md5
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
# !/bin/bash
if [ "$1" = "?" ]
then
B1="\033[1m";
B2="\033[0m";
echo -e "";
echo -e "${B1}AUTHOR${B2}";
echo -e " Igor almeida";
echo -e "";
echo -e "${B1}INFO${B2}";
echo -e " Compares the MD5 in the remote and local path and shows a report";
echo -e "";
echo -e "${B1}USAGE${B2}";
echo -e " check-md5";
echo -e " -> compares all te files into the current folder with the remote root path";
echo -e "";
echo -e "${B1}EXAMPLES${B2}";
echo -e " check-md5 local-folder";
echo -e " -> compares all files in 'local-folder' with the remote 'root/local-folder'";
echo -e "";
echo -e " check-md5 local-folder remote-folder";
echo -e " -> compares all files in 'local-folder' with the remote 'root/remote-folder'";
echo -e "";
exit 1;
fi
dirname=`dirname $0`
. "$dirname/test-config"
# create remote and local log names
timestamp=`date +%F-%s`
local_log="local_$timestamp.md5log"
remote_log="remote_$timestamp.md5log"
# function to analyse reports.
function compare {
total=0
err=0
cat "$1" | {
while read line; do
match=`cat "$2" | grep "$line" | awk '{ print $1 }'`
if [ -z $match ];
then
e=$e"$line\n"
err=$(($err+1))
else
s=$s"$line\n"
fi
total=$(($total+1))
done
if [ "$total" -eq "0" ];
then
result="000"
else
# echo "100-$err/$total*100" | bc -l
result=`echo 100-$err/$total*100 | bc -l`
result=`printf %0.0f $result`
result=`printf %03d $result`
fi
echo -e "┃ $result% matching. ┃\n┗━━━━━━━━━━━━━━━━━━━━━━━┛"
echo -e "MD5 @ SCOPE: '$3'\n"
echo -e "[!] FILES NOT MATCHING [$err]\n"$e
echo -e "[+] FILES MATCHING [$(($total-$err))]\n"$s;
}
}
. "$dirname/remote-md5" >> "$remote_log"
. "$dirname/local-md5" >> "$local_log"
echo -e "\n┏━━━━━━━━━━━━━━━━━━━━━━━┓\n┃ LOCAL X REMOTE ┃"
compare "$local_log" "$remote_log" "$1"
echo -e "┏━━━━━━━━━━━━━━━━━━━━━━━┓\n┃ REMOTE X LOCAL ┃"
compare "$remote_log" "$local_log" "$root$2"
rm *.md5log