Skip to content

Commit 50bdf6a

Browse files
authored
Fix issue #4: give SHA256SUM files a date suffix
As described in issue #4, the SHA256SUM files are not removed after creating an ISO. This is intentional so they do not have to be downloaded more than once. However, this means that they can cause checksum verification to fail if the same files are used to validate the ISO from a different date. I have added a date suffix (DD-MM-YYYY) to the SHA256SUMS and SHA256SUMS.gpg files so that they are only used for the current day. There is still an issue if a user specifies an existing ISO image but does not disable automatic GPG verification (using the -k or --no-verify option), because if the specified image is not the current latest daily ISO, the verification will still fail. If users wish to use an existing ISO image other than the current latest one, they should disable GPG verification with the command line option and instead verify the ISO image themselves if desired.
1 parent 1d0a9aa commit 50bdf6a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

ubuntu-autoinstall-generator.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,20 @@ if [ ! -f "${source_iso}" ]; then
136136
log "👍 Downloaded and saved to ${source_iso}"
137137
else
138138
log "☑️ Using existing ${source_iso} file."
139+
if [ ${gpg_verify} -eq 1 ]; then
140+
if [ "${source_iso}" != "${script_dir}/ubuntu-original-$today.iso" ]; then
141+
log "⚠️ Automatic GPG verification is enabled. If the source ISO file is not the latest daily image, verification will fail!"
142+
fi
143+
fi
139144
fi
140145

141146
if [ ${gpg_verify} -eq 1 ]; then
142-
if [ ! -f "${script_dir}/SHA256SUMS" ]; then
147+
if [ ! -f "${script_dir}/SHA256SUMS-${today}" ]; then
143148
log "🌎 Downloading SHA256SUMS & SHA256SUMS.gpg files..."
144-
/usr/bin/curl -NsSL "https://cdimage.ubuntu.com/ubuntu-server/focal/daily-live/current/SHA256SUMS" -o "${script_dir}/SHA256SUMS"
145-
/usr/bin/curl -NsSL "https://cdimage.ubuntu.com/ubuntu-server/focal/daily-live/current/SHA256SUMS.gpg" -o "${script_dir}/SHA256SUMS.gpg"
149+
/usr/bin/curl -NsSL "https://cdimage.ubuntu.com/ubuntu-server/focal/daily-live/current/SHA256SUMS" -o "${script_dir}/SHA256SUMS-${today}"
150+
/usr/bin/curl -NsSL "https://cdimage.ubuntu.com/ubuntu-server/focal/daily-live/current/SHA256SUMS.gpg" -o "${script_dir}/SHA256SUMS-${today}.gpg"
146151
else
147-
log "☑️ Using existing SHA256SUMS & SHA256SUMS.gpg files."
152+
log "☑️ Using existing SHA256SUMS-${today} & SHA256SUMS-${today}.gpg files."
148153
fi
149154

150155
if [ ! -f "${script_dir}/${ubuntu_gpg_key_id}.keyring" ]; then
@@ -156,7 +161,7 @@ if [ ${gpg_verify} -eq 1 ]; then
156161
fi
157162

158163
log "🔐 Verifying ${source_iso} integrity and authenticity..."
159-
/usr/bin/gpg -q --keyring "${script_dir}/${ubuntu_gpg_key_id}.keyring" --verify "${script_dir}/SHA256SUMS.gpg" "${script_dir}/SHA256SUMS" 2>/dev/null
164+
/usr/bin/gpg -q --keyring "${script_dir}/${ubuntu_gpg_key_id}.keyring" --verify "${script_dir}/SHA256SUMS-${today}.gpg" "${script_dir}/SHA256SUMS-${today}" 2>/dev/null
160165
if [ $? -ne 0 ]; then
161166
rm -f "${script_dir}/${ubuntu_gpg_key_id}.keyring~"
162167
die "👿 Verification of SHA256SUMS signature failed."
@@ -165,7 +170,7 @@ if [ ${gpg_verify} -eq 1 ]; then
165170
rm -f "${script_dir}/${ubuntu_gpg_key_id}.keyring~"
166171
digest=$(sha256sum "${source_iso}" | cut -f1 -d ' ')
167172
set +e
168-
/usr/bin/grep -Fq "$digest" "${script_dir}/SHA256SUMS"
173+
/usr/bin/grep -Fq "$digest" "${script_dir}/SHA256SUMS-${today}"
169174
if [ $? -eq 0 ]; then
170175
log "👍 Verification succeeded."
171176
set -e

0 commit comments

Comments
 (0)