This repository has been archived by the owner on Nov 20, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecksum_wrapper.sh
83 lines (73 loc) · 1.9 KB
/
checksum_wrapper.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
####################################################
# GRIM REPO ########################################
####################################################
# checksum_wrapper.sh
#
# Wraps the checksum functionality for files and dirs.
# The checksum for a while should change whenever the
# content of the file changes.
# For starters, this is done via the md5sum tool.
# For directories, this is very inefficiently done
# by taking the md5sum of the md5sum+filename of
# all the files found (recursively) in the directory.
#
####################################################
####
# calc_checksum
#
# Calculates the checksum of the argument whether its a
# file or dir
#
# $1 - the path to the file
function calc_checksum {
filepath=$1;
if [ -f "$localroot$filepath" ]; then
checksum=`calc_file_checksum "$1"`;
else
checksum=`calc_dir_checksum "$1"`;
fi;
echo "${checksum% *}"
}
####
# calc_remote_file_checksum
#
# Calculates the checksum of the remote file, given as
# argument. Argument must be a file
#
# $1 - serverinfo: remote host (eg. user@host.com)
# $2 - file: full path to file
function calc_remote_file_checksum {
serverinfo=$1;
file=$2;
checksum=`ssh $serverinfo "md5sum \"$file\""`;
echo "${checksum% *}";
}
####
# calc_remote_dir_checksum
#
# Calculates the checksum of the remote dir, given as
# argument. Argument must be a dir
#
# $1 - serverinfo: remote host (eg. user@host.com)
# $2 - dir: full path to dir
function calc_remote_dir_checksum {
local serverinfo=$1;
local file=$2;
checksum=`ssh $serverinfo "find \"$file\" -type f -exec md5sum {} \; | md5sum;"`;
echo "${checksum% *}";
}
####
# Calculates checksum for dir
#
# $1 - path to dir, including dirname
function calc_dir_checksum {
find "$1" -type f -exec md5sum {} \; | md5sum;
}
####
# Calculates checksum for file
#
# $1 - path to file , including fileame
function calc_file_checksum {
md5sum "$1";
}