labs: verify MD5 checksum for Linux ISO image

Verify the MD5 checksum of the Linux distribution's ISO image before
trying to use it. Image corruption happens, and the resulting problems
are not always easy to diagnose.

Change-Id: I92852a28392002d4fcd64898453086d5920d0ef1
This commit is contained in:
Roger Luethi 2014-10-21 09:51:29 +02:00
parent f881eae252
commit 84863087a5
2 changed files with 25 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#-------------------------------------------------------------------------------
readonly ISO_URL=http://releases.ubuntu.com/14.04/ubuntu-14.04.1-server-amd64.iso
readonly ISO_MD5=ca2531b8cd79ea5b778ede3a524779b9
readonly _PS_ssh=http://git.openstack.org/cgit/openstack/training-guides/plain/labs/lib/osbash/netboot/preseed-ssh.cfg
readonly _PS_vbadd=http://git.openstack.org/cgit/openstack/training-guides/plain/labs/lib/osbash/netboot/preseed-vbadd.cfg

View File

@ -1,5 +1,26 @@
# This bash library contains the main function that creates the base disk.
function check_md5 {
local file=$1
local csum=$2
local md5exe
if ! md5exe=$(which md5sum); then
# On Mac OS X, the tool is called md5
if ! md5exe=$(which md5); then
echo >&2 "Neither md5sum nor md5 found. Aborting."
exit 1
fi
fi
echo >&2 -n "Verifying ISO image MD5 checksum: "
if $md5exe "$file" | grep -q "$csum"; then
echo >&2 "okay."
else
echo >&2 "failed."
echo >&2 "Aborting. Please fix or remove the ISO image."
exit 1
fi
}
function vm_install_base {
local base_disk=$1
local base_build_disk=$DISK_DIR/tmp-disk.vdi
@ -32,6 +53,9 @@ function vm_install_base {
fi
echo >&2 -e "Install ISO:\n\t$INSTALL_ISO"
${OSBASH:-:} check_md5 "$INSTALL_ISO" "$ISO_MD5"
$VBM storageattach "$vm_name" \
--storagectl IDE \
--port 0 \