1 #!/usr/bin/sudo /bin/sh
3 RPMS_FROM="$HOME/rpm/cleanRPMS.repo"
5 SRC="-n th-x86_64-test"
7 CACHEDIR="$PWD/poldekcache"
12 ignore() { IGNORE="$IGNORE $*"; }
18 # Whatever you set here as value, consider that it may not be shorter than
19 # /usr/lib/debug (or /usr/src/debug) for debuginfo to work.
20 # You get "Only dest dir longer than base dir not supported" error otherwise.
21 BUILDDIR=/usr/src/BUILD
23 [ -r .cleanbuildrc ] && . ./.cleanbuildrc
25 [ -z "$USER" ] && echo "USER not defined" && exit 1
26 [ "$USER" = "root" ] && echo "USER must not be root" && exit 1
33 [ $# -gt 0 ] && echo "$*"
35 echo " ./cleanbuild [cleanbuild options] specname [builder options]"
36 echo " ./build [cleanbuild options] specname [builder options]"
37 echo " ./clean [cleanbuild options]"
38 echo " ./create [cleanbuild options]"
39 echo " ./install [cleanbuild options] packages"
41 echo "cleanbuild options:"
42 echo " -32, -64, -th-i486 - select architecture"
43 echo " --cleanafter | -ca - clean after build"
44 echo " --forceumount | -fu - force umount tmpfs"
45 echo " --debug - enable debug"
46 echo " --network - allow build to use networking"
47 echo " -a, -b, -c, -d, -e - select alternative chroot directory"
85 while [ $# -gt 0 ]; do
88 -32) OPT="-th-i686" ;;
89 -64) OPT="-th-x86_64" ;;
90 -th-32) OPT="-th-i686" ;;
91 -th-64) OPT="-th-x86_64" ;;
92 -ti-32) OPT="-ti-i686" ;;
93 -ti-64) OPT="-ti-x86_64" ;;
94 -ac) OPT="-ac-amd64" ;;
95 -ac-32) OPT="-ac-i586" ;;
96 -ac-64) OPT="-ac-amd64" ;;
101 -th-i[46]86 | -th-x86_64)
105 -th-i[46]86-test | -th-x86_64-test)
109 -ti-i[56]86 | -ti-x86_64)
113 -ti-i[56]86-test | -ti-x86_64-test)
117 -ac-amd64 | -ac-i[356]86 | -ac-athlon)
121 -[1-9]G | -[1-9][0-9]G )
150 [ $# -ne 0 ] || usage
152 build_pkg="${build_pkg%/}"
153 build_pkg="${build_pkg%.spec}"
154 build_pkg="${build_pkg#*/}"
162 CHNAME="chroot-$DEST$SUFFIX"
164 CHHOME="/home/users/$USER"
168 echo -n -e "\033[31;1m" >&2
170 echo -e "\033[0m" >&2
183 echo -n -e "\033[32m"
191 local msg="$CHNAME: $build_pkg: $*"
194 echo -ne "\033]1;$msg\007\033]2;$msg\007" >&2
197 echo -ne "\033]0;$msg\007" >&2
210 [ -r "$CHDIR/.pid" ] || return
211 PID=$(< "$CHDIR/.pid")
212 if [ -d /proc/$PID ]; then
213 die 10 "Another process ($PID) already running in $CHNAME"
217 for D in installed buildlogs $CACHEDIR; do
218 if [ ! -d "$D" ]; then
220 su $USER -c "mkdir -p $D" || die 13 "Cannot create work directories"
231 xorg-driver-video-fglrx\* xorg-driver-video-nvidia\* xorg-xserver-xgl-libGL \
232 xorg-driver-video-vboxvideo \
236 libjpeg libjpeg-devel \
238 anacron fcron hc-cron \
239 masqmail msmtp-sendmail omta postfix sendmail ssmtp nail-mail nullmailer \
241 perl-Scalar-List-Utils \
242 perl-ExtUtils-Install \
243 phonon-backend-mplayer phonon-backend-vlc \
244 icedtea6-jre icedtea6-jdk \
245 java-sun-jre java5-sun-jre oracle-java7-jre \
247 gnome-speech-driver-festival gnome-speech-driver-speech-dispatcher
250 ignore '*-multilib-*'
255 $NOREBUILDDB || rpm --root=$CHDIR --rebuilddb
262 /usr/bin/poldek $SRC -s "$RPMS_FROM" -r "$CHDIR" "--cachedir=$CACHEDIR" --conf=$PWD/poldekconf/poldek.conf "$@"
268 for DIR in $CHHOME/rpm $CHHOME dev proc sys; do
269 [ -d $CHDIR/$DIR ] && umount $CHDIR/$DIR
276 if $FORCE_UMOUNT; then
278 [ "$CHDIR" ] || exit 1
279 [ -d "$CHDIR" ] || exit 1
290 info "Cleaning $CHNAME"
291 title "cleaning chroot"
298 title "preparing chroot"
302 mount -t tmpfs -o size=$CHROOTSIZE,relatime /dev/null $CHDIR
303 echo $$ > $CHDIR/.pid
305 rpmversion=$(rpm -E '%(v=%{_rpmversion}; IFS=.; set -- $v; echo $1)')
306 rpmversion=${rpmversion:-4}
308 if [ "$rpmversion" -ge 5 ]; then
309 rpm --root=$CHDIR -qa
311 rpm --root=$CHDIR --initdb
314 poldek -O "ignore=$IGNORE" -u rpm-build pwdutils coreutils time util-linux git-core gawk
317 for DIR in dev proc sys; do
318 # We need to create these directories manually, because they are marked
319 # as netsharedpath in cleanbuild poldek.conf
321 mount -o bind /$DIR $CHDIR/$DIR
324 # group 'users' may already exist, so ignore errors
325 chroot $CHDIR groupadd $(id $USER -gn) -g$(id $USER -g) || :
326 chroot $CHDIR useradd -m $USER -u$(id $USER -u) -g $(id $USER -gn)
328 # replicate files which already belong to $USER
329 # so they will have correct owner and permissions
330 cp -a $CHDIR/$CHHOME/{tmp,rpm}
331 cp -a $CHDIR/$CHHOME/tmp $CHDIR$BUILDDIR
333 cp -a $CHDIR/$CHHOME/{.bashrc,.rpmmacros}
334 cat <<-EOM > $CHDIR/$CHHOME/.rpmmacros
336 %buildroot %{_builddir}/%{name}-%{version}-root-%(id -u -n)
337 %_rpmdirname cleanRPMS
338 %_rpmdir %{expand:%%global _rpmdir %([ -d %{_topdir}/../%{_rpmdirname} ] && (cd %{_topdir}/../%{_rpmdirname}; pwd) || echo %{_topdir}/%{_rpmdirname})}%_rpmdir
339 %distribution CleanPLD
340 %_binary_payload w1.gzdio
342 [ -z "$RPMMACROS" ] || echo "$RPMMACROS" >> $CHDIR/$CHHOME/.rpmmacros
344 cp -a $CHDIR/$CHHOME/{.bashrc,.builderrc}
345 cat <<-'EORC' > $CHDIR/$CHHOME/.builderrc
348 [ -z "$BUILDERRC" ] || echo "$BUILDERRC" >> $CHDIR/$CHHOME/.builderrc
356 mount -o bind $HOME/rpm $CHDIR/$CHHOME/rpm
358 # ensure RPMS dir is available
359 chroot $CHDIR su $USER -c 'mkdir -p $(rpm -E %_rpmdir)'
365 if [ -r installed/$build_pkg ]; then
366 $echo "$(cat installed/$build_pkg | awk '{print $1}' | sort -u \
367 | awk '{br=br ", " $1} END{gsub(/^, /, "- BR: ", br ); print br}')"
368 cat installed/$build_pkg
379 echo "*** $build_pkg $(date --rfc-3339=seconds) ***" >> $LIST
380 print_installed echo >> $LIST
394 addlist "ERROR_$LIST"
403 [ -n "$I" ] || return 1
404 # Installing same packets second time
405 [ "$LAST_INSTALL" != "$I" ] || return 1
409 poldek -O "ignore=$IGNORE" -u $I | tee $$.poldek_install
411 if grep -q "Preparing... ##################################################" $$.poldek_install \
412 && ! grep -q "file .* from install of .* conflicts with file from package" $$.poldek_install
414 info "Poldek:" $I "installed"
416 elif grep -q "Nothing to do" $$.poldek_install; then
417 warn "Poldek:" $I "installed already"
421 [ -n "$ret" ] && return $ret
424 info "Poldek install failed, retry without ignore"
425 poldek -u $I && return 0
426 info "Poldek install failed, retry once more without ignore"
427 poldek -u $I && return 0
428 warn "Poldek:" "Could not install" $I
434 local cond="$1"; shift
435 local func="$1"; shift
437 [ $cond = "false" ] && return
439 [ $cond = "exit_after" ] && exit
444 info "Fetching $build_pkg"
447 su $USER -c "$HOME/rpm/packages/builder -g $build_pkg $builder_options" \
448 || die 11 "Fetch failed"
454 su $USER -c "poldek -s $RPMS_FROM --mkidx"
456 if [ ! -d $CHDIR ]; then
457 info "Preparing $CHNAME"
464 info "Configured Poldek sources"
467 maybe_call $FETCH fetch
471 maybe_call $CLEAN clean
473 maybe_call $CREATE create
475 echo $$ > $CHDIR/.pid
477 maybe_call $INSTALL poldek_install "$*"
479 maybe_call $NETWORK cp -bf /etc/resolv.conf $CHDIR/etc/
483 if [ -p /tmp/fixfreq ]; then
484 echo $$ > /tmp/fixfreq
488 info "Building $build_pkg in $CHNAME"
490 find $CHDIR/usr/lib{,64} -name "*.la" -print0 | \
491 xargs -0 -r sed -i -e "s@dependency_libs=.*@dependency_libs=' '@"
492 buildlog="buildlogs/$build_pkg"
493 if [ -r $buildlog ]; then
495 while [ -r $buildlog.$i ]; do
498 info "moving $buildlog to $buildlog.$i"
499 mv $buildlog $buildlog.$i
501 ./findunusedbr -c $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
503 ./teeboth $buildlog chroot $CHDIR su $USER -c "$CHHOME/rpm/packages/builder -nn --define '_enable_debug_packages 0' -bb $build_pkg $builder_options"
506 if grep -q "error: Failed build dependencies:" $buildlog; then
507 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 }')
508 INSTALL=$(poldek -O "ignore=$IGNORE" --shcmd="$SEARCH" | awk '{ if ( p ) { print; p = 0; } } / package\(s\) found:$/ { p = 1 }' | sed 's/^\(.*\)-.*-.*$/\1/' | sort -u)
510 if poldek_install "$INSTALL"; then
511 info "Deps installed"
514 addlist ERROR_BRINSTALL
515 die 4 "Cannot install BRs"
519 ./findbr $CHDIR/$BUILDDIR $buildlog > $$.installed
520 installed_something=false
521 while read pkg msg; do
522 if poldek_install $pkg; then
523 info "findbr:" $pkg "installed"
524 echo "$pkg $msg" >> installed/$build_pkg
525 ./addbr $build_pkg "$pkg" "$msg"
526 installed_something=true
528 warn "findbr:" $pkg "not installed"
532 $installed_something && continue
534 if [ $ECODE -eq 0 ]; then
537 ./findunusedbr $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
538 info "$build_pkg built OK !"
542 builddie UNKNOWN 1 "Got error but dunno what to do !"
547 # vim: ts=4 sw=4 filetype=sh