Enable --offline support for Ubuntu root images.

When --offline is set elements should not revalidate cached data. The
ubuntu element had not been updated to match this. SHA checking is
also skipped as we only move a new cached file into place when the
hash matches, and we might download a new hash before updating the
image cache, which would cause persistent --offline failures.

Change-Id: If1a0366b51951a73b7a3ffe23a29a3d910b08938
This commit is contained in:
Robert Collins 2013-07-18 10:05:47 +12:00
parent f7f6cb45ee
commit d7379df8b8

View File

@ -1,7 +1,7 @@
#!/bin/bash
# These are useful, or at worst not harmful, for all images we build.
set -e
set -eu
[ -n "$ARCH" ]
[ -n "$TARGET_ROOT" ]
@ -13,13 +13,18 @@ DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://cloud-images.ubuntu.com/}
DIB_RELEASE=${DIB_RELEASE:-quantal}
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-$DIB_RELEASE-server-cloudimg-$ARCH-root.tar.gz}
SHA256SUMS=${SHA256SUMS:-https://${DIB_CLOUD_IMAGES##http?(s)://}/$DIB_RELEASE/current/SHA256SUMS}
CACHED_FILE=$IMG_PATH/$BASE_IMAGE_FILE
if [ -n "$DIB_OFFLINE" -a -f "$CACHED_FILE" ] ; then
echo "Not checking freshness of cached $CACHED_FILE."
else
echo "Fetching Base Image"
$TMP_HOOKS_PATH/bin/cache-url $SHA256SUMS $IMG_PATH/SHA256SUMS.ubuntu.$DIB_RELEASE.$ARCH
$TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$DIB_RELEASE/current/$BASE_IMAGE_FILE $IMG_PATH/$BASE_IMAGE_FILE
$TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$DIB_RELEASE/current/$BASE_IMAGE_FILE $CACHED_FILE
pushd $IMG_PATH
grep "$BASE_IMAGE_FILE" SHA256SUMS.ubuntu.$DIB_RELEASE.$ARCH | sha256sum --check -
popd
fi
# Extract the base image
sudo tar -C $TARGET_ROOT -xzf $IMG_PATH/$BASE_IMAGE_FILE
sudo rmdir $TARGET_ROOT/lost+found