forked from neomutt/neomutt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhcachever.sh
executable file
·119 lines (101 loc) · 2.01 KB
/
hcachever.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
#!/bin/sh
BASEVERSION=2
cleanstruct () {
echo "$1" | sed -e 's/.* //'
}
cleanbody () {
echo "$1" | sed -e 's/{ *//'
}
getstruct () {
STRUCT=""
BODY=''
inbody=0
case "$1" in
*'{') inbody=1 ;;
*';') return ;;
esac
STRUCT=`cleanstruct "$1"`
while read line
do
if test $inbody -eq 0
then
case "$line" in
'{'*) inbody=1 ;;
*';') return ;;
esac
fi
case "$line" in
'};'*)
break
;;
'#'*) continue ;;
*)
if test $inbody -ne 0
then
BODY="$BODY $line"
fi
;;
esac
done
case $STRUCT in
Address|Body|Buffer|Envelope|Header|ListNode|Parameter)
BODY=`cleanbody "$BODY"`
echo "$STRUCT: $BODY"
;;
esac
return
}
md5prog () {
prog=""
# Use OpenSSL if it's installed
openssl=`which openssl`
if [ $? = 0 ];then
# Check that openssl supports the -r option (requires version 1.1.0)
echo test | openssl md5 -r > /dev/null 2>&1
if [ $? = 0 ]; then
echo "$openssl md5 -r"
return
fi
fi
# Fallback to looking for a system-specific utility
case "`uname`" in
SunOS)
# This matches most of the Solaris family
prog="digest -a md5"
;;
*BSD|Darwin)
# Darwin, FreeBSD, NetBSD, and OpenBSD all have md5
prog="md5"
;;
*)
# Assume anything else has binutils' md5sum
prog="md5sum"
;;
esac
echo $prog
}
DEST="$1"
TMPD="$DEST.tmp"
TEXT="$BASEVERSION"
echo "/* base version: $BASEVERSION" > $TMPD
while read line
do
case "$line" in
'struct'*)
STRUCT=`getstruct "$line"`
if test -n "$STRUCT"
then
NAME=`echo $STRUCT | cut -d: -f1`
BODY=`echo $STRUCT | cut -d' ' -f2-`
echo " * $NAME:" $BODY >> $TMPD
TEXT="$TEXT $NAME {$BODY}"
fi
;;
esac
done
echo " */" >> $TMPD
MD5PROG=$(md5prog)
MD5TEXT=`echo "$TEXT" | $MD5PROG | cut -c-8`
echo "#define HCACHEVER 0x$MD5TEXT" >> $TMPD
# TODO: validate we have all structs
mv $TMPD $DEST