blob: 2414acdea17564bb08b594a9848c65725b69eb7a (
plain)
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
|
#!/bin/sh
PROG=injectdigs
if [ $# -eq 0 ]
then
digstr="md5 sha512"
else
digstr=$*
fi
if ! which openssl > /dev/null
then
echo "$PROG: openssl needs to be installed to calculate digests"
exit 2
fi
awk -v digstr="$digstr" -v prog="$PROG" '
BEGIN {
diglen = split(digstr, digalgs)
FS = "\n"; RS = ""; ORS = "\n\n"
}
function calcdigs(alg, files)
{
cmd = "openssl " alg " " files
digests = ""
while(cmd | getline > 0){
digests = digests $2 "\n"
}
close(cmd)
return digests
}
1
$1 == "source" {
for(i = 2; i <= NF; i++){
file = $i
sub(/.*\//, "", file)
if(system("test -f " file) != 0){
print prog ": source file " file " is missing!" | "cat 1>&2"
exit 1
}
files = files file " "
filelen++
}
}
END {
FS = " "; RS = "\n"
OFS = ORS = "\n"
if(!filelen) exit 0
for(i = 1; i <= diglen; i++){
alg = digalgs[i]
print alg "sums", calcdigs(alg, files)
}
}
'
|