-
Notifications
You must be signed in to change notification settings - Fork 19
/
verify-ofbiz-release.sh
executable file
·210 lines (173 loc) · 4.89 KB
/
verify-ofbiz-release.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
#####################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#####################################################################
# verify-ofbiz-release.sh
# Apache OFBiz release verification tool.
# Downloads and checks the given release zip file for correct md5/SHA checksums
# and signing certificate (see https://www.apache.org/dev/release-signing.html).
# If selected, can also automatically unpack the release, init the Gradle warapper
# and perform the integration tests.
#
# Usage: $0 [-h] [-d] [-v] [-t] [-a] [apache-ofbiz-xx.xx.xx]
# Options
# -h print help and exit
# -d download release files
# -v verify release files
# -t run integration tests
# -a all of the above
#
# to log the output to a file, do something like
# ./verify-ofbiz-release.sh -a apache-ofbiz-17.12.06 2>&1 | tee verify.log
# configuration
VERSION=0.2
URL='https://dist.apache.org/repos/dist/dev/ofbiz'
# color definitions for output
RED='\033[0;31m'
GRN='\033[0;32m'
NC='\033[0m' # No Color
# Preserve original language and set en_EN
TEMPLANG=$LANG
LANG=en_EN.UTF-8
printHelp () {
cat <<EOF
Apache OFBiz release verification tool v$VERSION.
Usage: $0 [-h] [-d] [-v] [-t] [-a] [apache-ofbiz-xx.xx.xx]
Options:
-h print help and exit
-d download release files
-v verify release files
-t run integration tests
-a all of the above
To log the output to a file, use something like
./verify-ofbiz-release.sh -a apache-ofbiz-17.12.06 2>&1 | tee verify.log
EOF
}
# np parameters at all - print help and exit
if [[ $# -eq 0 ]] ; then
printHelp
exit 1
fi
# initialize switches
download=false
verify=false
runtests=false
# get options and strip from commandline
while getopts "hdvta" option
do
case $option in
h) printHelp; exit 0 ;;
d) download=true ;;
v) verify=true ;;
t) runtests=true ;;
a) download=true; verify=true; runtests=true ;;
?) echo "Error: option -$OPTARG is not implemented."; exit 1;;
esac
done
shift $(( OPTIND - 1 ))
# no remaining argument with the release name - print help and exit
if [ -z "$1" ] ; then
printHelp
exit 1
fi
# remaining (last) parameter is the release name
RELEASE=$1
ZIP=$RELEASE.zip
printHelp () {
echo "Usage: $0 [-h] [-d] [-v] [-t] [-a] [apache-ofbiz-xx.xx.xx]"
echo "Options:"
echo "-h print help and exit"
echo "-d download release files"
echo "-v verify release files"
echo "-t run integration tests"
echo "-a all of the above"
}
downloadFiles () {
echo "Downloading files for $ZIP..."
wget $URL/KEYS
wget $URL/$ZIP
wget $URL/$ZIP.asc
wget $URL/$ZIP.sha512
echo 'Done!'
echo " "
}
verifyFiles () {
echo "Verifying files..."
if [ ! -f $ZIP.sha512 ];
then
echo -e "${RED}skipping sha check!${NC} (sha checksum file $ZIP.sha512 not found)\n"
else
checkSHA $ZIP
fi
if [ ! -f $ZIP.asc ];
then
echo -e "${RED}skipping signature check!${NC} (signature file $ZIP.asc not found)"
else
echo "GPG verification output"
LC_MESSAGES=en_EN.UTF-8 gpg --verify $ZIP.asc $ZIP
fi
echo " "
}
checkSHA () {
file1=`gpg --print-md SHA512 $ZIP`
file2=`cut -d* -f1 $ZIP.sha512`
echo "sha check of file: $ZIP"
echo "Using sha file: $ZIP.sha512"
echo $file1
echo $file2
if [ "$file1" != "$file2" ]
then
echo -e "${RED}sha sums mismatch!${NC}"
else
echo -e "${GRN}sha checksum OK${NC}"
fi
echo ""
}
runTests () {
if [ ! -d $RELEASE ];
then
echo "Unpacking release file archive $ZIP..."
unzip $ZIP
fi
cd $RELEASE
echo "Initializing Gradle wrapper..."
./gradle/init-gradle-wrapper.sh
echo "Running tests..."
./gradlew cleanAll loadAll testIntegration
cd ..
}
echo "Processing files for release: $RELEASE..."
# downlad release files
if [ "$download" = true ]
then
downloadFiles
fi
# verify release files
if [ "$verify" = true ]
then
verifyFiles
fi
# unpack, init Gradle wrapper and run integration tests
if [ "$runtests" = true ]
then
runTests
fi
# reset original language
LANG=$TEMPLANG
echo "Done processing files for release $RELEASE"
exit 0