1 #!/usr/bin/sudo /bin/sh
3 RPMS_FROM="$HOME/rpm/cleanRPMS.repo"
5 SRC="-n th-x86_64-test"
7 CACHEDIR="$PWD/poldekcache"
9 ignore() { IGNORE="$IGNORE $*"; }
14 [ -r .cleanbuildrc ] && . ./.cleanbuildrc
16 [ -z "$USER" ] && echo "USER not defined" && exit 1
17 [ "$USER" == "root" ] && echo "USER must not be root" && exit 1
24 [ $# -gt 0 ] && echo "$*"
26 echo " ./cleanbuild [cleanbuild options] specname [builder options]"
27 echo " ./build [cleanbuild options] specname [builder options]"
28 echo " ./clean [cleanbuild options]"
29 echo " ./create [cleanbuild options]"
30 echo " ./install [cleanbuild options] packages"
32 echo "cleanbuild options:"
33 echo " -32, -64, -th-i486 - select architecture"
34 echo " --cleanafter | -ca - clean after build"
35 echo " --forceumount | -fu - force umount tmpfs"
36 echo " --debug - enable debug"
37 echo " -a, -b, -c, -d, -e - select alternative chroot directory"
74 while [ $# -gt 0 ]; do
77 -32) OPT="-th-i686" ;;
78 -64) OPT="-th-x86_64" ;;
79 -th-32) OPT="-th-i686" ;;
80 -th-64) OPT="-th-x86_64" ;;
81 -ti-32) OPT="-ti-i686" ;;
82 -ti-64) OPT="-ti-x86_64" ;;
83 -ac) OPT="-ac-amd64" ;;
84 -ac-32) OPT="-ac-i586" ;;
85 -ac-64) OPT="-ac-amd64" ;;
90 -th-i[46]86 | -th-x86_64)
94 -th-i[46]86-test | -th-x86_64-test)
98 -ti-i[56]86 | -ti-x86_64)
102 -ti-i[56]86-test | -ti-x86_64-test)
106 -ac-amd64 | -ac-i[356]86 | -ac-athlon)
133 [ $# -ne 0 ] || usage
142 CHNAME="chroot-$DEST$SUFFIX"
144 CHHOME="/home/users/$USER"
148 echo -n -e "\033[31;1m" >&2
150 echo -e "\033[0m" >&2
163 echo -n -e "\033[32m"
171 local msg="$CHNAME: $build_pkg: $*"
174 echo -ne "\033]1;$msg\007\033]2;$msg\007" >&2
177 echo -ne "\033]0;$msg\007" >&2
190 [ -r "$CHDIR/.pid" ] || return
191 PID=$(< "$CHDIR/.pid")
192 if [ -d /proc/$PID ]; then
193 die 10 "Another process ($PID) already running in $CHNAME"
197 for D in installed buildlogs $CACHEDIR; do
198 if [ ! -d "$D" ]; then
200 su $USER -c "mkdir -p $D" || die 13 "Cannot create work directories"
207 xorg-driver-video-fglrx\* xorg-driver-video-nvidia\* xorg-xserver-xgl-libGL \
211 anacron fcron hc-cron \
212 masqmail msmtp-sendmail omta postfix sendmail ssmtp nail-mail nullmailer \
215 gnome-speech-driver-festival gnome-speech-driver-speech-dispatcher
220 #rpm --root=$CHDIR --rebuilddb
227 /usr/bin/poldek $SRC -s "$RPMS_FROM" -r "$CHDIR" "--cachedir=$CACHEDIR" --conf=$PWD/poldekconf/poldek.conf "$@"
233 for DIR in $CHHOME/rpm $CHHOME dev proc sys; do
234 [ -d $CHDIR/$DIR ] && umount $CHDIR/$DIR
241 if $FORCE_UMOUNT; then
243 [ "$CHDIR" ] || exit 1
244 [ -d "$CHDIR" ] || exit 1
255 info "Cleaning $CHNAME"
256 title "cleaning chroot"
263 title "preparing chroot"
267 mount -t tmpfs -o size=8G,relatime /dev/null $CHDIR
268 echo $$ > $CHDIR/.pid
270 rpm --root=$CHDIR --initdb
272 poldek -O "ignore=$IGNORE" -u rpm-build pwdutils coreutils
274 for DIR in dev proc sys; do
275 # We need to create these directories manually, because they are marked
276 # as netsharedpath in cleanbuild poldek.conf
278 mount -o bind /$DIR $CHDIR/$DIR
281 chroot $CHDIR useradd -m $USER -u$(getent passwd $USER | cut -d: -f3)
283 # replicate files which already belong to $USER
284 # so they will have correct owner and permissions
285 cp -a $CHDIR/$CHHOME/{tmp,rpm}
286 cp -a $CHDIR/$CHHOME/tmp $CHDIR/BUILD
288 cp -a $CHDIR/$CHHOME/{.bashrc,.rpmmacros}
289 cat <<-'EOM' > $CHDIR/$CHHOME/.rpmmacros
291 %buildroot %{_builddir}/%{name}-%{version}-root-%(id -u -n)
292 %_rpmdirname cleanRPMS
293 %_rpmdir %{expand:%%global _rpmdir %([ -d %{_topdir}/../%{_rpmdirname} ] && (cd %{_topdir}/../%{_rpmdirname}; pwd) || echo %{_topdir}/%{_rpmdirname})}%_rpmdir
294 %distribution CleanPLD
295 %_binary_payload w1.gzdio
299 cp -a $CHDIR/$CHHOME/{.bashrc,.builderrc}
300 cat <<-'EORC' > $CHDIR/$CHHOME/.builderrc
309 mount -o bind $HOME/rpm $CHDIR/$CHHOME/rpm
316 if [ -r installed/$build_pkg ]; then
317 $echo "$(cat installed/$build_pkg | awk '{print $1}' | sort -u \
318 | awk '{br=br ", " $1} END{gsub(/^, /, "- BR: ", br ); print br}')"
319 cat installed/$build_pkg
330 echo "*** $build_pkg $(date --rfc-3339=seconds) ***" >> $LIST
331 print_installed echo >> $LIST
345 addlist "ERROR_$LIST"
354 [ -n "$I" ] || return 1
355 # Installing same packets second time
356 [ "$LAST_INSTALL" != "$I" ] || return 1
360 poldek -O "ignore=$IGNORE" -u $I | tee $$.poldek_install
362 if grep -q "Preparing... ##################################################" $$.poldek_install \
363 && ! grep -q "file .* from install of .* conflicts with file from package" $$.poldek_install
365 info "Poldek:" $I "installed"
367 elif grep -q "Nothing to do" $$.poldek_install; then
368 warn "Poldek:" $I "installed already"
372 [ -n "$ret" ] && return $ret
375 poldek -u $I && return 0
376 poldek -u $I && return 0
377 warn "Poldek:" "Could not install" $I
383 local cond="$1"; shift
384 local func="$1"; shift
386 [ $cond == "false" ] && return
388 [ $cond == "exit_after" ] && exit
393 info "Fetching $build_pkg"
396 su $USER -c "$HOME/rpm/packages/builder -g $build_pkg $builder_options" \
397 || die 11 "Fetch failed"
403 su $USER -c "poldek -s $RPMS_FROM --mkidx"
405 if [ ! -d $CHDIR ]; then
406 info "Preparing $CHNAME"
413 maybe_call $FETCH fetch
417 maybe_call $CLEAN clean
419 maybe_call $CREATE create
421 echo $$ > $CHDIR/.pid
423 maybe_call $INSTALL poldek_install "$*"
427 if [ -p /tmp/fixfreq ]; then
428 echo $$ > /tmp/fixfreq
432 info "Building $build_pkg in $CHNAME"
434 buildlog="buildlogs/$build_pkg"
435 if [ -r $buildlog ]; then
437 while [ -r $buildlog.$i ]; do
440 info "moving $buildlog to $buildlog.$i"
441 mv $buildlog $buildlog.$i
443 ./findunusedbr -c $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
445 { chroot $CHDIR su $USER -c "$CHHOME/rpm/packages/builder -nn -bb $build_pkg $builder_options" 2>&1; echo $? > ecode; } | tee $buildlog
450 if grep -q "error: Failed build dependencies:" $buildlog; then
451 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 }')
452 INSTALL=$(poldek -O "ignore=$IGNORE" --shcmd="$SEARCH" | awk '{ if ( p ) { print; p = 0; } } / package\(s\) found:$/ { p = 1 }' | sed 's/^\(.*\)-.*-.*$/\1/' | sort -u)
454 if poldek_install "$INSTALL"; then
455 info "Deps installed"
458 addlist ERROR_BRINSTALL
459 die 4 "Cannot install BRs"
463 ./findbr $CHDIR/BUILD $buildlog > $$.installed
464 installed_something=false
465 while read pkg msg; do
466 if poldek_install $pkg; then
467 info "findbr:" $pkg "installed"
468 echo "$pkg $msg" >> installed/$build_pkg
469 ./addbr $build_pkg "$pkg" "$msg"
470 installed_something=true
472 warn "findbr:" $pkg "not installed"
476 $installed_something && continue
478 if [ $ECODE -eq 0 ]; then
481 ./findunusedbr $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
482 info "$build_pkg built OK !"
486 builddie UNKNOWN 1 "Got error but dunno what to do !"
491 # vim: ts=4 sw=4 filetype=sh