e753fdf4 |
#!/bin/bash |
e62ba4d3 |
# **get_uec_image.sh**
# Download and prepare Ubuntu UEC images |
d7326d2e |
CACHEDIR=${CACHEDIR:-/opt/stack/cache} |
0c495392 |
ROOTSIZE=${ROOTSIZE:-2000M} |
e753fdf4 |
|
04156dbe |
# Keep track of the current directory
TOOLS_DIR=$(cd $(dirname "$0") && pwd) |
7f9aa71b |
TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
# Import common functions
. $TOP_DIR/functions |
04156dbe |
|
e62ba4d3 |
# Exit on error to stop unexpected errors |
43392f74 |
set -o errexit |
9c7c9083 |
set -o xtrace |
43392f74 |
|
e753fdf4 |
usage() { |
e62ba4d3 |
echo "Usage: $0 - Download and prepare Ubuntu UEC images" |
e753fdf4 |
echo "" |
d7326d2e |
echo "$0 [-r rootsize] release imagefile [kernel]" |
e753fdf4 |
echo "" |
d7326d2e |
echo "-r size - root fs size (min 2000MB)" |
0c495392 |
echo "release - Ubuntu release: lucid - quantal" |
a03b99dc |
echo "imagefile - output image file" |
d7326d2e |
echo "kernel - output kernel" |
e753fdf4 |
exit 1
}
|
55c02737 |
# Clean up any resources that may be in use
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 $$
}
|
d7326d2e |
while getopts hr: c; do |
e753fdf4 |
case $c in
h) usage
;;
r) ROOTSIZE=$OPTARG
;;
esac
done
shift `expr $OPTIND - 1`
|
d7326d2e |
if [[ ! "$#" -eq "2" && ! "$#" -eq "3" ]]; then |
e753fdf4 |
usage
fi
# Default args
DIST_NAME=$1
IMG_FILE=$2 |
71745fe6 |
IMG_FILE_TMP=`mktemp $IMG_FILE.XXXXXX` |
d7326d2e |
KERNEL=$3 |
e753fdf4 |
case $DIST_NAME in |
0c495392 |
quantal) ;; |
93923ebe |
precise) ;; |
e753fdf4 |
oneiric) ;;
natty) ;;
maverick) ;;
lucid) ;;
*) echo "Unknown release: $DIST_NAME"
usage
;;
esac
|
d7326d2e |
trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT |
43392f74 |
|
d7326d2e |
# Check dependencies
if [ ! -x "`which qemu-img`" -o -z "`dpkg -l | grep cloud-utils`" ]; then |
43392f74 |
# Missing KVM? |
d7326d2e |
apt_get install qemu-kvm cloud-utils |
43392f74 |
fi |
55c02737 |
|
d7326d2e |
# 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 |
e753fdf4 |
# Get the UEC image
UEC_NAME=$DIST_NAME-server-cloudimg-amd64 |
0c495392 |
if [ ! -d $CACHEDIR/$DIST_NAME ]; then |
d7326d2e |
mkdir -p $CACHEDIR/$DIST_NAME |
e753fdf4 |
fi |
d7326d2e |
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) |
e753fdf4 |
fi
|
d7326d2e |
$RESIZE $CACHEDIR/$DIST_NAME/$UEC_NAME.img ${ROOTSIZE} $IMG_FILE_TMP
mv $IMG_FILE_TMP $IMG_FILE |
dccd6b92 |
|
d7326d2e |
# Copy kernel to destination
if [ -n "$KERNEL" ]; then
cp -p $CACHEDIR/$DIST_NAME/*-vmlinuz-virtual $KERNEL
fi |
71745fe6 |
|
d7326d2e |
trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT |