~philroche/ubuntu-on-ec2/ec2-publishing-scripts-kernel-panic-revert

8 by Scott Moser
switch to publish tools, away from bundle.sh and ec2-bundle
1
#!/bin/bash
2
# vi: ts=4 noexpandtab
3
4
MS="milestone"
466 by Ben Howard
Tweaks of sandbox/testing publication process
5
 LABELS=( sandbox daily   testing     beta beta[0-9] alpha alpha[0-9] rc  rc[0-9] release )
6
BUCKETS=( sandbox testing testing-dev $MS  $MS       $MS   $MS        $MS $MS     "" )
8 by Scott Moser
switch to publish tools, away from bundle.sh and ec2-bundle
7
326.1.2 by Scott Moser
move publishing tools to use new bucket/prefix convention
8
get_prefix() {
9 by Scott Moser
clean up label2bucketbase adding usage, more consitency with other tools
9
	local label=${1} itype=${2:-image}
8 by Scott Moser
switch to publish tools, away from bundle.sh and ec2-bundle
10
	local i="" x=""
9 by Scott Moser
clean up label2bucketbase adding usage, more consitency with other tools
11
	case "${itype}" in
12
		kernels|vmlinuz|kernel|ramdisk|initrd) ftype="kernels";;
13
		image) ftype="images";;
14
		*) echo "invalid type ${itype}" 1>&2; return 1;;
15
	esac
326.1.2 by Scott Moser
move publishing tools to use new bucket/prefix convention
16
	local path_prefix=${TEST_PUBLISH_PATH_PREFIX:-""}
8 by Scott Moser
switch to publish tools, away from bundle.sh and ec2-bundle
17
	for((i=0;i<${#LABELS[@]};i++)); do
18
		case "${label}" in
19
			${LABELS[$i]})
20
				x=${BUCKETS[$i]};
21
				[ "$x" = "" ] || x=-${x}
326.1.2 by Scott Moser
move publishing tools to use new bucket/prefix convention
22
				_RET="${path_prefix}${ftype}${x}"
8 by Scott Moser
switch to publish tools, away from bundle.sh and ec2-bundle
23
				return 0
24
				;;
25
		esac
26
	done
27
	return 1
28
}
29
9 by Scott Moser
clean up label2bucketbase adding usage, more consitency with other tools
30
Usage() {
31
	cat <<EOF
32
Usage: ${0##*/} label image-type
326.1.2 by Scott Moser
move publishing tools to use new bucket/prefix convention
33
   output the correct prefix (path within a bucket)
9 by Scott Moser
clean up label2bucketbase adding usage, more consitency with other tools
34
   for an image of type 'image-type' labeled 'label'.
35
36
   options:
37
     --show-labels:  dump valid labels to stdout and exit
38
     --show-mapping: dump table of label -> bucket for provided type
39
                     example: ${0##*/} --show-mapping kernel
40
41
   label is one of:
42
      ${LABELS[*]}
43
   image-type is one of:
44
      image, initrd, kernel, ramdisk, vmlinuz
45
EOF
46
}
47
48
if [ "$1" = "-h" -o "$1" = "--help" ]; then
49
	Usage; exit 0;
50
elif [ "$1" = "--show-labels" ]; then
51
	echo "${LABELS[*]}"; exit 0;
8 by Scott Moser
switch to publish tools, away from bundle.sh and ec2-bundle
52
elif [ "$1" = "--show-mapping" ]; then
53
	shift;
54
	for x in "${LABELS[@]}"; do
55
		modx=${x}
56
		[ "${x#*[}" != "${x}" ] && modx=${x%%[*}1
326.1.2 by Scott Moser
move publishing tools to use new bucket/prefix convention
57
		get_prefix "${modx}" ${1} || exit
8 by Scott Moser
switch to publish tools, away from bundle.sh and ec2-bundle
58
		printf "%-12s %s\n" "${x}" "${_RET}"
59
	done
60
	exit 0
61
fi
62
9 by Scott Moser
clean up label2bucketbase adding usage, more consitency with other tools
63
[ $# -eq 0 ] && { Usage 1>&2; exit 1; }
64
326.1.2 by Scott Moser
move publishing tools to use new bucket/prefix convention
65
get_prefix "${1}" ${2} && { echo "${_RET}"; exit 0; }
8 by Scott Moser
switch to publish tools, away from bundle.sh and ec2-bundle
66
exit 1