blob: 7fa920ec641ee495e3813287b7cb645268717fd6 [file] [log] [blame]
Dean Troyere753fdf2011-10-25 15:45:26 -05001#!/bin/bash
Jesse Andrewsd7326d22011-11-20 10:02:26 -08002# get_uec_image.sh - Prepare Ubuntu UEC images
Dean Troyere753fdf2011-10-25 15:45:26 -05003
Jesse Andrewsd7326d22011-11-20 10:02:26 -08004CACHEDIR=${CACHEDIR:-/opt/stack/cache}
Dean Troyere753fdf2011-10-25 15:45:26 -05005ROOTSIZE=${ROOTSIZE:-2000}
Dean Troyere753fdf2011-10-25 15:45:26 -05006
Jesse Andrews04156db2011-10-31 11:59:55 -07007# Keep track of the current directory
8TOOLS_DIR=$(cd $(dirname "$0") && pwd)
9TOP_DIR=`cd $TOOLS_DIR/..; pwd`
10
Dean Troyer43392f72011-11-05 16:55:15 -050011# exit on error to stop unexpected errors
12set -o errexit
13
Dean Troyere753fdf2011-10-25 15:45:26 -050014usage() {
Jesse Andrewsd7326d22011-11-20 10:02:26 -080015 echo "Usage: $0 - Fetch and prepare Ubuntu images"
Dean Troyere753fdf2011-10-25 15:45:26 -050016 echo ""
Jesse Andrewsd7326d22011-11-20 10:02:26 -080017 echo "$0 [-r rootsize] release imagefile [kernel]"
Dean Troyere753fdf2011-10-25 15:45:26 -050018 echo ""
Jesse Andrewsd7326d22011-11-20 10:02:26 -080019 echo "-r size - root fs size (min 2000MB)"
Dean Troyere753fdf2011-10-25 15:45:26 -050020 echo "release - Ubuntu release: jaunty - oneric"
Dean Troyera03b99d2011-10-25 16:28:49 -050021 echo "imagefile - output image file"
Jesse Andrewsd7326d22011-11-20 10:02:26 -080022 echo "kernel - output kernel"
Dean Troyere753fdf2011-10-25 15:45:26 -050023 exit 1
24}
25
Dean Troyer55c02732011-11-01 17:44:03 -050026# Clean up any resources that may be in use
27cleanup() {
28 set +o errexit
29
30 # Mop up temporary files
31 if [ -n "$IMG_FILE_TMP" -a -e "$IMG_FILE_TMP" ]; then
32 rm -f $IMG_FILE_TMP
33 fi
34
Dean Troyer55c02732011-11-01 17:44:03 -050035 # Kill ourselves to signal any calling process
36 trap 2; kill -2 $$
37}
38
Jesse Andrewsd7326d22011-11-20 10:02:26 -080039while getopts hr: c; do
Dean Troyere753fdf2011-10-25 15:45:26 -050040 case $c in
Dean Troyere753fdf2011-10-25 15:45:26 -050041 h) usage
42 ;;
Dean Troyere753fdf2011-10-25 15:45:26 -050043 r) ROOTSIZE=$OPTARG
Dean Troyere753fdf2011-10-25 15:45:26 -050044 ;;
45 esac
46done
47shift `expr $OPTIND - 1`
48
Jesse Andrewsd7326d22011-11-20 10:02:26 -080049if [[ ! "$#" -eq "2" && ! "$#" -eq "3" ]]; then
Dean Troyere753fdf2011-10-25 15:45:26 -050050 usage
51fi
52
53# Default args
54DIST_NAME=$1
55IMG_FILE=$2
Dean Troyer71745fe2011-10-31 16:59:02 -050056IMG_FILE_TMP=`mktemp $IMG_FILE.XXXXXX`
Jesse Andrewsd7326d22011-11-20 10:02:26 -080057KERNEL=$3
Dean Troyere753fdf2011-10-25 15:45:26 -050058
59case $DIST_NAME in
60 oneiric) ;;
61 natty) ;;
62 maverick) ;;
63 lucid) ;;
Dean Troyere753fdf2011-10-25 15:45:26 -050064 *) echo "Unknown release: $DIST_NAME"
65 usage
66 ;;
67esac
68
Jesse Andrewsd7326d22011-11-20 10:02:26 -080069trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT
Dean Troyer43392f72011-11-05 16:55:15 -050070
Jesse Andrewsd7326d22011-11-20 10:02:26 -080071# Check dependencies
72if [ ! -x "`which qemu-img`" -o -z "`dpkg -l | grep cloud-utils`" ]; then
Dean Troyer43392f72011-11-05 16:55:15 -050073 # Missing KVM?
Jesse Andrewsd7326d22011-11-20 10:02:26 -080074 apt_get install qemu-kvm cloud-utils
Dean Troyer43392f72011-11-05 16:55:15 -050075fi
Dean Troyer55c02732011-11-01 17:44:03 -050076
Jesse Andrewsd7326d22011-11-20 10:02:26 -080077# Find resize script
78RESIZE=`which resize-part-image || which uec-resize-image`
79if [ -z "$RESIZE" ]; then
80 echo "resize tool from cloud-utils not found"
81 exit 1
82fi
Dean Troyere753fdf2011-10-25 15:45:26 -050083
84# Get the UEC image
85UEC_NAME=$DIST_NAME-server-cloudimg-amd64
Jesse Andrewsd7326d22011-11-20 10:02:26 -080086if [ ! -d $CACHEDIR ]; then
87 mkdir -p $CACHEDIR/$DIST_NAME
88fi
89if [ ! -e $CACHEDIR/$DIST_NAME/$UEC_NAME.tar.gz ]; then
90 (cd $CACHEDIR/$DIST_NAME && wget -N http://uec-images.ubuntu.com/$DIST_NAME/current/$UEC_NAME.tar.gz)
91 (cd $CACHEDIR/$DIST_NAME && tar Sxvzf $UEC_NAME.tar.gz)
Dean Troyere753fdf2011-10-25 15:45:26 -050092fi
93
Jesse Andrewsd7326d22011-11-20 10:02:26 -080094$RESIZE $CACHEDIR/$DIST_NAME/$UEC_NAME.img ${ROOTSIZE} $IMG_FILE_TMP
Dean Troyer71745fe2011-10-31 16:59:02 -050095mv $IMG_FILE_TMP $IMG_FILE
Jesse Andrewsd7326d22011-11-20 10:02:26 -080096
97# Copy kernel to destination
98if [ -n "$KERNEL" ]; then
99 cp -p $CACHEDIR/$DIST_NAME/*-vmlinuz-virtual $KERNEL
100fi
101
102trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT