1 #!/usr/bin/sudo /bin/sh
3 RPMS_FROM="$HOME/rpm/cleanRPMS.repo"
5 SRC="-n th-x86_64-test"
7 CACHEDIR="$PWD/poldekcache"
11 ignore() { IGNORE="$IGNORE $*"; }
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.
19 BUILDDIR=/usr/src/BUILD
21 [ -r .cleanbuildrc ] && . ./.cleanbuildrc
23 [ -z "$USER" ] && echo "USER not defined" && exit 1
24 [ "$USER" == "root" ] && echo "USER must not be root" && exit 1
31 [ $# -gt 0 ] && echo "$*"
33 echo " ./cleanbuild [cleanbuild options] specname [builder options]"
34 echo " ./build [cleanbuild options] specname [builder options]"
35 echo " ./clean [cleanbuild options]"
36 echo " ./create [cleanbuild options]"
37 echo " ./install [cleanbuild options] packages"
39 echo "cleanbuild options:"
40 echo " -32, -64, -th-i486 - select architecture"
41 echo " --cleanafter | -ca - clean after build"
42 echo " --forceumount | -fu - force umount tmpfs"
43 echo " --debug - enable debug"
44 echo " -a, -b, -c, -d, -e - select alternative chroot directory"
81 while [ $# -gt 0 ]; do
84 -32) OPT="-th-i686" ;;
85 -64) OPT="-th-x86_64" ;;
86 -th-32) OPT="-th-i686" ;;
87 -th-64) OPT="-th-x86_64" ;;
88 -ti-32) OPT="-ti-i686" ;;
89 -ti-64) OPT="-ti-x86_64" ;;
90 -ac) OPT="-ac-amd64" ;;
91 -ac-32) OPT="-ac-i586" ;;
92 -ac-64) OPT="-ac-amd64" ;;
97 -th-i[46]86 | -th-x86_64)
101 -th-i[46]86-test | -th-x86_64-test)
105 -ti-i[56]86 | -ti-x86_64)
109 -ti-i[56]86-test | -ti-x86_64-test)
113 -ac-amd64 | -ac-i[356]86 | -ac-athlon)
140 [ $# -ne 0 ] || usage
142 build_pkg="${build_pkg%/}"
143 build_pkg="${build_pkg%.spec}"
144 build_pkg="${build_pkg#*/}"
152 CHNAME="chroot-$DEST$SUFFIX"
154 CHHOME="/home/users/$USER"
158 echo -n -e "\033[31;1m" >&2
160 echo -e "\033[0m" >&2
173 echo -n -e "\033[32m"
181 local msg="$CHNAME: $build_pkg: $*"
184 echo -ne "\033]1;$msg\007\033]2;$msg\007" >&2
187 echo -ne "\033]0;$msg\007" >&2
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"
207 for D in installed buildlogs $CACHEDIR; do
208 if [ ! -d "$D" ]; then
210 su $USER -c "mkdir -p $D" || die 13 "Cannot create work directories"
217 xorg-driver-video-fglrx\* xorg-driver-video-nvidia\* xorg-xserver-xgl-libGL \
222 anacron fcron hc-cron \
223 masqmail msmtp-sendmail omta postfix sendmail ssmtp nail-mail nullmailer \
226 gnome-speech-driver-festival gnome-speech-driver-speech-dispatcher
231 $NOREBUILDDB || rpm --root=$CHDIR --rebuilddb
238 /usr/bin/poldek $SRC -s "$RPMS_FROM" -r "$CHDIR" "--cachedir=$CACHEDIR" --conf=$PWD/poldekconf/poldek.conf "$@"
244 for DIR in $CHHOME/rpm $CHHOME dev proc sys; do
245 [ -d $CHDIR/$DIR ] && umount $CHDIR/$DIR
252 if $FORCE_UMOUNT; then
254 [ "$CHDIR" ] || exit 1
255 [ -d "$CHDIR" ] || exit 1
266 info "Cleaning $CHNAME"
267 title "cleaning chroot"
274 title "preparing chroot"
278 mount -t tmpfs -o size=8G,relatime /dev/null $CHDIR
279 echo $$ > $CHDIR/.pid
281 rpm --root=$CHDIR --initdb
283 poldek -O "ignore=$IGNORE" -u rpm-build pwdutils coreutils
285 for DIR in dev proc sys; do
286 # We need to create these directories manually, because they are marked
287 # as netsharedpath in cleanbuild poldek.conf
289 mount -o bind /$DIR $CHDIR/$DIR
292 chroot $CHDIR useradd -m $USER -u$(id $USER -u)
294 # replicate files which already belong to $USER
295 # so they will have correct owner and permissions
296 cp -a $CHDIR/$CHHOME/{tmp,rpm}
297 cp -a $CHDIR/$CHHOME/tmp $CHDIR$BUILDDIR
299 cp -a $CHDIR/$CHHOME/{.bashrc,.rpmmacros}
300 cat <<-EOM > $CHDIR/$CHHOME/.rpmmacros
302 %buildroot %{_builddir}/%{name}-%{version}-root-%(id -u -n)
303 %_rpmdirname cleanRPMS
304 %_rpmdir %{expand:%%global _rpmdir %([ -d %{_topdir}/../%{_rpmdirname} ] && (cd %{_topdir}/../%{_rpmdirname}; pwd) || echo %{_topdir}/%{_rpmdirname})}%_rpmdir
305 %distribution CleanPLD
306 %_binary_payload w1.gzdio
308 [ -z "$RPMMACROS" ] || echo "$RPMMACROS" >> $CHDIR/$CHHOME/.rpmmacros
310 cp -a $CHDIR/$CHHOME/{.bashrc,.builderrc}
311 cat <<-'EORC' > $CHDIR/$CHHOME/.builderrc
314 [ -z "$BUILDERRC" ] || echo "$BUILDERRC" >> $CHDIR/$CHHOME/.builderrc
322 mount -o bind $HOME/rpm $CHDIR/$CHHOME/rpm
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
343 echo "*** $build_pkg $(date --rfc-3339=seconds) ***" >> $LIST
344 print_installed echo >> $LIST
358 addlist "ERROR_$LIST"
367 [ -n "$I" ] || return 1
368 # Installing same packets second time
369 [ "$LAST_INSTALL" != "$I" ] || return 1
373 poldek -O "ignore=$IGNORE" -u $I | tee $$.poldek_install
375 if grep -q "Preparing... ##################################################" $$.poldek_install \
376 && ! grep -q "file .* from install of .* conflicts with file from package" $$.poldek_install
378 info "Poldek:" $I "installed"
380 elif grep -q "Nothing to do" $$.poldek_install; then
381 warn "Poldek:" $I "installed already"
385 [ -n "$ret" ] && return $ret
388 poldek -u $I && return 0
389 poldek -u $I && return 0
390 warn "Poldek:" "Could not install" $I
396 local cond="$1"; shift
397 local func="$1"; shift
399 [ $cond == "false" ] && return
401 [ $cond == "exit_after" ] && exit
406 info "Fetching $build_pkg"
409 su $USER -c "$HOME/rpm/packages/builder -g $build_pkg $builder_options" \
410 || die 11 "Fetch failed"
416 su $USER -c "poldek -s $RPMS_FROM --mkidx"
418 if [ ! -d $CHDIR ]; then
419 info "Preparing $CHNAME"
426 maybe_call $FETCH fetch
430 maybe_call $CLEAN clean
432 maybe_call $CREATE create
434 echo $$ > $CHDIR/.pid
436 maybe_call $INSTALL poldek_install "$*"
440 if [ -p /tmp/fixfreq ]; then
441 echo $$ > /tmp/fixfreq
445 info "Building $build_pkg in $CHNAME"
447 find $CHDIR/usr/lib{,64} -name "*.la" -print0 | \
448 xargs -0 -r sed -i -e "s@dependency_libs=.*@dependency_libs=' '@"
449 buildlog="buildlogs/$build_pkg"
450 if [ -r $buildlog ]; then
452 while [ -r $buildlog.$i ]; do
455 info "moving $buildlog to $buildlog.$i"
456 mv $buildlog $buildlog.$i
458 ./findunusedbr -c $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
460 { chroot $CHDIR su $USER -c "$CHHOME/rpm/packages/builder -nn -bb $build_pkg $builder_options" < /dev/null 2>&1; echo $? > ecode; } | tee $buildlog
465 if grep -q "error: Failed build dependencies:" $buildlog; then
466 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 }')
467 INSTALL=$(poldek -O "ignore=$IGNORE" --shcmd="$SEARCH" | awk '{ if ( p ) { print; p = 0; } } / package\(s\) found:$/ { p = 1 }' | sed 's/^\(.*\)-.*-.*$/\1/' | sort -u)
469 if poldek_install "$INSTALL"; then
470 info "Deps installed"
473 addlist ERROR_BRINSTALL
474 die 4 "Cannot install BRs"
478 ./findbr $CHDIR/$BUILDDIR $buildlog > $$.installed
479 installed_something=false
480 while read pkg msg; do
481 if poldek_install $pkg; then
482 info "findbr:" $pkg "installed"
483 echo "$pkg $msg" >> installed/$build_pkg
484 ./addbr $build_pkg "$pkg" "$msg"
485 installed_something=true
487 warn "findbr:" $pkg "not installed"
491 $installed_something && continue
493 if [ $ECODE -eq 0 ]; then
496 ./findunusedbr $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
497 info "$build_pkg built OK !"
501 builddie UNKNOWN 1 "Got error but dunno what to do !"
506 # vim: ts=4 sw=4 filetype=sh