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 libgcj libgcj-devel \
245 icedtea6-jre icedtea6-jdk \
246 icedtea7-jre icedtea7-jdk \
247 java-sun-jre java-sun-jdk \
248 java5-sun-jre java5-sun-jdk \
249 oracle-java7-jre oracle-java7-jdk \
251 gnome-speech-driver-festival gnome-speech-driver-speech-dispatcher
254 ignore '*-multilib-*'
259 $NOREBUILDDB || rpm --root=$CHDIR --rebuilddb
266 /usr/bin/poldek $SRC -s "$RPMS_FROM" -r "$CHDIR" "--cachedir=$CACHEDIR" --conf=$PWD/poldekconf/poldek.conf "$@"
272 for DIR in $CHHOME/rpm $CHHOME dev proc sys; do
273 [ -d $CHDIR/$DIR ] && umount $CHDIR/$DIR
280 if $FORCE_UMOUNT; then
282 [ "$CHDIR" ] || exit 1
283 [ -d "$CHDIR" ] || exit 1
294 info "Cleaning $CHNAME"
295 title "cleaning chroot"
302 title "preparing chroot"
306 mount -t tmpfs -o size=$CHROOTSIZE,relatime /dev/null $CHDIR
307 echo $$ > $CHDIR/.pid
309 rpmversion=$(rpm -E '%(v=%{_rpmversion}; IFS=.; set -- $v; echo $1)')
310 rpmversion=${rpmversion:-4}
312 if [ "$rpmversion" -ge 5 ]; then
313 rpm --root=$CHDIR -qa
315 rpm --root=$CHDIR --initdb
318 poldek -O "ignore=$IGNORE" -u rpm-build pwdutils coreutils time util-linux git-core gawk
321 for DIR in dev proc sys; do
322 # We need to create these directories manually, because they are marked
323 # as netsharedpath in cleanbuild poldek.conf
325 mount -o bind /$DIR $CHDIR/$DIR
328 # group 'users' may already exist, so ignore errors
329 chroot $CHDIR groupadd $(id $USER -gn) -g$(id $USER -g) || :
330 chroot $CHDIR useradd -m $USER -u$(id $USER -u) -g $(id $USER -gn)
332 # replicate files which already belong to $USER
333 # so they will have correct owner and permissions
334 cp -a $CHDIR/$CHHOME/{tmp,rpm}
335 cp -a $CHDIR/$CHHOME/tmp $CHDIR$BUILDDIR
337 cp -a $CHDIR/$CHHOME/{.bashrc,.rpmmacros}
338 cat <<-EOM > $CHDIR/$CHHOME/.rpmmacros
340 %buildroot %{_builddir}/%{name}-%{version}-root-%(id -u -n)
341 %_rpmdirname cleanRPMS
342 %_rpmdir %{expand:%%global _rpmdir %([ -d %{_topdir}/../%{_rpmdirname} ] && (cd %{_topdir}/../%{_rpmdirname}; pwd) || echo %{_topdir}/%{_rpmdirname})}%_rpmdir
343 %distribution CleanPLD
344 %_binary_payload w1.gzdio
346 [ -z "$RPMMACROS" ] || echo "$RPMMACROS" >> $CHDIR/$CHHOME/.rpmmacros
348 cp -a $CHDIR/$CHHOME/{.bashrc,.builderrc}
349 cat <<-'EORC' > $CHDIR/$CHHOME/.builderrc
352 [ -z "$BUILDERRC" ] || echo "$BUILDERRC" >> $CHDIR/$CHHOME/.builderrc
360 mount -o bind $HOME/rpm $CHDIR/$CHHOME/rpm
362 # ensure RPMS dir is available
363 chroot $CHDIR su $USER -c 'mkdir -p $(rpm -E %_rpmdir)'
369 if [ -r installed/$build_pkg ]; then
370 $echo "$(cat installed/$build_pkg | awk '{print $1}' | sort -u \
371 | awk '{br=br ", " $1} END{gsub(/^, /, "- BR: ", br ); print br}')"
372 cat installed/$build_pkg
383 echo "*** $build_pkg $(date --rfc-3339=seconds) ***" >> $LIST
384 print_installed echo >> $LIST
398 addlist "ERROR_$LIST"
407 [ -n "$I" ] || return 1
408 # Installing same packets second time
409 [ "$LAST_INSTALL" != "$I" ] || return 1
413 poldek -O "ignore=$IGNORE" -u $I | tee $$.poldek_install
415 if grep -q "Preparing... ##################################################" $$.poldek_install \
416 && ! grep -q "file .* from install of .* conflicts with file from package" $$.poldek_install
418 info "Poldek:" $I "installed"
420 elif grep -q "Nothing to do" $$.poldek_install; then
421 warn "Poldek:" $I "installed already"
425 [ -n "$ret" ] && return $ret
428 info "Poldek install failed, retry without ignore"
429 poldek -u $I && return 0
430 info "Poldek install failed, retry once more without ignore"
431 poldek -u $I && return 0
432 warn "Poldek:" "Could not install" $I
438 local cond="$1"; shift
439 local func="$1"; shift
441 [ $cond = "false" ] && return
443 [ $cond = "exit_after" ] && exit
448 info "Fetching $build_pkg"
451 su $USER -c "$HOME/rpm/packages/builder -g $build_pkg $builder_options" \
452 || die 11 "Fetch failed"
458 su $USER -c "poldek -s $RPMS_FROM --mkidx"
460 if [ ! -d $CHDIR ]; then
461 info "Preparing $CHNAME"
468 info "Configured Poldek sources"
471 maybe_call $FETCH fetch
475 maybe_call $CLEAN clean
477 maybe_call $CREATE create
479 echo $$ > $CHDIR/.pid
481 maybe_call $INSTALL poldek_install "$*"
483 maybe_call $NETWORK cp -bf /etc/resolv.conf $CHDIR/etc/
487 if [ -p /tmp/fixfreq ]; then
488 echo $$ > /tmp/fixfreq
492 info "Building $build_pkg in $CHNAME"
495 buildlog="buildlogs/$build_pkg"
496 if [ -r $buildlog ]; then
498 while [ -r $buildlog.$i ]; do
501 info "moving $buildlog to $buildlog.$i"
502 mv $buildlog $buildlog.$i
504 ./findunusedbr -c $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
506 ./teeboth $buildlog chroot $CHDIR su $USER -c "$CHHOME/rpm/packages/builder -nn --define '_enable_debug_packages 0' -bb $build_pkg $builder_options"
509 if grep -q "error: Failed build dependencies:" $buildlog; then
510 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 }')
511 INSTALL=$(poldek -O "ignore=$IGNORE" --shcmd="$SEARCH" | awk '{ if ( p ) { print; p = 0; } } / package\(s\) found:$/ { p = 1 }' | sed 's/^\(.*\)-.*-.*$/\1/' | sort -u)
513 if poldek_install "$INSTALL"; then
514 info "Deps installed"
517 addlist ERROR_BRINSTALL
518 die 4 "Cannot install BRs"
522 ./findbr $CHDIR/$BUILDDIR $buildlog > $$.installed
523 installed_something=false
524 while read pkg msg; do
525 if poldek_install $pkg; then
526 info "findbr:" $pkg "installed"
527 echo "$pkg $msg" >> installed/$build_pkg
528 ./addbr $build_pkg "$pkg" "$msg"
529 installed_something=true
531 warn "findbr:" $pkg "not installed"
535 $installed_something && continue
537 if [ $ECODE -eq 0 ]; then
540 ./findunusedbr $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
541 info "$build_pkg built OK !"
545 builddie UNKNOWN 1 "Got error but dunno what to do !"
550 # vim: ts=4 sw=4 filetype=sh