Fix openSUSE cloud image download and extraction
Use the latest available version of the rootfs (instead of a qcow2 image) to simplify rootfs extraction. Change-Id: Ic3a646b923738464b5217d799758b6980b2deaf2
This commit is contained in:
parent
7214ca1196
commit
1757ef20ea
@ -3,20 +3,6 @@
|
|||||||
set -eu
|
set -eu
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
function find_free_nbd_device () {
|
|
||||||
# Return first free nbd device
|
|
||||||
return_device=''
|
|
||||||
for chk_device in /sys/class/block/nbd*; do
|
|
||||||
# find free nbd device by checking size field
|
|
||||||
size_chk=`cat $chk_device/size`
|
|
||||||
if [ "$size_chk" = "0" ]; then
|
|
||||||
# device looks free. lets use it.
|
|
||||||
return_device=$chk_device
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
echo $return_device
|
|
||||||
}
|
|
||||||
[ -n "$ARCH" ]
|
[ -n "$ARCH" ]
|
||||||
[ -n "$TARGET_ROOT" ]
|
[ -n "$TARGET_ROOT" ]
|
||||||
|
|
||||||
@ -24,81 +10,35 @@ if [ 'amd64' = "$ARCH" ] ; then
|
|||||||
ARCH="x86_64"
|
ARCH="x86_64"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ 'i386' = "$ARCH" ] ; then
|
if ! [ 'x86_64' = "$ARCH" ] ; then
|
||||||
ARCH="i586"
|
echo "Only x86_64 images are currently available but ARCH is set to $ARCH."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://download.opensuse.org/repositories/Cloud:/Images/images/}
|
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://download.opensuse.org/repositories/Cloud:/Images/images/}
|
||||||
DIB_RELEASE=${DIB_RELEASE:-13.1}
|
DIB_RELEASE=${DIB_RELEASE:-13.1}
|
||||||
# FIXME: Hard coded build numbers, versions, etc.
|
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-openSUSE-${DIB_RELEASE}-OS-rootfs.${ARCH}.tbz}
|
||||||
# NOTE: Actual file name seems unstable, and has changed several times.
|
SHA256SUMS_FILE=${SHA256SUMS_FILE:-${BASE_IMAGE_FILE}.sha256}
|
||||||
BASE_IMAGE_NAME=${BASE_IMAGE_NAME:-openSUSE-$DIB_RELEASE-OS-guest.$ARCH-0.0.2-Build3.1}
|
|
||||||
|
|
||||||
if [ -z "$DIB_OFFLINE" ] ; then
|
CACHED_FILE=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE
|
||||||
# XXX: Try to extract the filename of the current built from the index
|
CACHED_SHA256SUMS_FILE=$DIB_IMAGE_CACHE/SHA256SUMS.$BASE_IMAGE_FILE
|
||||||
# page. As there is one built available in the repo at a given time, this
|
|
||||||
# should work. This is a tempoary workaround until the fix for
|
|
||||||
# https://bugzilla.novell.com/show_bug.cgi?id=853882 is deployed
|
|
||||||
echo "Looking up current built of Base Image ($BASE_IMAGE_NAME):"
|
|
||||||
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-$(curl $DIB_CLOUD_IMAGES | \
|
|
||||||
sed -n "s/^.*\<a\ href\=\"\($BASE_IMAGE_NAME.*\.tar\.bz2\)\".*$/\1/p")}
|
|
||||||
if [ -n "$BASE_IMAGE_FILE" ]; then
|
|
||||||
echo "Using base image: $DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE"
|
|
||||||
else
|
|
||||||
echo -e "Failed to extract image file name from $DIB_CLOUD_IMAGES" \
|
|
||||||
"\nPlease set BASE_IMAGE_FILE manually and retry."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-$BASE_IMAGE_NAME-raw.tar.bz2}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# FIXME: either check the checksums into git or verify the signature
|
# FIXME: either check the checksums into git or verify the signature
|
||||||
# on the checksums. We should not be trusting checksums we download
|
# on the checksums. We should not be trusting checksums we download
|
||||||
# over HTTP
|
# over HTTP
|
||||||
SHA256SUMS=${SHA256SUMS:-$DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE.sha256}
|
|
||||||
CACHED_FILE=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE
|
|
||||||
|
|
||||||
if [ -n "$DIB_OFFLINE" -a -f "$CACHED_FILE" ] ; then
|
if [ -n "$DIB_OFFLINE" -a -f "$CACHED_FILE" ] ; then
|
||||||
echo "Not checking freshness of cached $CACHED_FILE."
|
echo "Not checking freshness of cached $CACHED_FILE."
|
||||||
else
|
else
|
||||||
echo "Fetching Base Image"
|
echo "Fetching Base Image"
|
||||||
$TMP_HOOKS_PATH/bin/cache-url $SHA256SUMS $DIB_IMAGE_CACHE/SHA256SUMS.openSUSE.$DIB_RELEASE.$ARCH
|
$TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$SHA256SUMS_FILE $CACHED_SHA256SUMS_FILE
|
||||||
$TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE $CACHED_FILE
|
$TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE $CACHED_FILE
|
||||||
pushd $DIB_IMAGE_CACHE
|
pushd $DIB_IMAGE_CACHE
|
||||||
grep "$BASE_IMAGE_FILE" SHA256SUMS.openSUSE.$DIB_RELEASE.$ARCH | sha256sum --check -
|
# Calculate sha256sum of downloaded image and check against content from sha256 file
|
||||||
|
SHA256SUM=$(sha256sum ${BASE_IMAGE_FILE} | cut -d " " -f1)
|
||||||
|
grep -q $SHA256SUM SHA256SUMS.$BASE_IMAGE_FILE
|
||||||
popd
|
popd
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Extract the qcow2 image and qcow2.sha256 files.
|
# Extract the base image (use --numeric-owner to avoid UID/GID mismatch between
|
||||||
# to make life easier create a temp directory to unzip the files.
|
# image tarball and host OS)
|
||||||
# TODO(NobodyCam): validate qcow2 with sha256 file
|
sudo tar -C $TARGET_ROOT --numeric-owner -xjf $CACHED_FILE
|
||||||
UNTAR_TO_LOCATION=$TMP_MOUNT_PATH/openSUSE/Untar
|
|
||||||
mkdir -p $UNTAR_TO_LOCATION
|
|
||||||
sudo tar -C $UNTAR_TO_LOCATION -xjf $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE
|
|
||||||
# mount qcow
|
|
||||||
nbd_device=$(find_free_nbd_device)
|
|
||||||
mount_device=/dev/`basename $nbd_device`
|
|
||||||
sudo qemu-nbd -c $mount_device $UNTAR_TO_LOCATION/$BASE_IMAGE_NAME.qcow2
|
|
||||||
# Ensure that $mount_device is a block device.
|
|
||||||
if [ -b $mount_device ]; then
|
|
||||||
org_dir=`pwd`
|
|
||||||
# make a mount point for the image
|
|
||||||
mkdir $UNTAR_TO_LOCATION/mnt
|
|
||||||
# mount the images root partition
|
|
||||||
sudo mount ${mount_device}p1 $UNTAR_TO_LOCATION/mnt
|
|
||||||
# copy contents to the build area
|
|
||||||
cd $UNTAR_TO_LOCATION/mnt
|
|
||||||
sudo find . -print | sudo cpio -padmu $TARGET_ROOT
|
|
||||||
# ensure we are not in the directory about to be unmounted
|
|
||||||
cd $org_dir
|
|
||||||
echo "Copied $UNTAR_TO_LOCATION/mnt to $TARGET_ROOT"
|
|
||||||
# unmount and remove the device used for the copy
|
|
||||||
sudo umount $UNTAR_TO_LOCATION/mnt
|
|
||||||
sudo qemu-nbd -d $mount_device
|
|
||||||
else
|
|
||||||
echo "Unable to extract openSUSE Image."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
# remove the temp directory
|
|
||||||
sudo rm -rf $UNTAR_TO_LOCATION
|
|
||||||
|
Loading…
Reference in New Issue
Block a user