a8312db742
This switches $CLOUD_IMAGES and $RELEASE to the DIB_ namespace so they will survive future changes to the sanitisation of the build environment. Change-Id: I7dc2aa82fb9ef452705b080cc404f41046014f20
46 lines
1.4 KiB
Bash
Executable File
46 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
[ -n "$ARCH" ]
|
|
[ -n "$TARGET_ROOT" ]
|
|
|
|
if [ 'amd64' = "$ARCH" ] ; then
|
|
ARCH="x86_64"
|
|
fi
|
|
|
|
IMG_PATH=~/.cache/image-create
|
|
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://mattdm.fedorapeople.org/cloud-images/}
|
|
DIB_RELEASE=${DIB_RELEASE:-Fedora18}
|
|
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-$DIB_RELEASE-Cloud-$ARCH-latest.raw.tar.xz}
|
|
BASE_IMAGE_TAR=$DIB_RELEASE-Cloud-$ARCH-latest.tgz
|
|
|
|
mkdir -p $IMG_PATH
|
|
# TODO: don't cache forever.
|
|
if [ ! -f $IMG_PATH/$BASE_IMAGE_FILE ] ; then
|
|
echo "Fetching Base Image"
|
|
wget $DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE -O $IMG_PATH/$BASE_IMAGE_FILE.tmp
|
|
mv $IMG_PATH/$BASE_IMAGE_FILE.tmp $IMG_PATH/$BASE_IMAGE_FILE
|
|
fi
|
|
if [ ! -f $IMG_PATH/$BASE_IMAGE_TAR ] ; then
|
|
echo "Repacking base image as tarball."
|
|
WORKING=$(mktemp -d)
|
|
EACTION="rm -r $WORKING"
|
|
trap "$EACTION" EXIT
|
|
echo "Working in $WORKING"
|
|
tar -xJC $WORKING -f $IMG_PATH/$BASE_IMAGE_FILE
|
|
LOOPDEV=$(sudo losetup --show -r -f $WORKING/*.raw)
|
|
EACTION="sudo losetup -d $LOOPDEV;$EACTION"
|
|
trap "$EACTION" EXIT
|
|
sudo partprobe $LOOPDEV
|
|
mkdir $WORKING/mnt
|
|
sudo mount ${LOOPDEV}p2 $WORKING/mnt
|
|
EACTION="sudo umount -f $WORKING/mnt;$EACTION"
|
|
trap "$EACTION" EXIT
|
|
# Chroot in so that we get the correct uid/gid
|
|
sudo chroot $WORKING/mnt bin/tar -cz . > $WORKING/tmp.tar
|
|
mv $WORKING/tmp.tar $IMG_PATH/$BASE_IMAGE_TAR
|
|
fi
|
|
# Extract the base image
|
|
sudo tar -C $TARGET_ROOT -xzf $IMG_PATH/$BASE_IMAGE_TAR
|