forked from openSUSE/openSUSE-release-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish_distro
executable file
·293 lines (262 loc) · 6.96 KB
/
publish_distro
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
#!/bin/bash
#
# The script is executed periodically by cronjob
# as part of ~mirror/bin/publish_factory_leap wrapper on pontifex
#
# Tool publises data from stage (/src/ftp-stage) to public (/srv/ftp - download.opensuse.org)
#
# Configuration lives in openSUSE-release-tools.git/publish_distro_conf
# Syntax: ./publish_distro config_file
#
# no --delete built in
# number of hours to delay publishing when new isos arrive
PUBLISH_DELAY=2
# force publish even if isos appear to be synced already
force=
# used for cleanup
date='now'
# set to echo for dry run
dryrun=
# cleanup instead of sync
do_cleanup=
# url with snapshot changes app
diff_url_base="https://openqa.opensuse.org/snapshot-changes/opensuse"
changes_dir_base="/srv/www-local/snapshot-changes"
repos=("oss" "non-oss")
extra_repos=("source" "debug")
isodir="iso"
get_version() {
exit 1
}
get_iso() {
exit 1
}
get_iso_link() {
exit 1
}
get_diff_url() {
exit 1
}
get_mark_published_url() {
exit 1
}
get_changes_filename() {
exit 1
}
# --dry and --cleanup should not be passed to rsync through $@
# config file and possibly other opts including --force need to be
for arg; do
shift
if [ "$arg" == '--force' ]; then
force=1
newargs+=("$arg")
shift
continue
elif [ "$arg" == '--dry' ]; then
dryrun=echo
shift
continue
elif [ "$arg" == '--cleanup' ]; then
do_cleanup=1
date="90 days ago"
continue
elif [ "$arg" == '--now' ]; then
PUBLISH_DELAY=0
shift
continue
else
newargs+=("$arg")
fi
done
# set newargs as $@
set -- "${newargs[@]}"
. "$1" || {
echo "need to specify config file" >&2
exit 1
}
shift
stage="/srv/ftp-stage/pub/opensuse/$path"
dest="/srv/ftp/pub/opensuse/$path"
if [ ! -e "$stage" -o ! -e "$dest" ]; then
echo "stage ($stage) and/or dest ($dest) doesn't exist" >&2
exit 1
fi
if [ -n "$do_cleanup" ]; then
# find newest delete log of that day
deletelog=$(ls -1tr ${deletelog%/*}/*-deletes.log | tail -1)
test -n "$deletelog" || exit 1
(
df -h /srv
for i in $(awk '/\*deleting .*/ { print $2}' $deletelog); do
if [ -e "$stage/$i" ]; then
echo "WARNING: $i still exist in stage, not deleting"
else
$dryrun rm -rvf "$dest/$i"
fi
done
df -h /srv
) >$deletelog-deleted
exit 0
fi
mkdir -p "${synclog%/*}" "${deletelog%/*}"
if test -f $synclog; then
old $synclog
fi
if test -f $deletelog; then
old $deletelog
fi
version=
do_sync_isos=1
for flavor in "${flavors[@]}"; do
get_version
get_iso
get_diff_url
get_changes_filename
if [ -z "$force" -a -e "$dest/$isodir/$iso" ]; then
if [ -t 1 ]; then # only log to tty
echo "$iso already published, skipping isos"
fi
do_sync_isos=0
break
fi
if [ -n "$changes" ]; then
if [ -d "$stage/$changes" ]; then
# new way, use the obs generated changelogs
$dryrun rsync -avvhiH $stage/$changes \
--link-dest=$stage \
$dest/$changes $dry_delete "$@" |
LC_ALL=C grep -v '^\.[fdL] ' |
LC_ALL=C grep -v '^\(sending\|delta\)' |
tee -a $log
else
# old way (already broken?)
if [ ! -s "$changes" ]; then
echo "generating $changes" | tee -a $synclog
[ -z "$dryrun" ] || changes=/dev/stdout
$dryrun curl -sf "$url" >$changes
fi
if [ ! -e $stage/$isodir/$changes ]; then
$dryrun cp -v $changes $stage/$isodir | tee -a $synclog
[ -e $stage/$isodir/Changes ] || $dryrun ln -sf . $stage/$isodir/Changes 2>&1 | tee -a $synclog
fi
fi
fi
if [ ! -e "$stage/$isodir/$iso" ]; then
echo "$flavor with $version doesn't exist, skipping isos" | tee -a $synclog
do_sync_isos=0
break
else
get_iso_link
if [ "$(readlink $link)" != "$iso" ]; then
$dryrun ln -sf "$iso" "$link"
$dryrun ln -sf "$iso.sha256" "$link.sha256"
fi
if [ -z "$force" ]; then
if test $(date -d "$PUBLISH_DELAY hours ago" +%s) -lt $(stat -c "%Z" "$stage/$isodir/$iso"); then
echo "$iso was created less than $PUBLISH_DELAY hours ago, delay publishing" | tee -a $synclog
do_sync_isos=0
fi
fi
fi
done
# produce directories stamped with build number
for r in "${repos[@]/#//repo/}"; do
for i in /suse/setup /boot; do
d="$stage$r$i"
[ -d "$d" ] || continue
if [ -e "$stage$r/media.1/build" ]; then
read build <"$stage$r/media.1/build"
stamp="${build#*Build}"
if [ "$build" = "$stamp" ]; then
echo "ERROR: build id not parsable: $build. not syncing"
do_sync_isos=0
break 2
fi
elif [ -e "$stage$r/media.1/media" ]; then
{
read dummy
read build
} <"$stage$r/media.1/media"
stamp="${build#*Build}"
if [ "$build" = "$stamp" ]; then
echo "ERROR: build id not parsable: $build. not syncing"
do_sync_isos=0
break 2
fi
else
echo "ERROR: repo $r is missing build id, not syncing"
do_sync_isos=0
break 2
fi
stamped="$stage$r${i%/*}/$stamp-${i##*/}"
if [ ! -L "$d" ]; then
$dryrun mv "$d" "$stamped"
$dryrun ln -s "${stamped##*/}" "$d"
echo "current $stamp" | $dryrun tee $stage/$r/.current.txt
fi
done
done
if [ "$do_sync_isos" = 0 ]; then
if [ -t 1 ]; then
echo "nothing to do"
fi
exit 0
fi
# scan mirrors before making the files visible
#mb scan -q -a -d /tumbleweed
TODO=()
#if [ "$do_sync_isos" = 1 ]; then
TODO+=(iso)
echo "current $version" | $dryrun tee $stage/$isodir/.current.txt
#fi
if [ -n "$repos" ]; then
TODO+=(repo)
TODO+=(DELETE_repo)
fi
# a single grep -v regexp performs awfully bad (needs at least 30x so long)
# although LC_ALL=C might fix this, too
for i in "${TODO[@]}"; do
case $i in
DELETE_*)
i=${i#DELETE_}
log=$deletelog
dry_delete="--delete -n"
;;
iso) # ISOs we sync with delete
log=$synclog
dry_delete="--delete-after"
i="$isodir"
;;
*)
log=$synclog
dry_delete=""
;;
esac
echo ========== $i $dry_delete ===========
$dryrun rsync -avvhiH $stage/$i \
--link-dest=$stage \
$dest $dry_delete "$@" |
LC_ALL=C grep -v '^\.[fdL] ' |
LC_ALL=C grep -v '^\(sending\|delta\)' |
tee -a $log
done
# also sync source and debug, not bind mounted for Leap
for r in "${extra_repos[@]}"; do
stage="/srv/ftp-stage/pub/opensuse/$r/$path"
dest="/srv/ftp/pub/opensuse/$r/$path"
$dryrun rsync -avhiH $stage/ --link-dest=$stage \
$dest --delete-after "$@" | tee -a log
done
# mark published
get_mark_published_url
if [ -n "$url" ]; then
$dryrun curl -X POST -F "version=$version" "$url"
fi
#echo creating hashes
#metalink-hasher update -t /srv/metalink-hashes/srv/ftp/pub/opensuse/tumbleweed \
# -b /srv/ftp/pub/opensuse/tumbleweed \
# /srv/ftp/pub/opensuse/tumbleweed
# mb makehaskes is not needed by mirrorcache (replaced mirrorbrain)
#$dryrun /usr/bin/mb makehashes -b /srv/ftp/pub/opensuse \
# -t /srv/metalink-hashes/srv/ftp/pub/opensuse \
# $dest