]> git.pld-linux.org Git - projects/cleanbuild.git/blame - cleanbuild
- exclude freetyp1-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
ed51b677 15REBUILDDB=false
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}"
142 shift
143
144 builder_options="$*"
145fi
146
311d51c7 147$NODEBUG || set -x
148
febc90ba 149CHNAME="chroot-$DEST$SUFFIX"
150CHDIR="$PWD/$CHNAME"
151CHHOME="/home/users/$USER"
152
153warn()
154{
82208ca0 155 echo -n -e "\033[31;1m" >&2
156 echo -n "$*" >&2
157 echo -e "\033[0m" >&2
158}
febc90ba 159
160die()
161{
82208ca0 162 code=$1
163 shift
164 warn "$*"
165 exit $code
166}
febc90ba 167
168info()
169{
82208ca0 170 echo -n -e "\033[32m"
171 echo -n "$*"
172 echo -e "\033[0m"
173}
febc90ba 174
175title()
176{
82208ca0 177 [ -t 1 ] || return 0
178 local msg="$CHNAME: $build_pkg: $*"
179 case "$TERM" in
180 cygwin|xterm*)
181 echo -ne "\033]1;$msg\007\033]2;$msg\007" >&2
182 ;;
183 screen*)
184 echo -ne "\033]0;$msg\007" >&2
185 ;;
186 esac
187 return 0
188}
189
febc90ba 190exit_after()
191{
192 return 0;
193}
82208ca0 194
febc90ba 195check_running()
196{
82208ca0 197 [ -r "$CHDIR/.pid" ] || return
198 PID=$(< "$CHDIR/.pid")
199 if [ -d /proc/$PID ]; then
200 die 10 "Another process ($PID) already running in $CHNAME"
201 fi
202}
203
82208ca0 204for D in installed buildlogs $CACHEDIR; do
205 if [ ! -d "$D" ]; then
febc90ba 206 info "mkdir $D"
82208ca0 207 su $USER -c "mkdir -p $D" || die 13 "Cannot create work directories"
208 fi
209done
210
82208ca0 211ignore \
212 vserver-packages \
213 upstart\* \
214 xorg-driver-video-fglrx\* xorg-driver-video-nvidia\* xorg-xserver-xgl-libGL \
215 xorg-data-xbitmaps \
216 compat-gcc\* \
217 libpng1\* \
932132fc 218 freetype1-devel-* \
82208ca0 219 anacron fcron hc-cron \
220 masqmail msmtp-sendmail omta postfix sendmail ssmtp nail-mail nullmailer \
221 ghostscript-esp \
222 \*-multilib-\* \
3cb48d43 223 gnome-speech-driver-festival gnome-speech-driver-speech-dispatcher
82208ca0 224
225
febc90ba 226rebuilddb()
227{
ed51b677 228 $REBUILDDB && rpm --root=$CHDIR --rebuilddb
82208ca0 229}
230
febc90ba 231poldek()
232{
311d51c7 233 $NODEBUG || set -x
82208ca0 234 rebuilddb
11aa2a39 235 /usr/bin/poldek $SRC -s "$RPMS_FROM" -r "$CHDIR" "--cachedir=$CACHEDIR" --conf=$PWD/poldekconf/poldek.conf "$@"
82208ca0 236}
237
238
febc90ba 239build_umount()
240{
82208ca0 241 for DIR in $CHHOME/rpm $CHHOME dev proc sys; do
242 [ -d $CHDIR/$DIR ] && umount $CHDIR/$DIR
243 done
244}
245
febc90ba 246build_remove_root()
247{
714fcf38 248 $NODEBUG || set -x
5e0e7403 249 if $FORCE_UMOUNT; then
c6fcd6a8 250 # safety checks.
251 [ "$CHDIR" ] || exit 1
252 [ -d "$CHDIR" ] || exit 1
253 rm -rf $CHDIR/*
254 umount -l $CHDIR
255 else
256 umount $CHDIR
257 fi
82208ca0 258 rmdir $CHDIR
259}
260
febc90ba 261clean()
262{
82208ca0 263 info "Cleaning $CHNAME"
7bf0c1e6 264 title "cleaning chroot"
82208ca0 265 build_umount
266 build_remove_root
82208ca0 267}
268
febc90ba 269build_prepare_root()
270{
7bf0c1e6 271 title "preparing chroot"
82208ca0 272 set -e
311d51c7 273 $NODEBUG || set -x
82208ca0 274 mkdir $CHDIR
11aa2a39 275 mount -t tmpfs -o size=8G,relatime /dev/null $CHDIR
82208ca0 276 echo $$ > $CHDIR/.pid
277
278 rpm --root=$CHDIR --initdb
279 poldek --up || :
11aa2a39 280 poldek -O "ignore=$IGNORE" -u rpm-build pwdutils coreutils
82208ca0 281
282 for DIR in dev proc sys; do
49e71696 283 # We need to create these directories manually, because they are marked
284 # as netsharedpath in cleanbuild poldek.conf
285 mkdir $CHDIR/$DIR
82208ca0 286 mount -o bind /$DIR $CHDIR/$DIR
287 done
288
08b388ad 289 chroot $CHDIR useradd -m $USER -u$(id $USER -u)
b259c625 290
291 # replicate files which already belong to $USER
292 # so they will have correct owner and permissions
82208ca0 293 cp -a $CHDIR/$CHHOME/{tmp,rpm}
646fa345 294 cp -a $CHDIR/$CHHOME/tmp $CHDIR$BUILDDIR
b259c625 295
82208ca0 296 cp -a $CHDIR/$CHHOME/{.bashrc,.rpmmacros}
646fa345
ER
297 cat <<-EOM > $CHDIR/$CHHOME/.rpmmacros
298 %_builddir $BUILDDIR
82208ca0 299 %buildroot %{_builddir}/%{name}-%{version}-root-%(id -u -n)
11aa2a39 300 %_rpmdirname cleanRPMS
301 %_rpmdir %{expand:%%global _rpmdir %([ -d %{_topdir}/../%{_rpmdirname} ] && (cd %{_topdir}/../%{_rpmdirname}; pwd) || echo %{_topdir}/%{_rpmdirname})}%_rpmdir
82208ca0 302 %distribution CleanPLD
303 %_binary_payload w1.gzdio
304EOM
08b388ad 305 [ -z "$RPMMACROS" ] || echo "$RPMMACROS" >> $CHDIR/$CHHOME/.rpmmacros
b259c625 306
307 cp -a $CHDIR/$CHHOME/{.bashrc,.builderrc}
82208ca0 308 cat <<-'EORC' > $CHDIR/$CHHOME/.builderrc
309 TITLECHANGE=no
310EORC
08b388ad 311 [ -z "$BUILDERRC" ] || echo "$BUILDERRC" >> $CHDIR/$CHHOME/.builderrc
312
82208ca0 313 set +e
314}
315
febc90ba 316build_mount_home()
317{
311d51c7 318 $NODEBUG || set -x
82208ca0 319 mount -o bind $HOME/rpm $CHDIR/$CHHOME/rpm
320}
321
82208ca0 322
febc90ba 323print_installed()
324{
82208ca0 325 echo=$1
326 if [ -r installed/$build_pkg ]; then
327 $echo "$(cat installed/$build_pkg | awk '{print $1}' | sort -u \
328 | awk '{br=br ", " $1} END{gsub(/^, /, "- BR: ", br ); print br}')"
329 cat installed/$build_pkg
330 fi
331}
332
febc90ba 333addlist()
334{
82208ca0 335 LIST="$1"
336
337 print_installed info
11aa2a39 338
339 return
82208ca0 340 echo "*** $build_pkg $(date --rfc-3339=seconds) ***" >> $LIST
341 print_installed echo >> $LIST
342}
343
febc90ba 344builddie()
345{
82208ca0 346 LIST="$1"; shift
347 CODE="$1"; shift
348 MSG="$*"
349
febc90ba 350 rm -f $CHDIR/.pid
351
82208ca0 352 $CLEANAFTER && clean
353 title "failed !"
354
355 addlist "ERROR_$LIST"
356 die $CODE "$MSG"
357}
358
359LAST_INSTALL=""
febc90ba 360poldek_install()
361{
82208ca0 362 I="$1";
363 # Nothing to install
364 [ -n "$I" ] || return 1
365 # Installing same packets second time
366 [ "$LAST_INSTALL" != "$I" ] || return 1
367 LAST_INSTALL="$I"
368
369 info "Installing" $I
370 poldek -O "ignore=$IGNORE" -u $I | tee $$.poldek_install
371 ret=
372 if grep -q "Preparing... ##################################################" $$.poldek_install \
373 && ! grep -q "file .* from install of .* conflicts with file from package" $$.poldek_install
374 then
375 info "Poldek:" $I "installed"
376 ret=0
377 elif grep -q "Nothing to do" $$.poldek_install; then
378 warn "Poldek:" $I "installed already"
379 ret=1
380 fi
381 rm $$.poldek_install
382 [ -n "$ret" ] && return $ret
383
384 # try harder
385 poldek -u $I && return 0
386 poldek -u $I && return 0
387 warn "Poldek:" "Could not install" $I
388 return 1
389}
390
febc90ba 391maybe_call()
392{
393 local cond="$1"; shift
394 local func="$1"; shift
395
396 [ $cond == "false" ] && return
397 $func "$@"
398 [ $cond == "exit_after" ] && exit
399}
400
401fetch()
402{
403 info "Fetching $build_pkg"
404 title "fetch"
311d51c7 405 $NODEBUG || set -x
febc90ba 406 su $USER -c "$HOME/rpm/packages/builder -g $build_pkg $builder_options" \
407 || die 11 "Fetch failed"
408}
409
410create()
411{
311d51c7 412 $NODEBUG || set -x
febc90ba 413 su $USER -c "poldek -s $RPMS_FROM --mkidx"
414
415 if [ ! -d $CHDIR ]; then
416 info "Preparing $CHNAME"
417 build_prepare_root
418 build_mount_home
419 fi
420}
421
422
423maybe_call $FETCH fetch
424
425check_running
426
427maybe_call $CLEAN clean
428
429maybe_call $CREATE create
430
431echo $$ > $CHDIR/.pid
432
433maybe_call $INSTALL poldek_install "$*"
434
435$BUILD || exit
436
437if [ -p /tmp/fixfreq ]; then
438 echo $$ > /tmp/fixfreq
82208ca0 439fi
440
441while true; do
442 info "Building $build_pkg in $CHNAME"
443 rebuilddb
444 buildlog="buildlogs/$build_pkg"
445 if [ -r $buildlog ]; then
446 i=1
447 while [ -r $buildlog.$i ]; do
448 i=$((i+1))
449 done
450 info "moving $buildlog to $buildlog.$i"
451 mv $buildlog $buildlog.$i
452 fi
11aa2a39 453 ./findunusedbr -c $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
82208ca0 454 title "building"
20fda3e4 455 { chroot $CHDIR su $USER -c "$CHHOME/rpm/packages/builder -nn -bb $build_pkg $builder_options" < /dev/null 2>&1; echo $? > ecode; } | tee $buildlog
82208ca0 456
457 ECODE=$(< ecode)
458 rm -f ecode
459
460 if grep -q "error: Failed build dependencies:" $buildlog; then
461 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 }')
462 INSTALL=$(poldek -O "ignore=$IGNORE" --shcmd="$SEARCH" | awk '{ if ( p ) { print; p = 0; } } / package\(s\) found:$/ { p = 1 }' | sed 's/^\(.*\)-.*-.*$/\1/' | sort -u)
463
464 if poldek_install "$INSTALL"; then
465 info "Deps installed"
466 continue
467 else
468 addlist ERROR_BRINSTALL
469 die 4 "Cannot install BRs"
470 fi
471 fi
472
473 ./findbr $CHDIR/BUILD $buildlog > $$.installed
474 installed_something=false
475 while read pkg msg; do
476 if poldek_install $pkg; then
477 info "findbr:" $pkg "installed"
478 echo "$pkg $msg" >> installed/$build_pkg
479 ./addbr $build_pkg "$pkg" "$msg"
480 installed_something=true
481 else
482 warn "findbr:" $pkg "not installed"
483 fi
484 done < $$.installed
485 rm -f $$.installed
486 $installed_something && continue
487
488 if [ $ECODE -eq 0 ]; then
489 $CLEANAFTER && clean
490 addlist BUILT_OK
11aa2a39 491 ./findunusedbr $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
82208ca0 492 info "$build_pkg built OK !"
493 title "OK !"
494 exit 0
495 else
496 builddie UNKNOWN 1 "Got error but dunno what to do !"
497 fi
498done
499
500
501# vim: ts=4 sw=4 filetype=sh
This page took 0.122895 seconds and 4 git commands to generate.