forked from openstack/devstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_uec_image.sh
More file actions
executable file
·109 lines (88 loc) · 2.43 KB
/
get_uec_image.sh
File metadata and controls
executable file
·109 lines (88 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# **get_uec_image.sh**
# Download and prepare Ubuntu UEC images
CACHEDIR=${CACHEDIR:-/opt/stack/cache}
ROOTSIZE=${ROOTSIZE:-2000}
# Keep track of the current directory
TOOLS_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
# Import common functions
. $TOP_DIR/functions
# Exit on error to stop unexpected errors
set -o errexit
set -o xtrace
usage() {
echo "Usage: $0 - Download and prepare Ubuntu UEC images"
echo ""
echo "$0 [-r rootsize] release imagefile [kernel]"
echo ""
echo "-r size - root fs size (min 2000MB)"
echo "release - Ubuntu release: jaunty - oneric"
echo "imagefile - output image file"
echo "kernel - output kernel"
exit 1
}
# 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 $$
}
while getopts hr: c; do
case $c in
h) usage
;;
r) ROOTSIZE=$OPTARG
;;
esac
done
shift `expr $OPTIND - 1`
if [[ ! "$#" -eq "2" && ! "$#" -eq "3" ]]; then
usage
fi
# Default args
DIST_NAME=$1
IMG_FILE=$2
IMG_FILE_TMP=`mktemp $IMG_FILE.XXXXXX`
KERNEL=$3
case $DIST_NAME in
oneiric) ;;
natty) ;;
maverick) ;;
lucid) ;;
*) echo "Unknown release: $DIST_NAME"
usage
;;
esac
trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT
# Check dependencies
if [ ! -x "`which qemu-img`" -o -z "`dpkg -l | grep cloud-utils`" ]; then
# Missing KVM?
apt_get install qemu-kvm cloud-utils
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
# Get the UEC image
UEC_NAME=$DIST_NAME-server-cloudimg-amd64
if [ ! -d $CACHEDIR ]; then
mkdir -p $CACHEDIR/$DIST_NAME
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)
fi
$RESIZE $CACHEDIR/$DIST_NAME/$UEC_NAME.img ${ROOTSIZE} $IMG_FILE_TMP
mv $IMG_FILE_TMP $IMG_FILE
# Copy kernel to destination
if [ -n "$KERNEL" ]; then
cp -p $CACHEDIR/$DIST_NAME/*-vmlinuz-virtual $KERNEL
fi
trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT