From 84863087a52a8c79e0872849cfd50586692b5772 Mon Sep 17 00:00:00 2001 From: Roger Luethi Date: Tue, 21 Oct 2014 09:51:29 +0200 Subject: [PATCH] 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 --- labs/lib/osbash/lib.ubuntu-14.04-server-amd64 | 1 + labs/lib/osbash/virtualbox.install_base | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/labs/lib/osbash/lib.ubuntu-14.04-server-amd64 b/labs/lib/osbash/lib.ubuntu-14.04-server-amd64 index 7db1fb21..266e9a0e 100644 --- a/labs/lib/osbash/lib.ubuntu-14.04-server-amd64 +++ b/labs/lib/osbash/lib.ubuntu-14.04-server-amd64 @@ -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 diff --git a/labs/lib/osbash/virtualbox.install_base b/labs/lib/osbash/virtualbox.install_base index 5c5a7d06..b40848d6 100644 --- a/labs/lib/osbash/virtualbox.install_base +++ b/labs/lib/osbash/virtualbox.install_base @@ -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 \