~ubuntu-archive/ubuntu-archive-scripts/trunk

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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#! /bin/sh
set -e

LOCK=
mtimes=
cleanup () {
	[ "$mtimes" ] && rm -rf "$mtimes"
	[ "$LOCK" ] && rm -f "$LOCK"
}
trap cleanup EXIT HUP INT QUIT TERM

if [ -t 1 ]; then
	REDIR=
else
	REDIR='>/dev/null 2>&1'
fi

LOCK="$HOME/.archive-reports.lock"
if ! eval lockfile -r1 "$LOCK" $REDIR; then
	trap - EXIT HUP INT QUIT TERM
	exit 1
fi

MIRROR="$HOME/mirror/ubuntu"
MIRROR_RTM="$HOME/mirror/ubuntu-rtm"
MIRROR_PHONE_OVERLAY="$HOME/mirror/phone-overlay"
GERMINATE="$HOME/mirror/ubuntu-germinate"
OUT="$HOME/public_html"
DEVEL=eoan
DEVEL_RTM=14.09
DEVEL_RTM_FACTORY=14.09-factory
PROPOSED_MIGRATION_SERIES="precise trusty xenial bionic cosmic disco eoan"
PROPOSED_MIGRATION_SERIES_RTM="14.09 14.09-factory"

mtimes="$(mktemp -d)"

collect_mtimes () {
	stat -c '%n %Y' \
		"$MIRROR"/dists/*/Release \
		"$MIRROR_RTM"/dists/*/Release \
		"$MIRROR_PHONE_OVERLAY"/dists/*/Release \
		"$GERMINATE/germinate.output" \
		"$HOME/extra-germinate/germinate.output" \
		>"$mtimes/$1" 2>/dev/null || true
}

mtime () {
	(grep "^$2 " "$mtimes/$1" || echo "$2 0") | cut -d' ' -f2
}

mtime_changed () {
	[ "$(mtime old "$1")" != "$(mtime new "$1")" ]
}

is_rtm () {
	[ -e "$MIRROR_RTM/dists/$1" ]
}

release_changed () {
	if is_rtm "$1"; then
		mtime_changed "$MIRROR_RTM/dists/$1/Release"
	else
		mtime_changed "$MIRROR/dists/$1/Release"
	fi
}

germinate_changed () {
	mtime_changed "$GERMINATE/germinate.output" || \
		mtime_changed "$HOME/extra-germinate/germinate.output"
}

is_devel () {
	case $suite in
	    $DEVEL-proposed|$DEVEL_RTM-proposed|$DEVEL_RTM_FACTORY-proposed)
		return 0
		;;
	    *)
		return 1
		;;
	esac
}

pm_pending_tests () {
	local excuses
	if is_rtm "$1"; then
		excuses="$HOME/public_html/proposed-migration/ubuntu-rtm/$1/update_excuses.html"
	else
		excuses="$HOME/public_html/proposed-migration/$1/update_excuses.html"
	fi
	grep -q "Test in progress" "$excuses"
}

background () {
	local var="$1"
	shift
	"$@" &
	eval "$var=\"\${$var:+\$$var }\$!\""
}

background_wait () {
	local var="$1"
	for pid in $(eval "echo \$$var"); do
		wait "$pid"
	done
	eval "$var="
}

collect_mtimes old

mkdir -p "$MIRROR"
rsync -aq \
	--exclude dapper\* --exclude edgy\* --exclude feisty\* \
	--exclude gutsy\* --exclude hardy\* --exclude intrepid\* \
	--exclude jaunty\* --exclude karmic\* --exclude lucid\* \
	--exclude maverick\* --exclude natty\* --exclude oneiric\* \
	--exclude quantal\* --exclude raring\* --exclude saucy\* \
	--exclude utopic\* --exclude wily\* \
	--exclude yakkety\* --exclude zesty\* --exclude artful\* \
	--include Packages\* --include Sources\* --include Release\* \
	--include udeb.list --include \*\*/installer-\*/current \
	--include "**/$DEVEL/Contents-*" \
	--include \*/ --exclude \* --delete --delete-excluded \
	--prune-empty-dirs \
	ftpmaster.internal::ubuntu-dists/ "$MIRROR/dists/"

mkdir -p "$MIRROR_RTM"
rsync -aq \
	--include Packages\* --include Sources\* --include Release\* \
	--include udeb.list --include \*\*/installer-\*/current \
	--include "**/$DEVEL_RTM/Contents-*" \
	--include "**/$DEVEL_RTM_FACTORY/Contents-*" \
	--include \*/ --exclude \* --delete --delete-excluded \
	--prune-empty-dirs \
	bilimbi.canonical.com::ubuntu-rtm-dists/ "$MIRROR_RTM/dists/"

mkdir -p "$MIRROR_PHONE_OVERLAY"
http_proxy=http://squid.internal:3128/ wget -q --mirror \
	-nH --cut-dirs=3 -np -R '*index.html*' \
	-P "$MIRROR_PHONE_OVERLAY" \
	-X '/*/*/*/*/*/*/i18n' \
	http://ppa.launchpad.net/ci-train-ppa-service/stable-phone-overlay/ubuntu/dists/

collect_mtimes new

# The $DEVEL-proposed chdist configuration is used by proposed-migration;
# it's important to get that done as soon as possible, so we do it first.
chdist_pids=
chdists=0
for dist in "$HOME/.chdist"/*; do
	[ -d "$dist" ] || continue
	suite="${dist##*/}"
	suite="${suite%-*}"
	if is_devel "$suite" && release_changed "$suite"; then
		background chdist_pids chdist apt-get "${dist##*/}" update >/dev/null
		chdists=$(($chdists + 1))
	fi
	if [ "$chdists" = 7 ]; then
		background_wait chdist_pids
		chdists=0
	fi
done
background_wait chdist_pids

if mtime_changed "$MIRROR/.*/Release" || \
   mtime_changed "$MIRROR_RTM/.*/Release" || \
   mtime_changed "$MIRROR_PHONE_OVERLAY/.*/Release"; then
	background pids run-apt-mirror-snapshot
fi

pids=
run_proposed_migration () {
	DISTRIBUTION=ubuntu SERIES="$1" run-proposed-migration
}
for series in $PROPOSED_MIGRATION_SERIES; do
	if release_changed "$series" || release_changed "$series-proposed" || \
	   release_changed "$series-updates" || \
	   pm_pending_tests "$series"; then
		background pids run_proposed_migration "$series"
	fi
done

run_proposed_migration_rtm () {
	DISTRIBUTION=ubuntu-rtm SERIES="$1" \
		B2_CONFIG=/home/ubuntu-archive/proposed-migration/britney-rtm.conf \
		B2_CONFIG_NOBREAKALL=/home/ubuntu-archive/proposed-migration/britney_nobreakall-rtm.conf \
		run-proposed-migration
}
for series in $PROPOSED_MIGRATION_SERIES_RTM; do
	if release_changed "$series" || release_changed "$series-proposed" || \
	   release_changed "$series-updates" || \
	   pm_pending_tests "$series"; then
		background pids run_proposed_migration_rtm "$series"
	fi
done

# Both update-transitions and run-britney need this.
rsync -aq --delete --prune-empty-dirs \
	"$MIRROR/dists/" \
	"/srv/chroots/trusty-transitions/srv/transitions/mirror/ubuntu/dists/"

if release_changed "$DEVEL-proposed"; then
	background pids update-transitions
fi

if release_changed "$DEVEL"; then
	background pids run-britney
fi

# Now update all the other chdist configurations, and wait for that to
# finish before doing anything else.
chdist_pids=
chdists=0
for dist in "$HOME/.chdist"/*; do
	[ -d "$dist" ] || continue
	suite="${dist##*/}"
	suite="${suite%-*}"
	if ! is_devel "$suite" && release_changed "$suite"; then
		background chdist_pids chdist apt-get "${dist##*/}" update >/dev/null
		chdists=$(($chdists + 1))
	fi
	if [ "$chdists" = 7 ]; then
		background_wait chdist_pids
		chdists=0
	fi
done
background_wait chdist_pids

if release_changed "$DEVEL"; then
	background pids cron.NBS
fi

nbs_rtm () {
	DISTRIBUTION=ubuntu-rtm RELEASE="$1" \
		OUTDIR="$HOME/public_html/NBS-RTM" \
		OUTFILE="$HOME/public_html/nbs-rtm.html" \
		cron.NBS
}
if release_changed "$DEVEL_RTM"; then
	background pids nbs_rtm "$DEVEL_RTM"
fi

if release_changed "$DEVEL" || release_changed "$DEVEL-proposed"; then
	# Do an extra germinate run so that we can run component-mismatches
	# against -proposed.  (We can't do this as part of LP archive
	# publishing because that would probably cause us to break our
	# 30-minute window.)
	background pids \
		env PYTHONPATH="$HOME/ubuntu-archive-tools:$HOME/germinate" \
		extra-germinate -o "$HOME/extra-germinate" ubuntu
fi

background_wait pids

rsync -aq \
	--include germinate.output \
	--exclude _\* --exclude \*.new --include "*_${DEVEL}_*" \
	--exclude \* --delete --delete-excluded \
	ftpmaster.internal::ubuntu-germinate/ "$GERMINATE/"

collect_mtimes new

if germinate_changed; then
	# Give germinate a two minute window to stop spewing to output
	# and assume it's finished, this should be more than enough time,
	# given that it outputs nearly constantly when run, and completes
	# in under three minutes, on average
	NEW_GERMINATE_MTIME="$(mtime new "$GERMINATE/germinate.output")"
	if [ $(($(date +%s) - $NEW_GERMINATE_MTIME)) -gt 120 ]; then
		component_mismatches () {
			local name="$1"
			shift
			component-mismatches \
				-d "$OUT/$name.dot" -o "$OUT/$name.txt.new" \
				--html-output-file "$OUT/$name.html" \
				--csv-file "$OUT/$name.csv" \
				"$@"
			if [ "$name" = component-mismatches ]; then
				process-component-mismatches-diff \
					"$OUT/$name.txt" "$OUT/$name.txt.new"
			fi
			mv "$OUT/$name.txt.new" "$OUT/$name.txt"
			dot -Tsvg -Gdpi=55 -o "$OUT/$name.svg" "$OUT/$name.dot"
		}
		background pids component_mismatches component-mismatches
		background pids component_mismatches component-mismatches-proposed \
			-s "$DEVEL-proposed" \
			--germinate-path "$HOME/extra-germinate"
		background pids priority-mismatches \
			-o "$OUT/priority-mismatches.txt" \
			--html-output-file "$OUT/priority-mismatches.html" \
			--csv-file "$OUT/priority-mismatches.csv"
		background pids architecture-mismatches \
			-o "$OUT/architecture-mismatches.txt" \
			--html-output-file "$OUT/architecture-mismatches.html" \
			--csv-file "$OUT/architecture-mismatches.csv"

		background_wait pids
	else
		# Artifically bump $GERMINATE/germinate.output into the past
		touch -d @$(($NEW_GERMINATE_MTIME - 1)) $GERMINATE/germinate.output
	fi
fi