|
99 | 99 | # We should be able to find at least one output
|
100 | 100 | ################
|
101 | 101 |
|
102 |
| -echo "Looking for build output directories in ${OUTDIR_BASE}" |
| 102 | +echo "Looking for build output SHA256SUMS fragments in ${OUTDIR_BASE}" |
103 | 103 |
|
104 | 104 | shopt -s nullglob
|
105 |
| -OUTDIRS=( "${OUTDIR_BASE}"/* ) # This expands to an array of directories... |
| 105 | +OUTDIRS=( "$OUTDIR_BASE"/*/SHA256SUMS.part ) # This expands to an array of directories... |
106 | 106 | shopt -u nullglob
|
107 | 107 |
|
| 108 | +noncodesigned_fragments=() |
| 109 | +codesigned_fragments=() |
| 110 | + |
108 | 111 | if (( ${#OUTDIRS[@]} )); then
|
109 |
| - echo "Found build output directories:" |
| 112 | + echo "Found build output SHA256SUMS fragments:" |
110 | 113 | for outdir in "${OUTDIRS[@]}"; do
|
111 | 114 | echo " '$outdir'"
|
| 115 | + case "$outdir" in |
| 116 | + "$OUTDIR_BASE"/*-codesigned/SHA256SUMS.part) |
| 117 | + codesigned_fragments+=("$outdir") |
| 118 | + ;; |
| 119 | + *) |
| 120 | + noncodesigned_fragments+=("$outdir") |
| 121 | + ;; |
| 122 | + esac |
112 | 123 | done
|
113 | 124 | echo
|
114 | 125 | else
|
115 |
| - echo "ERR: Could not find any build output directories in ${OUTDIR_BASE}" |
| 126 | + echo "ERR: Could not find any build output SHA256SUMS fragments in ${OUTDIR_BASE}" |
116 | 127 | exit 1
|
117 | 128 | fi
|
118 | 129 |
|
119 |
| - |
120 | 130 | ##############
|
121 | 131 | ## Attest ##
|
122 | 132 | ##############
|
|
126 | 136 | # HOST: The output directory being attested
|
127 | 137 | #
|
128 | 138 | out_name() {
|
129 |
| - basename "$1" |
130 |
| -} |
131 |
| - |
132 |
| -# Usage: out_sig_dir $outdir |
133 |
| -# |
134 |
| -# outdir: The output directory being attested |
135 |
| -# |
136 |
| -out_sig_dir() { |
137 |
| - echo "$GUIX_SIGS_REPO/$VERSION/$(out_name "$1")/$signer_name" |
| 139 | + basename "$(dirname "$1")" |
138 | 140 | }
|
139 | 141 |
|
140 |
| -# Accumulate a list of signature directories that already exist... |
141 |
| -outdirs_already_attested_to=() |
142 |
| - |
143 | 142 | echo "Attesting to build outputs for version: '${VERSION}'"
|
144 | 143 | echo ""
|
145 | 144 |
|
146 |
| -# MAIN LOGIC: Loop through each output for VERSION and attest to output in |
147 |
| -# GUIX_SIGS_REPO as SIGNER, if attestation does not exist |
148 |
| -for outdir in "${OUTDIRS[@]}"; do |
149 |
| - if [ -e "${outdir}/SKIPATTEST.TAG" ]; then |
150 |
| - echo "${outname}: SKIPPING: Output directory marked with SKIPATTEST.TAG file" |
151 |
| - continue |
152 |
| - fi |
153 |
| - outname="$(out_name "$outdir")" |
154 |
| - outsigdir="$(out_sig_dir "$outdir")" |
155 |
| - if [ -e "$outsigdir" ]; then |
156 |
| - echo "${outname}: SKIPPING: Signature directory already exists in the specified guix.sigs repository" |
157 |
| - outdirs_already_attested_to+=("$outdir") |
| 145 | +outsigdir="$GUIX_SIGS_REPO/$VERSION/$signer_name" |
| 146 | +mkdir -p "$outsigdir" |
| 147 | +( |
| 148 | + cd "$outsigdir" |
| 149 | + |
| 150 | + if [ -e "noncodesigned.SHA256SUMS" ]; then |
| 151 | + echo "noncodesigned.SHA256SUMS already exists, using..." |
| 152 | + elif (( ${#noncodesigned_fragments[@]} )); then |
| 153 | + cat "${noncodesigned_fragments[@]}" \ |
| 154 | + | sort -u \ |
| 155 | + | sort -k2 \ |
| 156 | + > noncodesigned.SHA256SUMS |
158 | 157 | else
|
159 |
| - # Clean up incomplete sigdir if something fails (likely gpg) |
160 |
| - trap 'rm -rf "$outsigdir"' ERR |
161 |
| - |
162 |
| - mkdir -p "$outsigdir" |
163 |
| - |
164 |
| - ( |
165 |
| - cd "$outdir" |
166 |
| - |
167 |
| - if [ -e inputs.SHA256SUMS ]; then |
168 |
| - echo "${outname}: Including existent input SHA256SUMS" |
169 |
| - cat inputs.SHA256SUMS >> "$outsigdir"/SHA256SUMS |
170 |
| - fi |
| 158 | + echo "no noncodesigned outputs found" |
| 159 | + fi |
171 | 160 |
|
172 |
| - echo "${outname}: Hashing build outputs to produce SHA256SUMS" |
173 |
| - files="$(find -L . -type f ! -iname '*.SHA256SUMS')" |
174 |
| - if [ -n "$files" ]; then |
175 |
| - cut -c3- <<< "$files" | env LC_ALL=C sort | xargs sha256sum >> "$outsigdir"/SHA256SUMS |
176 |
| - else |
177 |
| - echo "ERR: ${outname}: No outputs found in '${outdir}'" |
178 |
| - exit 1 |
179 |
| - fi |
180 |
| - ) |
181 |
| - if [ -z "$NO_SIGN" ]; then |
182 |
| - echo "${outname}: Signing SHA256SUMS to produce SHA256SUMS.asc" |
183 |
| - gpg --detach-sign --local-user "$gpg_key_name" --armor --output "$outsigdir"/SHA256SUMS.asc "$outsigdir"/SHA256SUMS |
| 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 |
184 | 174 | else
|
185 |
| - echo "${outname}: Not signing SHA256SUMS as \$NO_SIGN is not empty" |
| 175 | + echo "no codesigned outputs found" |
186 | 176 | fi
|
187 |
| - echo "" |
188 | 177 |
|
189 |
| - trap - ERR # Reset ERR trap |
| 178 | + if [ -e all.SHA256SUMS ]; then |
| 179 | + ( cd "$OUTDIR_BASE"; sha256sum -c "$outsigdir"/all.SHA256SUMS ) |
| 180 | + fi |
190 | 181 | fi
|
191 |
| -done |
192 |
| - |
193 |
| -if (( ${#outdirs_already_attested_to[@]} )); then |
194 |
| -# ...so that we can print them out nicely in a warning message |
195 |
| -cat << EOF |
196 | 182 |
|
197 |
| -WARN: Signature directories from '$signer_name' already exist in the specified |
198 |
| - guix.sigs repository for the following output directories and were |
199 |
| - skipped: |
200 | 183 |
|
201 |
| -EOF |
202 |
| -for outdir in "${outdirs_already_attested_to[@]}"; do |
203 |
| - echo " '${outdir}'" |
204 |
| - echo " Corresponds to: '$(out_sig_dir "$outdir")'" |
| 184 | + if [ -z "$NO_SIGN" ]; then |
| 185 | + echo "Signing SHA256SUMS to produce SHA256SUMS.asc" |
| 186 | + for i in *.SHA256SUMS; do |
| 187 | + if [ ! -e "$i".asc ]; then |
| 188 | + gpg --detach-sign \ |
| 189 | + --local-user "$gpg_key_name" \ |
| 190 | + --armor \ |
| 191 | + --output "$i".asc "$i" |
| 192 | + else |
| 193 | + echo "Signature already there" |
| 194 | + fi |
| 195 | + done |
| 196 | + else |
| 197 | + echo "Not signing SHA256SUMS as \$NO_SIGN is not empty" |
| 198 | + fi |
205 | 199 | echo ""
|
206 |
| -done |
207 |
| -fi |
| 200 | +) |
0 commit comments