devstack/tools/get_uec_image.sh

110 lines
2.5 KiB
Bash
Raw Normal View History

2011-10-25 15:45:26 -05:00
#!/bin/bash
# **get_uec_image.sh**
# Download and prepare Ubuntu UEC images
CACHEDIR=${CACHEDIR:-/opt/stack/cache}
ROOTSIZE=${ROOTSIZE:-2000M}
2011-10-25 15:45:26 -05:00
2011-10-31 11:59:55 -07:00
# Keep track of the current directory
TOOLS_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
# Import common functions
. $TOP_DIR/functions
2011-10-31 11:59:55 -07:00
# Exit on error to stop unexpected errors
2011-11-05 16:55:15 -05:00
set -o errexit
set -o xtrace
2011-11-05 16:55:15 -05:00
function usage {
echo "Usage: $0 - Download and prepare Ubuntu UEC images"
2011-10-25 15:45:26 -05:00
echo ""
echo "$0 [-r rootsize] release imagefile [kernel]"
2011-10-25 15:45:26 -05:00
echo ""
echo "-r size - root fs size (min 2000MB)"
echo "release - Ubuntu release: lucid - quantal"
2011-10-25 16:28:49 -05:00
echo "imagefile - output image file"
echo "kernel - output kernel"
2011-10-25 15:45:26 -05:00
exit 1
}
# Clean up any resources that may be in use
function cleanup {
set +o errexit
# Mop up temporary files
if [ -n "$IMG_FILE_TMP" -a -e "$IMG_FILE_TMP" ]; then
rm -f $IMG_FILE_TMP
fi
# Kill ourselves to signal any calling process
trap 2; kill -2 $$
}
while getopts hr: c; do
2011-10-25 15:45:26 -05:00
case $c in
h) usage
;;
r) ROOTSIZE=$OPTARG
;;
esac
done
shift `expr $OPTIND - 1`
if [[ ! "$#" -eq "2" && ! "$#" -eq "3" ]]; then
2011-10-25 15:45:26 -05:00
usage
fi
# Default args
DIST_NAME=$1
IMG_FILE=$2
2011-10-31 16:59:02 -05:00
IMG_FILE_TMP=`mktemp $IMG_FILE.XXXXXX`
KERNEL=$3
2011-10-25 15:45:26 -05:00
case $DIST_NAME in
saucy) ;;
raring) ;;
quantal) ;;
precise) ;;
2011-10-25 15:45:26 -05:00
*) echo "Unknown release: $DIST_NAME"
usage
;;
esac
trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT
2011-11-05 16:55:15 -05:00
# Check dependencies
if [ ! -x "`which qemu-img`" -o -z "`dpkg -l | grep cloud-utils`" ]; then
2011-11-05 16:55:15 -05:00
# Missing KVM?
apt_get install qemu-kvm cloud-utils
2011-11-05 16:55:15 -05:00
fi
# Find resize script
RESIZE=`which resize-part-image || which uec-resize-image`
if [ -z "$RESIZE" ]; then
echo "resize tool from cloud-utils not found"
exit 1
fi
2011-10-25 15:45:26 -05:00
# Get the UEC image
UEC_NAME=$DIST_NAME-server-cloudimg-amd64
if [ ! -d $CACHEDIR/$DIST_NAME ]; then
mkdir -p $CACHEDIR/$DIST_NAME
2011-10-25 15:45:26 -05:00
fi
if [ ! -e $CACHEDIR/$DIST_NAME/$UEC_NAME.tar.gz ]; then
(cd $CACHEDIR/$DIST_NAME && wget -N http://uec-images.ubuntu.com/$DIST_NAME/current/$UEC_NAME.tar.gz)
(cd $CACHEDIR/$DIST_NAME && tar Sxvzf $UEC_NAME.tar.gz)
2011-10-25 15:45:26 -05:00
fi
$RESIZE $CACHEDIR/$DIST_NAME/$UEC_NAME.img ${ROOTSIZE} $IMG_FILE_TMP
mv $IMG_FILE_TMP $IMG_FILE
2011-11-01 15:46:14 -05:00
# Copy kernel to destination
if [ -n "$KERNEL" ]; then
cp -p $CACHEDIR/$DIST_NAME/*-vmlinuz-virtual $KERNEL
fi
2011-10-31 16:59:02 -05:00
trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT