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
149 CHNAME="chroot-$DEST$SUFFIX"
151 CHHOME="/home/users/$USER"
155 echo -n -e "\033[31;1m" >&2
157 echo -e "\033[0m" >&2
170 echo -n -e "\033[32m"
178 local msg="$CHNAME: $build_pkg: $*"
181 echo -ne "\033]1;$msg\007\033]2;$msg\007" >&2
184 echo -ne "\033]0;$msg\007" >&2
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"
204 for D in installed buildlogs $CACHEDIR; do
205 if [ ! -d "$D" ]; then
207 su $USER -c "mkdir -p $D" || die 13 "Cannot create work directories"
214 xorg-driver-video-fglrx\* xorg-driver-video-nvidia\* xorg-xserver-xgl-libGL \
219 anacron fcron hc-cron \
220 masqmail msmtp-sendmail omta postfix sendmail ssmtp nail-mail nullmailer \
223 gnome-speech-driver-festival gnome-speech-driver-speech-dispatcher
228 $NOREBUILDDB || rpm --root=$CHDIR --rebuilddb
235 /usr/bin/poldek $SRC -s "$RPMS_FROM" -r "$CHDIR" "--cachedir=$CACHEDIR" --conf=$PWD/poldekconf/poldek.conf "$@"
241 for DIR in $CHHOME/rpm $CHHOME dev proc sys; do
242 [ -d $CHDIR/$DIR ] && umount $CHDIR/$DIR
249 if $FORCE_UMOUNT; then
251 [ "$CHDIR" ] || exit 1
252 [ -d "$CHDIR" ] || exit 1
263 info "Cleaning $CHNAME"
264 title "cleaning chroot"
271 title "preparing chroot"
275 mount -t tmpfs -o size=8G,relatime /dev/null $CHDIR
276 echo $$ > $CHDIR/.pid
278 rpm --root=$CHDIR --initdb
280 poldek -O "ignore=$IGNORE" -u rpm-build pwdutils coreutils
282 for DIR in dev proc sys; do
283 # We need to create these directories manually, because they are marked
284 # as netsharedpath in cleanbuild poldek.conf
286 mount -o bind /$DIR $CHDIR/$DIR
289 chroot $CHDIR useradd -m $USER -u$(id $USER -u)
291 # replicate files which already belong to $USER
292 # so they will have correct owner and permissions
293 cp -a $CHDIR/$CHHOME/{tmp,rpm}
294 cp -a $CHDIR/$CHHOME/tmp $CHDIR$BUILDDIR
296 cp -a $CHDIR/$CHHOME/{.bashrc,.rpmmacros}
297 cat <<-EOM > $CHDIR/$CHHOME/.rpmmacros
299 %buildroot %{_builddir}/%{name}-%{version}-root-%(id -u -n)
300 %_rpmdirname cleanRPMS
301 %_rpmdir %{expand:%%global _rpmdir %([ -d %{_topdir}/../%{_rpmdirname} ] && (cd %{_topdir}/../%{_rpmdirname}; pwd) || echo %{_topdir}/%{_rpmdirname})}%_rpmdir
302 %distribution CleanPLD
303 %_binary_payload w1.gzdio
305 [ -z "$RPMMACROS" ] || echo "$RPMMACROS" >> $CHDIR/$CHHOME/.rpmmacros
307 cp -a $CHDIR/$CHHOME/{.bashrc,.builderrc}
308 cat <<-'EORC' > $CHDIR/$CHHOME/.builderrc
311 [ -z "$BUILDERRC" ] || echo "$BUILDERRC" >> $CHDIR/$CHHOME/.builderrc
319 mount -o bind $HOME/rpm $CHDIR/$CHHOME/rpm
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
340 echo "*** $build_pkg $(date --rfc-3339=seconds) ***" >> $LIST
341 print_installed echo >> $LIST
355 addlist "ERROR_$LIST"
364 [ -n "$I" ] || return 1
365 # Installing same packets second time
366 [ "$LAST_INSTALL" != "$I" ] || return 1
370 poldek -O "ignore=$IGNORE" -u $I | tee $$.poldek_install
372 if grep -q "Preparing... ##################################################" $$.poldek_install \
373 && ! grep -q "file .* from install of .* conflicts with file from package" $$.poldek_install
375 info "Poldek:" $I "installed"
377 elif grep -q "Nothing to do" $$.poldek_install; then
378 warn "Poldek:" $I "installed already"
382 [ -n "$ret" ] && return $ret
385 poldek -u $I && return 0
386 poldek -u $I && return 0
387 warn "Poldek:" "Could not install" $I
393 local cond="$1"; shift
394 local func="$1"; shift
396 [ $cond == "false" ] && return
398 [ $cond == "exit_after" ] && exit
403 info "Fetching $build_pkg"
406 su $USER -c "$HOME/rpm/packages/builder -g $build_pkg $builder_options" \
407 || die 11 "Fetch failed"
413 su $USER -c "poldek -s $RPMS_FROM --mkidx"
415 if [ ! -d $CHDIR ]; then
416 info "Preparing $CHNAME"
423 maybe_call $FETCH fetch
427 maybe_call $CLEAN clean
429 maybe_call $CREATE create
431 echo $$ > $CHDIR/.pid
433 maybe_call $INSTALL poldek_install "$*"
437 if [ -p /tmp/fixfreq ]; then
438 echo $$ > /tmp/fixfreq
442 info "Building $build_pkg in $CHNAME"
444 buildlog="buildlogs/$build_pkg"
445 if [ -r $buildlog ]; then
447 while [ -r $buildlog.$i ]; do
450 info "moving $buildlog to $buildlog.$i"
451 mv $buildlog $buildlog.$i
453 ./findunusedbr -c $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
455 { chroot $CHDIR su $USER -c "$CHHOME/rpm/packages/builder -nn -bb $build_pkg $builder_options" < /dev/null 2>&1; echo $? > ecode; } | tee $buildlog
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)
464 if poldek_install "$INSTALL"; then
465 info "Deps installed"
468 addlist ERROR_BRINSTALL
469 die 4 "Cannot install BRs"
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
482 warn "findbr:" $pkg "not installed"
486 $installed_something && continue
488 if [ $ECODE -eq 0 ]; then
491 ./findunusedbr $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
492 info "$build_pkg built OK !"
496 builddie UNKNOWN 1 "Got error but dunno what to do !"
501 # vim: ts=4 sw=4 filetype=sh