102
102
echo " Looking for build output SHA256SUMS fragments in ${OUTDIR_BASE} "
103
103
104
104
shopt -s nullglob
105
- OUTDIRS =( " $OUTDIR_BASE " /* /SHA256SUMS.part ) # This expands to an array of directories...
105
+ sha256sum_fragments =( " $OUTDIR_BASE " /* /SHA256SUMS.part ) # This expands to an array of directories...
106
106
shopt -u nullglob
107
107
108
108
noncodesigned_fragments=()
109
109
codesigned_fragments=()
110
110
111
- if (( ${# OUTDIRS [@]} )) ; then
111
+ if (( ${# sha256sum_fragments [@]} )) ; then
112
112
echo " Found build output SHA256SUMS fragments:"
113
- for outdir in " ${OUTDIRS [@]} " ; do
113
+ for outdir in " ${sha256sum_fragments [@]} " ; do
114
114
echo " '$outdir '"
115
115
case " $outdir " in
116
116
" $OUTDIR_BASE " /* -codesigned/SHA256SUMS.part)
@@ -139,6 +139,26 @@ out_name() {
139
139
basename " $( dirname " $1 " ) "
140
140
}
141
141
142
+ shasum_already_exists () {
143
+ cat << EOF
144
+ --
145
+
146
+ ERR: An ${1} file already exists for '${VERSION} ' and attests
147
+ differently. You likely previously attested to a partial build (e.g. one
148
+ where you specified the HOST environment variable).
149
+
150
+ See the diff above for more context.
151
+
152
+ Hint: You may wish to remove the existing attestations and their signatures by
153
+ invoking:
154
+
155
+ rm '${PWD} /${1} '{,.asc}
156
+
157
+ Then try running this script again.
158
+
159
+ EOF
160
+ }
161
+
142
162
echo " Attesting to build outputs for version: '${VERSION} '"
143
163
echo " "
144
164
@@ -147,40 +167,60 @@ mkdir -p "$outsigdir"
147
167
(
148
168
cd " $outsigdir "
149
169
150
- if [ -e " noncodesigned.SHA256SUMS" ]; then
151
- echo " noncodesigned.SHA256SUMS already exists, using..."
152
- elif (( ${# noncodesigned_fragments[@]} )) ; then
170
+ temp_noncodesigned=" $( mktemp) "
171
+ trap ' rm -rf -- "$temp_noncodesigned"' EXIT
172
+
173
+ if (( ${# noncodesigned_fragments[@]} )) ; then
153
174
cat " ${noncodesigned_fragments[@]} " \
154
175
| sort -u \
155
176
| sort -k2 \
156
- > noncodesigned.SHA256SUMS
177
+ > " $temp_noncodesigned "
178
+ if [ -e noncodesigned.SHA256SUMS ]; then
179
+ # The SHA256SUMS already exists, make sure it's exactly what we
180
+ # expect, error out if not
181
+ if diff -u noncodesigned.SHA256SUMS " $temp_noncodesigned " ; then
182
+ echo " A noncodesigned.SHA256SUMS file already exists for '${VERSION} ' and is up-to-date."
183
+ else
184
+ shasum_already_exists noncodesigned.SHA256SUMS
185
+ exit 1
186
+ fi
187
+ else
188
+ mv " $temp_noncodesigned " noncodesigned.SHA256SUMS
189
+ fi
157
190
else
158
- echo " no noncodesigned outputs found"
191
+ echo " ERR: No noncodesigned outputs found for '${VERSION} ', exiting..."
192
+ exit 1
159
193
fi
160
194
161
- if [ -e noncodesigned.SHA256SUMS ]; then
162
- # noncodesigned.SHA256SUMS already exists, or was produced, let's sanity
163
- # check it.
164
- ( cd " $OUTDIR_BASE " ; sha256sum -c " $outsigdir " /noncodesigned.SHA256SUMS )
165
-
166
- # Now produce all.SHA256SUMS manifest
167
- if [ -e " all.SHA256SUMS" ]; then
168
- echo " all.SHA256SUMS already there!"
169
- elif (( ${# codesigned_fragments[@]} )) ; then
170
- cat " ${OUTDIRS[@]} " \
171
- | sort -u \
172
- | sort -k2 \
173
- > all.SHA256SUMS
174
- else
175
- echo " no codesigned outputs found"
176
- fi
195
+ temp_codesigned=" $( mktemp) "
196
+ trap ' rm -rf -- "$temp_codesigned"' EXIT
177
197
178
- if [ -e all.SHA256SUMS ]; then
179
- ( cd " $OUTDIR_BASE " ; sha256sum -c " $outsigdir " /all.SHA256SUMS )
198
+ if (( ${# codesigned_fragments[@]} )) ; then
199
+ # Note: all.SHA256SUMS attests to all of $sha256sum_fragments, but is
200
+ # not needed if there are no $codesigned_fragments
201
+ cat " ${sha256sum_fragments[@]} " \
202
+ | sort -u \
203
+ | sort -k2 \
204
+ > " $temp_codesigned "
205
+ if [ -e codesigned.SHA256SUMS ]; then
206
+ # The SHA256SUMS already exists, make sure it's exactly what we
207
+ # expect, error out if not
208
+ if diff -u all.SHA256SUMS " $temp_codesigned " ; then
209
+ echo " An all.SHA256SUMS file already exists for '${VERSION} ' and is up-to-date."
210
+ else
211
+ shasum_already_exists all.SHA256SUMS
212
+ exit 1
213
+ fi
214
+ else
215
+ mv " $temp_codesigned " codesigned.SHA256SUMS
180
216
fi
217
+ else
218
+ # It is fine to have the codesigned outputs be missing (perhaps the
219
+ # detached codesigs have not been published yet), just print a log
220
+ # message instead of erroring out
221
+ echo " INFO: No codesigned outputs found for '${VERSION} ', skipping..."
181
222
fi
182
223
183
-
184
224
if [ -z " $NO_SIGN " ]; then
185
225
echo " Signing SHA256SUMS to produce SHA256SUMS.asc"
186
226
for i in * .SHA256SUMS; do
0 commit comments