]> git.pld-linux.org Git - projects/cleanbuild.git/blame - cleanbuild
- "GCONF_SCHEMAS_INSTALL" => "GConf2-devel"
[projects/cleanbuild.git] / cleanbuild
CommitLineData
82208ca0 1#!/usr/bin/sudo /bin/sh
2
82208ca0 3RPMS_FROM="$HOME/rpm/cleanRPMS.repo"
4DEST="th"
11aa2a39 5SRC="-n th-x86_64-test"
82208ca0 6SUFFIX=""
7CACHEDIR="$PWD/poldekcache"
08b388ad 8RPMMACROS=""
9BUILDERRC=""
febc90ba 10IGNORE=""
3cb48d43 11ignore() { IGNORE="$IGNORE $*"; }
311d51c7 12NODEBUG=true
5e0e7403 13CLEANAFTER=false
14FORCE_UMOUNT=false
c8aae0a1 15NOREBUILDDB=true
646fa345
ER
16# Whatever you set here as value, consider that it may not be shorter than
17# /usr/lib/debug (or /usr/src/debug) for debuginfo to work.
18# You get "Only dest dir longer than base dir not supported" error otherwise.
19BUILDDIR=/usr/src/BUILD
82208ca0 20
cca1186a 21[ -r .cleanbuildrc ] && . ./.cleanbuildrc
22
23[ -z "$USER" ] && echo "USER not defined" && exit 1
24[ "$USER" == "root" ] && echo "USER must not be root" && exit 1
82208ca0 25
26export LC_ALL=C
27unset LANGUAGE
28unset LANG
29
30usage() {
31 [ $# -gt 0 ] && echo "$*"
32 echo "Usage:"
33 echo " ./cleanbuild [cleanbuild options] specname [builder options]"
34 echo " ./build [cleanbuild options] specname [builder options]"
35 echo " ./clean [cleanbuild options]"
febc90ba 36 echo " ./create [cleanbuild options]"
82208ca0 37 echo " ./install [cleanbuild options] packages"
38 echo ""
39 echo "cleanbuild options:"
40 echo " -32, -64, -th-i486 - select architecture"
91d5d67b 41 echo " --cleanafter | -ca - clean after build"
5e0e7403 42 echo " --forceumount | -fu - force umount tmpfs"
91d5d67b 43 echo " --debug - enable debug"
3cc55bb0 44 echo " -a, -b, -c, -d, -e - select alternative chroot directory"
82208ca0 45 exit 1
46}
47
48FETCH=false
49CLEAN=false
febc90ba 50CREATE=false
82208ca0 51BUILD=false
52INSTALL=false
82208ca0 53
54case "$0" in
febc90ba 55 *clean)
56 CLEAN=exit_after
57 ;;
82208ca0 58 *cleanbuild)
59 FETCH=true
60 CLEAN=true
febc90ba 61 CREATE=true
82208ca0 62 BUILD=true
63 ;;
82208ca0 64 *build)
febc90ba 65 CREATE=true
82208ca0 66 BUILD=true
67 ;;
febc90ba 68 *create)
82208ca0 69 CLEAN=true
febc90ba 70 CREATE=exit_after
82208ca0 71 ;;
72 *install)
febc90ba 73 CREATE=true
74 INSTALL=exit_after
82208ca0 75 ;;
76 *)
77 usage
78 ;;
79esac
80
81while [ $# -gt 0 ]; do
82 OPT="${1}"
83 case "$OPT" in
84 -32) OPT="-th-i686" ;;
85 -64) OPT="-th-x86_64" ;;
86 -th-32) OPT="-th-i686" ;;
87 -th-64) OPT="-th-x86_64" ;;
560aa27b 88 -ti-32) OPT="-ti-i686" ;;
89 -ti-64) OPT="-ti-x86_64" ;;
82208ca0 90 -ac) OPT="-ac-amd64" ;;
91 -ac-32) OPT="-ac-i586" ;;
92 -ac-64) OPT="-ac-amd64" ;;
93 esac
94
95 V="${OPT#-}"
96 case "$OPT" in
97 -th-i[46]86 | -th-x86_64)
98 DEST="$V"
11aa2a39 99 SRC="-n $V-ready"
82208ca0 100 ;;
560aa27b 101 -th-i[46]86-test | -th-x86_64-test)
102 DEST="$V"
103 SRC="-n $V"
104 ;;
105 -ti-i[56]86 | -ti-x86_64)
106 DEST="$V"
107 SRC="-n $V-ready"
108 ;;
109 -ti-i[56]86-test | -ti-x86_64-test)
110 DEST="$V"
111 SRC="-n $V"
112 ;;
82208ca0 113 -ac-amd64 | -ac-i[356]86 | -ac-athlon)
114 DEST="$V"
11aa2a39 115 SRC="-n $V-ready"
82208ca0 116 ;;
febc90ba 117 --cleanafter | -ca)
82208ca0 118 CLEANAFTER=true
119 ;;
311d51c7 120 --debug)
121 NODEBUG=false
122 ;;
5e0e7403 123 --forceumount | -fu)
124 FORCE_UMOUNT=true
c6fcd6a8 125 ;;
3cc55bb0 126 -[a-e])
82208ca0 127 SUFFIX="$OPT"
128 ;;
129 -~*)
130 SUFFIX="$V"
131 ;;
132 *)
133 break
134 ;;
135 esac
136 shift
137done
138
139if $BUILD; then
140 [ $# -ne 0 ] || usage
141 build_pkg="${1}"
6361ea4c 142 build_pkg="${build_pkg%/}"
143 build_pkg="${build_pkg%.spec}"
144 build_pkg="${build_pkg#*/}"
82208ca0 145 shift
146
147 builder_options="$*"
148fi
149
311d51c7 150$NODEBUG || set -x
151
febc90ba 152CHNAME="chroot-$DEST$SUFFIX"
153CHDIR="$PWD/$CHNAME"
154CHHOME="/home/users/$USER"
155
156warn()
157{
82208ca0 158 echo -n -e "\033[31;1m" >&2
159 echo -n "$*" >&2
160 echo -e "\033[0m" >&2
161}
febc90ba 162
163die()
164{
82208ca0 165 code=$1
166 shift
167 warn "$*"
168 exit $code
169}
febc90ba 170
171info()
172{
82208ca0 173 echo -n -e "\033[32m"
174 echo -n "$*"
175 echo -e "\033[0m"
176}
febc90ba 177
178title()
179{
82208ca0 180 [ -t 1 ] || return 0
181 local msg="$CHNAME: $build_pkg: $*"
182 case "$TERM" in
183 cygwin|xterm*)
184 echo -ne "\033]1;$msg\007\033]2;$msg\007" >&2
185 ;;
186 screen*)
187 echo -ne "\033]0;$msg\007" >&2
188 ;;
189 esac
190 return 0
191}
192
febc90ba 193exit_after()
194{
195 return 0;
196}
82208ca0 197
febc90ba 198check_running()
199{
82208ca0 200 [ -r "$CHDIR/.pid" ] || return
201 PID=$(< "$CHDIR/.pid")
202 if [ -d /proc/$PID ]; then
203 die 10 "Another process ($PID) already running in $CHNAME"
204 fi
205}
206
82208ca0 207for D in installed buildlogs $CACHEDIR; do
208 if [ ! -d "$D" ]; then
febc90ba 209 info "mkdir $D"
82208ca0 210 su $USER -c "mkdir -p $D" || die 13 "Cannot create work directories"
211 fi
212done
213
82208ca0 214ignore \
215 vserver-packages \
216 upstart\* \
217 xorg-driver-video-fglrx\* xorg-driver-video-nvidia\* xorg-xserver-xgl-libGL \
218 xorg-data-xbitmaps \
219 compat-gcc\* \
220 libpng1\* \
932132fc 221 freetype1-devel-* \
82208ca0 222 anacron fcron hc-cron \
223 masqmail msmtp-sendmail omta postfix sendmail ssmtp nail-mail nullmailer \
224 ghostscript-esp \
225 \*-multilib-\* \
3cb48d43 226 gnome-speech-driver-festival gnome-speech-driver-speech-dispatcher
82208ca0 227
228
febc90ba 229rebuilddb()
230{
c8aae0a1 231 $NOREBUILDDB || rpm --root=$CHDIR --rebuilddb
82208ca0 232}
233
febc90ba 234poldek()
235{
311d51c7 236 $NODEBUG || set -x
82208ca0 237 rebuilddb
11aa2a39 238 /usr/bin/poldek $SRC -s "$RPMS_FROM" -r "$CHDIR" "--cachedir=$CACHEDIR" --conf=$PWD/poldekconf/poldek.conf "$@"
82208ca0 239}
240
241
febc90ba 242build_umount()
243{
82208ca0 244 for DIR in $CHHOME/rpm $CHHOME dev proc sys; do
245 [ -d $CHDIR/$DIR ] && umount $CHDIR/$DIR
246 done
247}
248
febc90ba 249build_remove_root()
250{
714fcf38 251 $NODEBUG || set -x
5e0e7403 252 if $FORCE_UMOUNT; then
c6fcd6a8 253 # safety checks.
254 [ "$CHDIR" ] || exit 1
255 [ -d "$CHDIR" ] || exit 1
256 rm -rf $CHDIR/*
257 umount -l $CHDIR
258 else
259 umount $CHDIR
260 fi
82208ca0 261 rmdir $CHDIR
262}
263
febc90ba 264clean()
265{
82208ca0 266 info "Cleaning $CHNAME"
7bf0c1e6 267 title "cleaning chroot"
82208ca0 268 build_umount
269 build_remove_root
82208ca0 270}
271
febc90ba 272build_prepare_root()
273{
7bf0c1e6 274 title "preparing chroot"
82208ca0 275 set -e
311d51c7 276 $NODEBUG || set -x
82208ca0 277 mkdir $CHDIR
11aa2a39 278 mount -t tmpfs -o size=8G,relatime /dev/null $CHDIR
82208ca0 279 echo $$ > $CHDIR/.pid
280
281 rpm --root=$CHDIR --initdb
282 poldek --up || :
11aa2a39 283 poldek -O "ignore=$IGNORE" -u rpm-build pwdutils coreutils
82208ca0 284
285 for DIR in dev proc sys; do
49e71696 286 # We need to create these directories manually, because they are marked
287 # as netsharedpath in cleanbuild poldek.conf
288 mkdir $CHDIR/$DIR
82208ca0 289 mount -o bind /$DIR $CHDIR/$DIR
290 done
291
08b388ad 292 chroot $CHDIR useradd -m $USER -u$(id $USER -u)
b259c625 293
294 # replicate files which already belong to $USER
295 # so they will have correct owner and permissions
82208ca0 296 cp -a $CHDIR/$CHHOME/{tmp,rpm}
646fa345 297 cp -a $CHDIR/$CHHOME/tmp $CHDIR$BUILDDIR
b259c625 298
82208ca0 299 cp -a $CHDIR/$CHHOME/{.bashrc,.rpmmacros}
646fa345
ER
300 cat <<-EOM > $CHDIR/$CHHOME/.rpmmacros
301 %_builddir $BUILDDIR
82208ca0 302 %buildroot %{_builddir}/%{name}-%{version}-root-%(id -u -n)
11aa2a39 303 %_rpmdirname cleanRPMS
304 %_rpmdir %{expand:%%global _rpmdir %([ -d %{_topdir}/../%{_rpmdirname} ] && (cd %{_topdir}/../%{_rpmdirname}; pwd) || echo %{_topdir}/%{_rpmdirname})}%_rpmdir
82208ca0 305 %distribution CleanPLD
306 %_binary_payload w1.gzdio
307EOM
08b388ad 308 [ -z "$RPMMACROS" ] || echo "$RPMMACROS" >> $CHDIR/$CHHOME/.rpmmacros
b259c625 309
310 cp -a $CHDIR/$CHHOME/{.bashrc,.builderrc}
82208ca0 311 cat <<-'EORC' > $CHDIR/$CHHOME/.builderrc
312 TITLECHANGE=no
313EORC
08b388ad 314 [ -z "$BUILDERRC" ] || echo "$BUILDERRC" >> $CHDIR/$CHHOME/.builderrc
315
82208ca0 316 set +e
317}
318
febc90ba 319build_mount_home()
320{
311d51c7 321 $NODEBUG || set -x
82208ca0 322 mount -o bind $HOME/rpm $CHDIR/$CHHOME/rpm
323}
324
82208ca0 325
febc90ba 326print_installed()
327{
82208ca0 328 echo=$1
329 if [ -r installed/$build_pkg ]; then
330 $echo "$(cat installed/$build_pkg | awk '{print $1}' | sort -u \
331 | awk '{br=br ", " $1} END{gsub(/^, /, "- BR: ", br ); print br}')"
332 cat installed/$build_pkg
333 fi
334}
335
febc90ba 336addlist()
337{
82208ca0 338 LIST="$1"
339
340 print_installed info
11aa2a39 341
342 return
82208ca0 343 echo "*** $build_pkg $(date --rfc-3339=seconds) ***" >> $LIST
344 print_installed echo >> $LIST
345}
346
febc90ba 347builddie()
348{
82208ca0 349 LIST="$1"; shift
350 CODE="$1"; shift
351 MSG="$*"
352
febc90ba 353 rm -f $CHDIR/.pid
354
82208ca0 355 $CLEANAFTER && clean
356 title "failed !"
357
358 addlist "ERROR_$LIST"
359 die $CODE "$MSG"
360}
361
362LAST_INSTALL=""
febc90ba 363poldek_install()
364{
82208ca0 365 I="$1";
366 # Nothing to install
367 [ -n "$I" ] || return 1
368 # Installing same packets second time
369 [ "$LAST_INSTALL" != "$I" ] || return 1
370 LAST_INSTALL="$I"
371
372 info "Installing" $I
373 poldek -O "ignore=$IGNORE" -u $I | tee $$.poldek_install
374 ret=
375 if grep -q "Preparing... ##################################################" $$.poldek_install \
376 && ! grep -q "file .* from install of .* conflicts with file from package" $$.poldek_install
377 then
378 info "Poldek:" $I "installed"
379 ret=0
380 elif grep -q "Nothing to do" $$.poldek_install; then
381 warn "Poldek:" $I "installed already"
382 ret=1
383 fi
384 rm $$.poldek_install
385 [ -n "$ret" ] && return $ret
386
387 # try harder
388 poldek -u $I && return 0
389 poldek -u $I && return 0
390 warn "Poldek:" "Could not install" $I
391 return 1
392}
393
febc90ba 394maybe_call()
395{
396 local cond="$1"; shift
397 local func="$1"; shift
398
399 [ $cond == "false" ] && return
400 $func "$@"
401 [ $cond == "exit_after" ] && exit
402}
403
404fetch()
405{
406 info "Fetching $build_pkg"
407 title "fetch"
311d51c7 408 $NODEBUG || set -x
febc90ba 409 su $USER -c "$HOME/rpm/packages/builder -g $build_pkg $builder_options" \
410 || die 11 "Fetch failed"
411}
412
413create()
414{
311d51c7 415 $NODEBUG || set -x
febc90ba 416 su $USER -c "poldek -s $RPMS_FROM --mkidx"
417
418 if [ ! -d $CHDIR ]; then
419 info "Preparing $CHNAME"
420 build_prepare_root
421 build_mount_home
422 fi
423}
424
425
426maybe_call $FETCH fetch
427
428check_running
429
430maybe_call $CLEAN clean
431
432maybe_call $CREATE create
433
434echo $$ > $CHDIR/.pid
435
436maybe_call $INSTALL poldek_install "$*"
437
438$BUILD || exit
439
440if [ -p /tmp/fixfreq ]; then
441 echo $$ > /tmp/fixfreq
82208ca0 442fi
443
444while true; do
445 info "Building $build_pkg in $CHNAME"
446 rebuilddb
447 buildlog="buildlogs/$build_pkg"
448 if [ -r $buildlog ]; then
449 i=1
450 while [ -r $buildlog.$i ]; do
451 i=$((i+1))
452 done
453 info "moving $buildlog to $buildlog.$i"
454 mv $buildlog $buildlog.$i
455 fi
11aa2a39 456 ./findunusedbr -c $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
82208ca0 457 title "building"
20fda3e4 458 { chroot $CHDIR su $USER -c "$CHHOME/rpm/packages/builder -nn -bb $build_pkg $builder_options" < /dev/null 2>&1; echo $? > ecode; } | tee $buildlog
82208ca0 459
460 ECODE=$(< ecode)
461 rm -f ecode
462
463 if grep -q "error: Failed build dependencies:" $buildlog; then
464 SEARCH=$(cat $buildlog | awk '/^Error:/ { p = 0 }; { if ( p ) { f="p"; if ( $1 ~ /^\// ) f="f"; printf "search -%c %s; ", f, $1; } }; /error: Failed build dependencies:/ { p = 1 }')
465 INSTALL=$(poldek -O "ignore=$IGNORE" --shcmd="$SEARCH" | awk '{ if ( p ) { print; p = 0; } } / package\(s\) found:$/ { p = 1 }' | sed 's/^\(.*\)-.*-.*$/\1/' | sort -u)
466
467 if poldek_install "$INSTALL"; then
468 info "Deps installed"
469 continue
470 else
471 addlist ERROR_BRINSTALL
472 die 4 "Cannot install BRs"
473 fi
474 fi
475
f34b364a 476 ./findbr $CHDIR/$BUILDDIR $buildlog > $$.installed
82208ca0 477 installed_something=false
478 while read pkg msg; do
479 if poldek_install $pkg; then
480 info "findbr:" $pkg "installed"
481 echo "$pkg $msg" >> installed/$build_pkg
482 ./addbr $build_pkg "$pkg" "$msg"
483 installed_something=true
484 else
485 warn "findbr:" $pkg "not installed"
486 fi
487 done < $$.installed
488 rm -f $$.installed
489 $installed_something && continue
490
491 if [ $ECODE -eq 0 ]; then
492 $CLEANAFTER && clean
493 addlist BUILT_OK
11aa2a39 494 ./findunusedbr $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
82208ca0 495 info "$build_pkg built OK !"
496 title "OK !"
497 exit 0
498 else
499 builddie UNKNOWN 1 "Got error but dunno what to do !"
500 fi
501done
502
503
504# vim: ts=4 sw=4 filetype=sh
This page took 0.089187 seconds and 4 git commands to generate.