6
OWNER_ID="099720109477"
7
error() { echo "$@" 1>&2; }
8
errorp() { printf "$@" 1>&2; }
9
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
10
failp() { [ $# -eq 0 ] || errorp "$@"; exit 1; }
11
bad_Usage() { Usage 1>&2; [ $# -eq 0 ] || error "$@"; exit 1; }
13
[ -n "${TMPD}" -a -d "${TMPD}" ] && rm -Rf "${TMPD}"
19
# ubuntu-karmic-i386-linux-image-2.6.31-300-ec2-v-2.6.31-300.5-kernel.img
20
# ubuntu-karmic-i386-linux-image-2.6.31-300-ec2-v-2.6.31-300.5-ramdisk.20091020.img
21
# ubuntu-karmic-x86_64-linux-image-2.6.31-300-ec2-v-2.6.31-300.5-ramdisk.20091020.1.img
22
# ubuntu-karmic-x86_64-linux-image-2.6.31-300-ec2-v-2.6.31-300.5-kernel.img
24
# read 2 inputs id manifest
26
# string up to "-kernel" or "-ramdisk"
27
# string after , or '0' if empty
29
# this should be sortable on key1, key2
31
local bname id man tmp ser base suf=".img.manifest.xml"
35
*-kernel${suf}|*-ramdisk${suf}) ser=0; base=${bname%-*${suf}};;
39
ser=${tmp##*-kernel.};;
40
*-ramdisk.*.img.manifest.xml)
43
ser=${tmp##*-ramdisk.};;
44
*) ser=0; base=${bname};;
46
printf "%s\t%s\t%s\t%s\t\n" \
47
"${base}" "${ser}" "${id}" "${man}"
53
prepare_for_sort | LANG=C sort --reverse |
54
awk -F '\t' '{ printf("%s\t%s\t\n",$3,$4); }'
55
for x in "${PIPESTATUS[@]}"; do [ "$x" = "0" ] || return 1; done
62
[ "$x" = "0" ] || i=$(($i+1))
69
[ "${#REGIONS[@]}" -eq 0 ] || return 0
70
REGIONS=( $(ec2-list-all-regions) ) || return 1
75
Usage: ${0##*/} [ options ] suite [arch]
77
find kernels and ramdisks on ec2 for suite release-type
78
output format is the same as 'publish-image' format, and should
79
be sorted within each region in "newest first" as:
87
if arch given, only do so for 'arch' (default: ${ARCHES[*]})
90
-l | --latest only print the "latest"
91
-m | --match m restrict kernels to those matching 'm'
92
-r | --regions r limit search to 'r' (comma or space delimited)
93
default: all (per describe-regions)
98
long_opts="latest,match:,regions:"
99
getopt_out=$(getopt --name "${0##*/}" \
100
--options "${short_opts}" --long "${long_opts}" -- "$@") &&
101
eval set -- "${getopt_out}" ||
107
arches=( i386 amd64 )
109
while [ $# -ne 0 ]; do
113
-l|--latest) latest=1;;
114
-m|--match) match=${next}; shift;;
115
-r|--regions) regions=( ${next//,/ } ); shift;;
120
[ $# -lt 1 ] && bad_Usage "must provide suite"
124
[ $# -eq 0 ] || arches=( "${@}" );
126
TMPD=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") ||
127
fail "failed to make tmpdir"
130
export XC2_XIMAGES_CACHE_D=${XC2_XIMAGES_CACHE_D:-"$TMPD/ximgcache"}
132
if [ ${#regions[@]} -eq 0 ]; then
133
get_regions || fail "failed to get region list"
134
regions=( "${REGIONS[@]}" )
137
for region in "${regions[@]}"; do
138
imglist="${TMPD}/images.${region}.txt"
139
xc2 ximages describe-images --region "${region}" --all > "${imglist}" ||
140
fail "failed to get images on ${region}"
142
for arch in "${arches[@]}"; do
143
action='printf("%s\t%s\n",$2,$3);'
144
criteria='$9 == type && $8 == xarch && $3 ~ regex'
146
klist="${TMPD}/kernels-${arch}.txt"
147
rlist="${TMPD}/ramdisks-${arch}.txt"
148
sklist="${klist}.sort"
149
srlist="${rlist}.sort"
151
[ "${arch}" = "x86_64" ] && arch=amd64;
152
xarch=${arch}; [ "${xarch}" = "amd64" ] && xarch=x86_64;
154
# account for region replacement in match input
155
if [ -n "$match" ]; then
156
# replace '%R' in match with region
157
rmatch="${match//%R/$region}"
158
kmatch="^${OWNER_ID}/${rmatch}$"
160
kmatch="^${OWNER_ID}/"
162
awk '-F\t' "${criteria} { ${action} }" \
163
"regex=${kmatch}" "type=kernel" "xarch=${xarch}" \
164
"${imglist}" > "${klist}" ||
165
fail "failed to search image results for ${kmatch}"
167
[ -s "${klist}" ] || {
168
errorp "no matching kernels in %s for suite %s arch %s\n\t%s\n" \
169
"${region}" "${suite}" "${arch}" "regex:${kmatch}";
173
krd_sort < "${klist}" > "${sklist}" || fail "failed to sort list"
175
while read k_ami k_manif; do
177
rmatch=${k_manif%-kernel*} # find ramdisks that match this kernel
179
awk '-F\t' "${criteria} { ${action} }" \
180
"regex=${rmatch}" "type=ramdisk" "xarch=${xarch}" \
181
"${imglist}" > "${rlist}" ||
182
fail "failed to search image results for ${rmatch}"
184
krd_sort < "${rlist}" > "${srlist}" ||
185
fail "failed to sort ramdisk list"
187
printf "%s\t%s\t%s\t%s\t%s\n" "${region}" "${k_ami}" \
188
"${arch}" kernel "${k_manif}"
190
# if 'latest', then we only print 1 ramdisk, and 1 kernel
191
if [ $latest -eq 1 ]; then
192
read ami manif < "${srlist}"
194
printf "%s\t%s\t%s\t%s\t%s\n" "${region}" "${ami}" \
195
"${arch}" "ramdisk" "${manif}"
198
# loop over ramdisk results
199
while read ami manif; do
201
printf "%s\t%s\t%s\t%s\t%s\n" "${region}" "${ami}" \
202
"${arch}" "ramdisk" "${manif}"