blob: 8d5f66a76ca6f208c67848c118aa6f6e1747b70f (
plain)
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
#!/bin/bash
# init variables
tmpDir="$(mktemp -d /tmp/archive.XXXXXX)"
pkgDirBase="/srv/arch-mirror/arch/arch"
pkgDir="${pkgDirBase}/archlinuxewe/os"
pkgSrcDir="$(dirname $(readlink -f -n "$0"))"
[ "$(hostname)" == "rechenknecht" ] && \
[ "${pkgSrcDir}" == "${HOME}" ] && \
aufRechenknecht=true || \
aufRechenknecht=false
force=false
upload=true
updateMe=true
abortOnMakepkgError=true
cleanUnsigned=false
checkDbSig='-v'
# print help screen
usage()
{
>&2 echo ''
>&2 echo 'Skript zum Updaten der selbsterstellten Archlinux-Pakete'
>&2 echo ''
>&2 echo 'Verwendung:'
>&2 echo ' '"$0"' [ -c|--cleanUnsigned ] [ -f|--force ] [ --ignore-wrong-db-signature ] [ --no-upload ] [ --no-selfUpdate ] [ --no-abortOnMakepkgError ] [ --only $package ]'
>&2 echo ' -c|--cleanUnsigned: remove unsigned Packages first'
>&2 echo ' -f|--force: rebuild packages even if they look up to date'
>&2 echo ' --ignore-wrong-db-signature: do not verify old database signature'
>&2 echo ' --no-upload: do not upload built packages from rechenknecht to jeti100'
>&2 echo ' --no-selfUpdate: do not update this script from git'
>&2 echo ' --no-abortOnMakepkgError: do not abort when makepkg returns non-zero'
>&2 echo ' --only $package: only consider $package for build and update process'
>&2 echo ''
rm -rf "${tmpDir}"
exit 1
}
echo 'parse arguments ...'
eval set -- "$(getopt -o cf --long cleanUnsigned,force,ignore-wrong-db-signature,no-upload,no-selfUpdate,no-abortOnMakepkgError,only: -n "$(basename "$0")" -- "$@" || echo "usage")"
args=("$@")
while true
do
case $1 in
-f|--force)
echo '"force" erkannt'
force=true
;;
-c|--cleanUnsigned)
echo '"cleanUnsigned" erkannt'
cleanUnsigned=true
;;
--no-upload)
echo '"no-upload" erkannt'
upload=false
;;
--ignore-wrong-db-signature)
echo '"ignore-wrong-db-signature" erkannt'
checkDbSig=''
;;
--no-selfUpdate)
echo '"no-selfUpdate" erkannt'
updateMe=false
;;
--no-abortOnMakepkgError)
echo '"no-abortOnMakepkgError" erkannt'
abortOnMakepkgError=false
;;
--only)
shift
echo '"only" erkannt'
onlyPackages[${#onlyPackages[@]}]="$1"
;;
--)
shift
break
;;
*)
>&2 echo "FEHLER: Verstehe Option \"$1\" doch nicht! Ich beende."
rm -rf "${tmpDir}"
exit 1
esac
shift
done
if [ ! $# -eq 0 ]
then
>&2 echo 'FEHLER: Zu viele Argumente! Ich beende.'
usage
fi
echo '... done'
$aufRechenknecht && pkgSrcDir="${pkgSrcDir}/archPackages"
cd "${pkgSrcDir}"
# extract git HEAD
git archive --format tar HEAD | \
tar -x -C "${tmpDir}" -f -
cd "${tmpDir}"
# update $0
if ${updateMe} && ${aufRechenknecht} && [ -e "$(basename $0)" ] && ! diff -q "$(basename $0)" "$0" &> /dev/null
then
cp "$(basename $0)" "$0"
$0 "${args[@]}"
err=$?
rm -rf "${tmpDir}"
exit ${err}
fi
# clean unsigned packages
if ${cleanUnsigned} && ${aufRechenknecht}
then
ssh paule@127.0.0.1 '
rmPaket() {
[ "$(basename "$(pwd)")" == "any" ] || \
repo-remove '${checkDbSig}' -s -k 0x20194BA1 archlinuxewe.db.tar.gz "${1%-*-*-*.pkg.tar.xz}"
rm "$1"
[ -e "$1.sig" ] && rm "$1.sig"
}
cd "'${pkgDir}'"
for arch in *
do
[ -d "${arch}" ] || continue
cd "${arch}"
for paket in *.pkg.tar.xz
do
[ -e "${paket}.sig" ] && continue
rmPaket ${paket}
done
cd ..
done
'
fi
unset pakete
unset archs
unset verss
# collect packages
for paket in $( \
echo */PKGBUILD | \
sed "s|/PKGBUILD||g" \
)
do
[ -d "${paket}" ] || continue
[ ${#onlyPackages[@]} -eq 0 ] && consider=true || consider=false
for ((i=0; i<${#onlyPackages[@]}; i++))
do
[ "${onlyPackages[${i}]}" == "${paket}" ] && consider=true
done
${consider} || continue
. ${paket}/PKGBUILD
for singleArch in "${arch[@]}"
do
[ "${singleArch}" == "x86_64" ] || \
[ "${singleArch}" == "i686" ] || \
[ "${singleArch}" == "any" ] || \
continue
pkgFile="${paket}-${pkgver}-${pkgrel}-${singleArch}.pkg.tar.xz"
allExist=true
[ "${singleArch}" == "any" ] && \
for dir in ${pkgDir}/*
do
[ "${dir}" == "any" ] && continue
[ ! -d "${dir}" ] && continue
[ ! -e "${dir}/${pkgFile}" ] && allExist=false
done
if ${force} || \
! ${aufRechenknecht} || \
[ ! -e "${pkgDir}/${singleArch}/${pkgFile}" ] || \
! ${allExist}
then
pakete[${#pakete[@]}]="${paket}"
archs[${#archs[@]}]="${singleArch}"
verss[${#verss[@]}]="${pkgver}-${pkgrel}"
fi
done
done
if ${aufRechenknecht}
then
# check sanity of build-chroots
err=false
for chrootArch in 32 64
do
[ -d "/opt/arch${chrootArch}" ] || continue
basePakete="$(
echo '
pacman -Qg base base-devel | \
cut -d " " -f 2 | \
sort -u
exit
' | \
chrootUnpriv "${chrootArch}"
)"
explizitinstalliertePakete="$(
echo '
pacman -Qtt | \
cut -d " " -f 1
exit
' | \
chrootUnpriv "${chrootArch}"
)"
alleinstalliertenPakete="$(
echo '
pacman -Q | \
cut -d " " -f 1
exit
' | \
chrootUnpriv "${chrootArch}"
)"
zuvielePakete="$(
(
(
echo "${explizitinstalliertePakete}"
echo "${basePakete}"
) | \
sort | \
uniq -d
echo "${explizitinstalliertePakete}"
) | \
sort | \
uniq -u
)"
zuwenigePakete="$(
(
(
echo "${alleinstalliertenPakete}"
echo "${basePakete}"
) | \
sort | \
uniq -d
echo "${basePakete}"
) | \
sort | \
uniq -u
)"
if [ -n "${zuvielePakete}" ]
then
>&2 echo 'zu viele Pakete in "'/opt/arch${chrootDir}'" installiert:'
>&2 echo "${zuvielePakete}"
err=true
fi
if [ -n "${zuwenigePakete}" ]
then
>&2 echo 'zu wenige Pakete in "'/opt/arch${chrootDir}'" installiert:'
>&2 echo "${zuwenigePakete}"
err=true
fi
done
${err} && exit 1
maxErr=0
# generate current makepkg.conf and makepkg32.conf
cd "${tmpDir}"
cp /etc/makepkg.conf .
patch -p0 -i makepkgSystem.patch
cp makepkg{,32}.conf
patch -p0 -i makepkg32.patch
# build packages
for ((i=0; i<${#pakete[@]}; i++))
do
paket="${pakete[${i}]}"
arch="${archs[${i}]}"
vers="${verss[${i}]}"
cd "${tmpDir}/${paket}"
rm -f ${paket}-*-${arch}.pkg.tar.xz
if [ "${arch}" == "i686" ]
then
# 32-bit is built in chroot /opt/arch32
echo '\
sudo pacman -Sy && \
cd "'"${tmpDir}/${paket}"'" && \
_targetHost='\''--host=i686-pc-linux-gnu'\'' makepkg --config "'"${tmpDir}"'/makepkg32.conf" --sign -fcsr --noconfirm
exit $?
' | \
chrootUnpriv 32
err[${i}]=$?
else
# 64-bit is built in chroot /opt/arch64
echo '\
sudo pacman -Sy && \
cd "'"${tmpDir}/${paket}"'" && \
makepkg --config "'"${tmpDir}"'/makepkg.conf" --sign -fcsr --noconfirm
exit $?
' | \
chrootUnpriv 64
err[${i}]=$?
fi
if ${abortOnMakepkgError} && [ ${err[${i}]} -ne 0 ]
then
rm -rf "${tmpDir}"
exit ${err[${i}]}
fi
[ ${err[${i}]} -gt ${maxErr} ] && maxErr=${err[${i}]}
if ${upload} && [ ${err[${i}]} -eq 0 ]
then
# upload package and update db
cd "${tmpDir}/${paket}"
tar -cf - ${paket}-${vers}-${arch}.pkg.tar.xz{,.sig} |
ssh paule@127.0.0.1 '
rmPaket() {
[ "$(basename "$(pwd)")" == "any" ] && return
repo-remove '${checkDbSig}' -s -k 0x20194BA1 archlinuxewe.db.tar.gz "${1%-*-*-*.pkg.tar.xz}"
rm "$1"
[ -e "$1.sig" ] && rm "$1.sig"
}
addPaket() {
[ "$(basename "$(pwd)")" == "any" ] && return
neu="$1"
for alt in $(ls ${neu%-*-*-*.pkg.tar.xz}-*.pkg.tar.xz)
do
[ "${alt}" == "${neu}" ] && continue
rmPaket "${alt}"
done
repo-add '${checkDbSig}' -s -k 0x20194BA1 archlinuxewe.db.tar.gz "${neu}"
}
cd '${pkgDir}/${arch}/'
if [ -e "'${paket}-${vers}-${arch}.pkg.tar.xz'" ]
then
rmPaket "'${paket}-${vers}-${arch}.pkg.tar.xz'"
fi
tar -xf -
addPaket "'${paket}-${vers}-${arch}.pkg.tar.xz'"
if [ "'${arch}'" == "any" ]
then
cd ..
for lArch in *
do
[ ! -d "${lArch}" ] && continue
[ "${lArch}" == "any" ] && continue
cd "${lArch}"
if [ -e "'${paket}-${vers}-${arch}.pkg.tar.xz'" ]
then
rmPaket "'${paket}-${vers}-${arch}.pkg.tar.xz'"
fi
ln -s "'${pkgDir}/any/${paket}-${vers}-${arch}.pkg.tar.xz'" "'${paket}-${vers}-${arch}.pkg.tar.xz'"
if [ -e "'${pkgDir}/any/${paket}-${vers}-${arch}.pkg.tar.xz.sig'" ]
then
ln -s "'${pkgDir}/any/${paket}-${vers}-${arch}.pkg.tar.xz.sig'" "'${paket}-${vers}-${arch}.pkg.tar.xz.sig'"
fi
addPaket "'${paket}-${vers}-${arch}.pkg.tar.xz'"
cd ..
done
fi
'
fi
done
# check db
if ${upload}
then
ssh paule@127.0.0.1 '
cd '${pkgDir}'
err=0
for arch in *
do
[ ! -d "${arch}" ] && continue
[ "${arch}" == "any" ] && continue
for paketFehler in $( \
(
tar -Oxzf '${pkgDir}'/${arch}/archlinuxewe.db.tar.gz | \
grep -A1 "^%FILENAME%\$" | \
grep -v "^%FILENAME%\$" | \
grep -v -- "^--\$"
ls '${pkgDir}'/${arch} | \
grep "^.*\.pkg\.tar\.xz\$"
) | \
sort | \
uniq -u
)
do
err=1
if [ -e "'${pkgDir}'/${arch}/${paketFehler}" ]
then
>&2 echo "FEHLER: Paket '${pkgDir}'/${arch}/${paketFehler} ist entweder nur im Verzeichnisbaum vorhanden."
else
>&2 echo "FEHLER: Paket '${pkgDir}'/${arch}/${paketFehler} ist entweder nur in der Datenbank vorhanden."
fi
done
for signaturWarnungen in $( \
ls '${pkgDir}'/${arch} | \
grep "^.*\.pkg\.tar\.xz\(\.sig\)\?\$" | \
sed "s|\.sig\$||" | \
sort | \
uniq -u
)
do
if [ -e "'${pkgDir}'/${arch}/${signaturWarnungen}" ]
then
>&2 echo "WARNUNG: Paket '${pkgDir}'/${arch}/${signaturWarnungen} hat keine Signatur."
else
err=1
>&2 echo "FEHLER: Zur Signatur '${pkgDir}'/${arch}/${signaturWarnungen}.sig gibt es kein Paket."
fi
done
done
exit ${err}
'
fi
if [ ${maxErr} -ne 0 ]
then
rm -rf "${tmpDir}"
exit ${maxErr}
fi
else
namcap */PKGBUILD
# check packages
err=false
for ((i=0; i<${#pakete[@]}; i++))
do
paket="${pakete[${i}]}"
. ${paket}/PKGBUILD
if echo "${source}" | grep -q "://opensources\.eckner\.net/"
then
# one of Erich's packages
if grep -q "sha512sums" ${paket}/PKGBUILD
then
sumTyp="sha512sum"
pkgSum="${sha512sums[@]}"
elif grep -q "sha256sums" ${paket}/PKGBUILD
then
sumTyp="sha256sum"
pkgSum="${sha256sums[@]}"
fi
remSum="$(curl -o - "${source#*::}&post=${sumTyp}" 2> /dev/null)"
if [ ! "${remSum}" == "${pkgSum}" ]
then
>&2 echo "${sumTyp}s von ${pkgname} stimmt nicht: ${remSum} vs. ${pkgSum}."
err=true
fi
elif echo "${source}" | grep -q "://arch\.eckner\.net/"
then
# a modified official package
offVer="$( \
ssh paule@jeti100 'find '"${pkgDirBase}"' -type f -name "'"${paket}"'-*.pkg.tar.xz" -exec basename "{}" \; ' | \
sort -V | \
tail -n1 \
)"
if [ ! "${offVer}" == "${pkgname}-${pkgver}-${pkgrel}-${arch}.pkg.tar.xz" ]
then
>&2 echo "${pkgname} ist in den offiziellen Quellen aktueller: ${offVer}."
err=true
fi
fi
done
if ${err}
then
rm -rf "${tmpDir}"
exit 1
fi
cd "${pkgSrcDir}"
git push
err=$?
if [ ${err} -ne 0 ]
then
rm -rf "${tmpDir}"
exit ${err}
fi
ssh -p 22222 141.35.51.219 "~/archPackagesUpdate" "${args[@]}"
err=$?
if [ ${err} -ne 0 ]
then
rm -rf "${tmpDir}"
exit ${err}
fi
fi
# clean up
rm -rf "${tmpDir}"
|