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 $*"; }
12 [ -r .cleanbuildrc ] && . ./.cleanbuildrc
14 [ -z "$USER" ] && echo "USER not defined" && exit 1
15 [ "$USER" == "root" ] && echo "USER must not be root" && exit 1
22 [ $# -gt 0 ] && echo "$*"
24 echo " ./cleanbuild [cleanbuild options] specname [builder options]"
25 echo " ./build [cleanbuild options] specname [builder options]"
26 echo " ./clean [cleanbuild options]"
27 echo " ./create [cleanbuild options]"
28 echo " ./install [cleanbuild options] packages"
30 echo "cleanbuild options:"
31 echo " -32, -64, -th-i486 - select architecture"
32 echo " --force | -f - force umount tmpfs"
33 echo " -a, -b, -c, -d - select chroot directory"
72 while [ $# -gt 0 ]; do
75 -32) OPT="-th-i686" ;;
76 -64) OPT="-th-x86_64" ;;
77 -th-32) OPT="-th-i686" ;;
78 -th-64) OPT="-th-x86_64" ;;
79 -ti-32) OPT="-ti-i686" ;;
80 -ti-64) OPT="-ti-x86_64" ;;
81 -ac) OPT="-ac-amd64" ;;
82 -ac-32) OPT="-ac-i586" ;;
83 -ac-64) OPT="-ac-amd64" ;;
88 -th-i[46]86 | -th-x86_64)
92 -th-i[46]86-test | -th-x86_64-test)
96 -ti-i[56]86 | -ti-x86_64)
100 -ti-i[56]86-test | -ti-x86_64-test)
104 -ac-amd64 | -ac-i[356]86 | -ac-athlon)
131 [ $# -ne 0 ] || usage
140 CHNAME="chroot-$DEST$SUFFIX"
142 CHHOME="/home/users/$USER"
146 echo -n -e "\033[31;1m" >&2
148 echo -e "\033[0m" >&2
161 echo -n -e "\033[32m"
169 local msg="$CHNAME: $build_pkg: $*"
172 echo -ne "\033]1;$msg\007\033]2;$msg\007" >&2
175 echo -ne "\033]0;$msg\007" >&2
188 [ -r "$CHDIR/.pid" ] || return
189 PID=$(< "$CHDIR/.pid")
190 if [ -d /proc/$PID ]; then
191 die 10 "Another process ($PID) already running in $CHNAME"
195 for D in installed buildlogs $CACHEDIR; do
196 if [ ! -d "$D" ]; then
198 su $USER -c "mkdir -p $D" || die 13 "Cannot create work directories"
205 xorg-driver-video-fglrx\* xorg-driver-video-nvidia\* xorg-xserver-xgl-libGL \
209 anacron fcron hc-cron \
210 masqmail msmtp-sendmail omta postfix sendmail ssmtp nail-mail nullmailer \
213 gnome-speech-driver-festival gnome-speech-driver-speech-dispatcher
218 #rpm --root=$CHDIR --rebuilddb
225 /usr/bin/poldek $SRC -s "$RPMS_FROM" -r "$CHDIR" "--cachedir=$CACHEDIR" --conf=$PWD/poldekconf/poldek.conf "$@"
231 for DIR in $CHHOME/rpm $CHHOME dev proc sys; do
232 [ -d $CHDIR/$DIR ] && umount $CHDIR/$DIR
241 [ "$CHDIR" ] || exit 1
242 [ -d "$CHDIR" ] || exit 1
253 info "Cleaning $CHNAME"
254 title "cleaning chroot"
261 title "preparing chroot"
265 mount -t tmpfs -o size=8G,relatime /dev/null $CHDIR
266 echo $$ > $CHDIR/.pid
268 rpm --root=$CHDIR --initdb
270 poldek -O "ignore=$IGNORE" -u rpm-build pwdutils coreutils
272 for DIR in dev proc sys; do
273 # We need to create these directories manually, because they are marked
274 # as netsharedpath in cleanbuild poldek.conf
276 mount -o bind /$DIR $CHDIR/$DIR
279 chroot $CHDIR useradd -m $USER -u$(getent passwd $USER | cut -d: -f3)
281 # replicate files which already belong to $USER
282 # so they will have correct owner and permissions
283 cp -a $CHDIR/$CHHOME/{tmp,rpm}
284 cp -a $CHDIR/$CHHOME/tmp $CHDIR/BUILD
286 cp -a $CHDIR/$CHHOME/{.bashrc,.rpmmacros}
287 cat <<-'EOM' > $CHDIR/$CHHOME/.rpmmacros
289 %buildroot %{_builddir}/%{name}-%{version}-root-%(id -u -n)
290 %_rpmdirname cleanRPMS
291 %_rpmdir %{expand:%%global _rpmdir %([ -d %{_topdir}/../%{_rpmdirname} ] && (cd %{_topdir}/../%{_rpmdirname}; pwd) || echo %{_topdir}/%{_rpmdirname})}%_rpmdir
292 %distribution CleanPLD
293 %_binary_payload w1.gzdio
297 cp -a $CHDIR/$CHHOME/{.bashrc,.builderrc}
298 cat <<-'EORC' > $CHDIR/$CHHOME/.builderrc
307 mount -o bind $HOME/rpm $CHDIR/$CHHOME/rpm
314 if [ -r installed/$build_pkg ]; then
315 $echo "$(cat installed/$build_pkg | awk '{print $1}' | sort -u \
316 | awk '{br=br ", " $1} END{gsub(/^, /, "- BR: ", br ); print br}')"
317 cat installed/$build_pkg
328 echo "*** $build_pkg $(date --rfc-3339=seconds) ***" >> $LIST
329 print_installed echo >> $LIST
343 addlist "ERROR_$LIST"
352 [ -n "$I" ] || return 1
353 # Installing same packets second time
354 [ "$LAST_INSTALL" != "$I" ] || return 1
358 poldek -O "ignore=$IGNORE" -u $I | tee $$.poldek_install
360 if grep -q "Preparing... ##################################################" $$.poldek_install \
361 && ! grep -q "file .* from install of .* conflicts with file from package" $$.poldek_install
363 info "Poldek:" $I "installed"
365 elif grep -q "Nothing to do" $$.poldek_install; then
366 warn "Poldek:" $I "installed already"
370 [ -n "$ret" ] && return $ret
373 poldek -u $I && return 0
374 poldek -u $I && return 0
375 warn "Poldek:" "Could not install" $I
381 local cond="$1"; shift
382 local func="$1"; shift
384 [ $cond == "false" ] && return
386 [ $cond == "exit_after" ] && exit
391 info "Fetching $build_pkg"
394 su $USER -c "$HOME/rpm/packages/builder -g $build_pkg $builder_options" \
395 || die 11 "Fetch failed"
401 su $USER -c "poldek -s $RPMS_FROM --mkidx"
403 if [ ! -d $CHDIR ]; then
404 info "Preparing $CHNAME"
411 maybe_call $FETCH fetch
415 maybe_call $CLEAN clean
417 maybe_call $CREATE create
419 echo $$ > $CHDIR/.pid
421 maybe_call $INSTALL poldek_install "$*"
425 if [ -p /tmp/fixfreq ]; then
426 echo $$ > /tmp/fixfreq
430 info "Building $build_pkg in $CHNAME"
432 buildlog="buildlogs/$build_pkg"
433 if [ -r $buildlog ]; then
435 while [ -r $buildlog.$i ]; do
438 info "moving $buildlog to $buildlog.$i"
439 mv $buildlog $buildlog.$i
441 ./findunusedbr -c $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
443 { chroot $CHDIR su $USER -c "$CHHOME/rpm/packages/builder -nn -bb $build_pkg $builder_options" 2>&1; echo $? > ecode; } | tee $buildlog
448 if grep -q "error: Failed build dependencies:" $buildlog; then
449 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 }')
450 INSTALL=$(poldek -O "ignore=$IGNORE" --shcmd="$SEARCH" | awk '{ if ( p ) { print; p = 0; } } / package\(s\) found:$/ { p = 1 }' | sed 's/^\(.*\)-.*-.*$/\1/' | sort -u)
452 if poldek_install "$INSTALL"; then
453 info "Deps installed"
456 addlist ERROR_BRINSTALL
457 die 4 "Cannot install BRs"
461 ./findbr $CHDIR/BUILD $buildlog > $$.installed
462 installed_something=false
463 while read pkg msg; do
464 if poldek_install $pkg; then
465 info "findbr:" $pkg "installed"
466 echo "$pkg $msg" >> installed/$build_pkg
467 ./addbr $build_pkg "$pkg" "$msg"
468 installed_something=true
470 warn "findbr:" $pkg "not installed"
474 $installed_something && continue
476 if [ $ECODE -eq 0 ]; then
479 ./findunusedbr $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
480 info "$build_pkg built OK !"
484 builddie UNKNOWN 1 "Got error but dunno what to do !"
489 # vim: ts=4 sw=4 filetype=sh