~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
#! /bin/sh
set -e

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

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

MIRROR="$HOME/mirror/ubuntu"
GERMINATE="$HOME/mirror/ubuntu-germinate"
OUT="$HOME/public_html"

mtimes="$(mktemp -d)"

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

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

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

release_changed () {
	mtime_changed "$MIRROR/dists/$1/Release"
}

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

PIDS=
background () {
	"$@" &
	PIDS="${PIDS:+$PIDS }$!"
}

background_wait () {
	for pid in $PIDS; do
		wait "$pid"
	done
	PIDS=
}

collect_mtimes old

rsync -a \
	--exclude dapper\* --exclude edgy\* --exclude feisty\* \
	--exclude gutsy\* --exclude hardy\* --exclude intrepid\* \
	--exclude jaunty\* --exclude karmic\* --exclude maverick\* \
	--exclude natty\* --exclude oneiric\* \
	--include Packages\* --include Sources\* --include Release\* \
	--include udeb.list --include \*\*/installer-\*/current \
	--include \*\*/saucy/Contents-\* \
	--include \*/ --exclude \* --delete --prune-empty-dirs \
	ftpmaster.internal::ubuntu-dists/ "$MIRROR/dists/"

collect_mtimes new

for dist in "$HOME/.chdist"/*; do
	[ -d "$dist" ] || continue
	suite="${dist##*/}"
	suite="${suite%-mainonly}"
	suite="${suite%-*}"
	if release_changed "$suite"; then
		background chdist apt-get "${dist##*/}" update >/dev/null
	fi
done
background_wait

if release_changed saucy; then
	background run-britney

	background cron.NBS
fi

if release_changed saucy || release_changed saucy-proposed; then
	background run-proposed-migration
fi

if release_changed saucy-proposed; then
	rsync -a --delete --prune-empty-dirs \
		"$MIRROR/dists/saucy/" \
		/srv/chroots/lucid-transitions/srv/transitions/mirror/ubuntu/dists/saucy/
	rsync -a --delete --prune-empty-dirs \
		"$MIRROR/dists/saucy-proposed/" \
		/srv/chroots/lucid-transitions/srv/transitions/mirror/ubuntu/dists/saucy-proposed/

	background update-transitions
fi

if release_changed saucy || release_changed saucy-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 \
		env PYTHONPATH="$HOME/ubuntu-archive-tools:$HOME/germinate" \
		extra-germinate -o "$HOME/extra-germinate" ubuntu
fi

background_wait

rsync -a \
	--include germinate.output \
	--exclude _\* --include \*_saucy_\* \
	--exclude \* --delete \
	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" \
				"$@"
			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 component_mismatches component-mismatches
		background component_mismatches component-mismatches-proposed \
			-s saucy-proposed \
			--germinate-path "$HOME/extra-germinate"
		background priority-mismatches -o "$OUT/priority-mismatches.txt"
		background architecture-mismatches -o "$OUT/architecture-mismatches.txt"

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