-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvmanifest.sh
executable file
·165 lines (144 loc) · 6.13 KB
/
vmanifest.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/ksh
# Usage: vmanifest [full path of directory]
#
# * Assumes a single directory that contains a set of content files and a set of individual .md5 files
# ** Generates manifest of md5s from individual md5 text files
# ** Creates new md5s of the payload files
# ** Runs diff against old manifest and new manifest and reports result
# * Not recursive - input directory must contain all files directly
#
# Remember to make the script executable: chmod +x vmanifest.sh
#
# Requirements: for MAC OS only, assumes existence of MD5 utility that comes with MAC OS
# This is an example script written by Bertram Lyons at IASA, 2015, in Paris, France for demonstration
# the version of the script
VERSION=1.0
# announce the tool
echo "MD5 Manifest Verifier: Version - $VERSION"
echo "Written for IASA demonstration only"
echo "AVPreserve, 2015; running `date`"
# syntax check (must have only one parameter: input directory)
if [ ! -d "$1" ];
then echo "Syntax: $0 <input directory>"
exit 1
fi
# change to the requested directory and inform the user of such
cd "$1"
echo ""
echo "Preparing to gather md5s from the following directory as requested: "
pwd
echo ""
echo ""
# create new directory on the user's desktop called "md5_verification" and inform user
# change the OUTPATH below to specify a different location for output files
OUTPATH=~/desktop/md5_verification
if [ ! -d "$OUTPATH" ]; then
echo "Creating new metadata folder for the requested directory..."
mkdir -p "$OUTPATH"
echo ""
fi
# begin accumulating md5s from all .md5 files in directory and
# placing results in a single new manifest.txt file
echo "Extracting pre-written md5s from md5 files..."
ls -1 | grep ".md5$" | while read file ; do
cat "$file"
done | sort -k2 > "$OUTPATH/manifest.txt"
COUNTERMD5=$(wc -l "$OUTPATH/manifest.txt" | awk '{print $1}')
# begin generating new md5s from all content files in directory and
# placing results in a single new nmanifest.txt file
echo ""
echo "Generating new md5s for payload files..."
ls -1 | grep -v ".md5$" | while read file ; do
md5 -r "$file"
done | sort -k2 > "$OUTPATH/nmanifest.txt"
COUNTERFILE=$(wc -l "$OUTPATH/nmanifest.txt" | awk '{print $1}')
# compare old md5 manifest with new md5 manifest to determine any issues
echo ""
echo "Comparing old md5s with new md5s..."
cd "$OUTPATH"
RESULT=$(diff -swB manifest.txt nmanifest.txt)
# determine if any problems exist based on the results of the diff function above
if [ "$RESULT" = "Files manifest.txt and nmanifest.txt are identical" ]
then
echo "MD5 Verifier Tool" >> "$OUTPATH/verification_result.txt"
NOW=$(date)
echo "Date performed: $NOW" >> "$OUTPATH/verification_result.txt"
echo "$COUNTERMD5 md5s found" >> "$OUTPATH/verification_result.txt"
echo "$COUNTERFILE files evaluated" >> "$OUTPATH/verification_result.txt"
echo "Result: All files are accounted for and all files match previous MD5s." >> "$OUTPATH/verification_result.txt"
echo "" >> "$OUTPATH/verification_result.txt"
echo "Files verified:" >> "$OUTPATH/verification_result.txt"
FILES=$(cat "$OUTPATH/manifest.txt")
echo "$FILES" >> "$OUTPATH/verification_result.txt"
# inform user of success and how many files processed
echo ""
echo "Analysis complete."
echo "$COUNTERMD5 md5s found"
echo "$COUNTERFILE files processed"
echo ""
echo "Result: All files are accounted for and all files match previous MD5s."
echo ""
exit
else
MD5CHECK=$(("$COUNTERMD5"-"$COUNTERFILE"))
FILECHECK=$(("$COUNTERFILE"-"$COUNTERMD5"))
if [ $MD5CHECK -ne $FILECHECK ]
then
if [ $MD5CHECK -lt $FILECHECK ]
then
echo "MD5 Verifier Tool" >> "$OUTPATH/verification_result.txt"
NOW=$(date)
echo "Date performed: $NOW" >> "$OUTPATH/verification_result.txt"
echo "$COUNTERMD5 md5s found" >> "$OUTPATH/verification_result.txt"
echo "$COUNTERFILE files evaluated" >> "$OUTPATH/verification_result.txt"
echo "There are more files here than checksums to verify." >> "$OUTPATH/verification_result.txt"
echo "Result: $RESULT." >> $OUTPATH/verification_result.txt
# inform user of success and how many files processed
echo ""
echo "Analysis complete."
echo "$COUNTERMD5 md5s found"
echo "$COUNTERFILE files processed"
echo "There are more files here than checksums to verify."
echo ""
echo "Result: $RESULT"
echo ""
exit
else
echo "MD5 Verifier Tool" >> "$OUTPATH/verification_result.txt"
NOW=$(date)
echo "Date performed: $NOW" >> "$OUTPATH/verification_result.txt"
echo "$COUNTERMD5 md5s found" >> "$OUTPATH/verification_result.txt"
echo "$COUNTERFILE files evaluated" >> "$OUTPATH/verification_result.txt"
echo "There are more checksums here than files to verify." >> "$OUTPATH/verification_result.txt"
echo "Result: $RESULT." >> "$OUTPATH/verification_result.txt"
# inform user of success and how many files processed
echo ""
echo "Analysis complete."
echo "$COUNTERMD5 md5s found"
echo "$COUNTERFILE files processed"
echo "There are more checksums here than files to verify."
echo ""
echo "Result: $RESULT"
echo ""
exit
fi
else
echo "MD5 Verifier Tool" >> "$OUTPATH/verification_result.txt"
NOW=$(date)
echo "Date performed: $NOW" >> "$OUTPATH/verification_result.txt"
echo "$COUNTERMD5 md5s found" >> "$OUTPATH/verification_result.txt"
echo "$COUNTERFILE files evaluated" >> "$OUTPATH/verification_result.txt"
echo "Checksums do not match." >> "$OUTPATH/verification_result.txt"
echo "Result: $RESULT." >> "$OUTPATH/verification_result.txt"
# inform user of success and how many files processed
echo ""
echo "Analysis complete."
echo "$COUNTERMD5 md5s found"
echo "$COUNTERFILE files processed"
echo "Checksums do not match."
echo ""
echo "Result: $RESULT"
echo ""
exit
fi
fi