~ubuntu-on-ec2/ubuntu-on-ec2/publish-debug-fginther

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
#!/bin/bash
error() { echo "$@" 1>&2; }
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }

Usage() {
	cat <<EOF
Usage: ${0##*/} [ options ] label build-dir [suite]

   update-build-indexes: re-make the web indices for a build output directory

   build-dir is a path to a build output directory
   label is valid input to pathprefix4label

   options:
    -h | --help     show help
    -n | --dry-run  only report what would be done
EOF
}
bad_Usage() { Usage 1>&2; fail "$@"; }

short_opts="hn"
long_opts="dry-run,help"
getopt_out=$(getopt --name "${0##*/}" \
	--options "${short_opts}" --long "${long_opts}" -- "$@") &&
	eval set -- "${getopt_out}" ||
	bad_Usage

dry_run=0

while [ $# -ne 0 ]; do
	cur=${1}; next=${2};
	case "$cur" in
		-h|--help) Usage; exit 0;;
		-n|--dry-run) dry_run=1;;
		--) shift; break;;
	esac
	shift;
done

[ $# -eq 2 -o $# -eq 3 ] || bad_Usage "must give label and build-dir. suite is optional"

label=${1}
build_d_in=${2}
suite=${3}

( cd "$build_d_in" ) 2>/dev/null || fail "${build_d_in}: not a directory"
out=$(pathprefix4label "$label") ||
	fail "$label is not valid label"

build_d=$( cd "$build_d_in" && x=$PWD && 
	{ [ "${x%unpacked}" = "$x" ] || cd .. ; } &&
	echo $PWD ) || fail "failed to get full build-directory for $build_d"

if [ -z "$suite" ]; then
	[ -f "$build_d/unpacked/build-info.txt" ] ||
		fail "no build-info.txt under $build_d_in"
	unset serial orig_prefix suite build_name;
	. $build_d/unpacked/build-info.txt

	[ -n "$suite" ] || fail "suite not set in build-info"
fi

error "updating web indices for suite=$suite label=$label in $build_d_in"

# this "when to use version in string" is copied elsewhere
# please look for VERSION2STRING if updating it.
# the idea is that beta+ get the release number in their name
rel_num=$(ubuntu-adj2version "${suite}") || fail "bad suite ${suite}"
case "${label}" in
	release)
		flabel=${rel_num};;
	beta*|rc*)
		flabel=${rel_num}-${label};;
	*) flabel=${label};;
esac

cdprefix="$flabel"
case "$label" in
    release|beta*|rc*) cdprefix="ubuntu-$flabel";;
    sandbox) cdprefix="sandbox-$flabel";;
    testing) cdprefix="testing-$flabel";;
esac

status="release"
case "$label" in
    daily) status="daily";;
    testing) status="testing";;
    sandbox) status="sandbox";;
esac

[ "$dry_run" -eq 1 ] && D="echo" || D=""

for dir in "$build_d" "$build_d/unpacked"; do
	env $D DIST="$suite" LABEL="$label" make-web-indices \
		"$dir" "$cdprefix" "$status" ||
		fail "failed to make web indicies for $dir"
done

# vi: ts=4 noexpandtab