]> git.pld-linux.org Git - projects/cleanbuild.git/blame - cleanbuild
- NEW
[projects/cleanbuild.git] / cleanbuild
CommitLineData
82208ca0 1#!/usr/bin/sudo /bin/sh
2
3USER="sparky"
4RPMS_FROM="$HOME/rpm/cleanRPMS.repo"
5DEST="th"
6SRC="-n th -n th-ready"
7SUFFIX=""
8CACHEDIR="$PWD/poldekcache"
9
10[ -r .cleanbuildrc ] && . .cleanbuildrc
11
12export LC_ALL=C
13unset LANGUAGE
14unset LANG
15
16usage() {
17 [ $# -gt 0 ] && echo "$*"
18 echo "Usage:"
19 echo " ./cleanbuild [cleanbuild options] specname [builder options]"
20 echo " ./build [cleanbuild options] specname [builder options]"
21 echo " ./clean [cleanbuild options]"
22 echo " ./cleaninstall [cleanbuild options] packages"
23 echo " ./install [cleanbuild options] packages"
24 echo ""
25 echo "cleanbuild options:"
26 echo " -32, -64, -th-i486 - select architecture"
27 echo " -a, -b, -c, -d - select chroot directory"
28 exit 1
29}
30
31FETCH=false
32CLEAN=false
33BUILD=false
34INSTALL=false
35CLEANAFTER=false
36
37case "$0" in
38 *cleanbuild)
39 FETCH=true
40 CLEAN=true
41 BUILD=true
42 ;;
43 *clean)
44 CLEAN=true
45 ;;
46 *build)
47 BUILD=true
48 ;;
49 *cleaninstall)
50 CLEAN=true
51 INSTALL=true
52 ;;
53 *install)
54 INSTALL=true
55 ;;
56 *)
57 usage
58 ;;
59esac
60
61while [ $# -gt 0 ]; do
62 OPT="${1}"
63 case "$OPT" in
64 -32) OPT="-th-i686" ;;
65 -64) OPT="-th-x86_64" ;;
66 -th-32) OPT="-th-i686" ;;
67 -th-64) OPT="-th-x86_64" ;;
68 -ac) OPT="-ac-amd64" ;;
69 -ac-32) OPT="-ac-i586" ;;
70 -ac-64) OPT="-ac-amd64" ;;
71 esac
72
73 V="${OPT#-}"
74 case "$OPT" in
75 -th-i[46]86 | -th-x86_64)
76 DEST="$V"
77 SRC="-n $V -n $V-ready -n th-noarch -n th-noarch-ready"
78 ;;
79 -ac-amd64 | -ac-i[356]86 | -ac-athlon)
80 DEST="$V"
81 SRC="-n $V"
82 ;;
83 -cleanafter | -ca)
84 CLEANAFTER=true
85 ;;
86 -[a-z])
87 SUFFIX="$OPT"
88 ;;
89 -~*)
90 SUFFIX="$V"
91 ;;
92 *)
93 break
94 ;;
95 esac
96 shift
97done
98
99if $BUILD; then
100 [ $# -ne 0 ] || usage
101 build_pkg="${1}"
102 shift
103
104 builder_options="$*"
105fi
106
107warn() {
108 echo -n -e "\033[31;1m" >&2
109 echo -n "$*" >&2
110 echo -e "\033[0m" >&2
111}
112die() {
113 code=$1
114 shift
115 warn "$*"
116 exit $code
117}
118info() {
119 echo -n -e "\033[32m"
120 echo -n "$*"
121 echo -e "\033[0m"
122}
123title() {
124 [ -t 1 ] || return 0
125 local msg="$CHNAME: $build_pkg: $*"
126 case "$TERM" in
127 cygwin|xterm*)
128 echo -ne "\033]1;$msg\007\033]2;$msg\007" >&2
129 ;;
130 screen*)
131 echo -ne "\033]0;$msg\007" >&2
132 ;;
133 esac
134 return 0
135}
136
137
138CHNAME="chroot-$DEST$SUFFIX"
139CHDIR="$PWD/$CHNAME"
140
141check_running() {
142 [ -r "$CHDIR/.pid" ] || return
143 PID=$(< "$CHDIR/.pid")
144 if [ -d /proc/$PID ]; then
145 die 10 "Another process ($PID) already running in $CHNAME"
146 fi
147}
148
149check_running
150
151for D in installed buildlogs $CACHEDIR; do
152 if [ ! -d "$D" ]; then
153 echo "mkdir $D"
154 su $USER -c "mkdir -p $D" || die 13 "Cannot create work directories"
155 fi
156done
157
158if $FETCH; then
159 info "Fetching $build_pkg"
160 title "fetch"
161 su $USER -c "$HOME/rpm/packages/builder -g $build_pkg $builder_options" \
162 || die 11 "Fetch failed"
163fi
164
165poldek_options="-O keep_downloads=yes -O suggests=no -O ignore=vserver-packages -O unique_package_names=yes -O particle_install=no"
166
167IGNORE=""
168ignore() { IGNORE="$IGNORE $*"; }
169ignore \
170 vserver-packages \
171 upstart\* \
172 xorg-driver-video-fglrx\* xorg-driver-video-nvidia\* xorg-xserver-xgl-libGL \
173 xorg-data-xbitmaps \
174 compat-gcc\* \
175 libpng1\* \
176 anacron fcron hc-cron \
177 masqmail msmtp-sendmail omta postfix sendmail ssmtp nail-mail nullmailer \
178 ghostscript-esp \
179 \*-multilib-\* \
180 stfl-python \
181 perl-PathTools perl-MIME-Base64 \
182 gnome-speech-driver-festival gnome-speech-driver-speech-dispatcher \
183 phonon-backend-xine \
184 xemacs-extras \
185 freetype1-devel \
186 kde-icons-actions kipi-plugins \
187 gnome-menus \
188 java-sun-jre
189
190
191rebuilddb() {
192 rpm --root=$CHDIR --rebuilddb
193}
194
195poldek() {
196 rebuilddb
197 /usr/bin/poldek $SRC -s "$RPMS_FROM" -r "$CHDIR" "--cachedir=$CACHEDIR" $poldek_options "$@"
198}
199
200
201CHHOME="/home/users/$USER"
202
203#set -x
204
205build_umount() {
206 for DIR in $CHHOME/rpm $CHHOME dev proc sys; do
207 [ -d $CHDIR/$DIR ] && umount $CHDIR/$DIR
208 done
209}
210
211build_remove_root() {
212 umount $CHDIR
213 rmdir $CHDIR
214}
215
216check_running
217
218clean() {
219 info "Cleaning $CHNAME"
220 build_umount
221 build_remove_root
222 title "clean"
223}
224
225$CLEAN && clean
226
227build_prepare_root() {
228 set -e
229 mkdir $CHDIR
230 mount -t tmpfs -o size=8G /dev/null $CHDIR
231 echo $$ > $CHDIR/.pid
232
233 rpm --root=$CHDIR --initdb
234 poldek --up || :
235 poldek --noask -u FHS
236 poldek --noask -u libstdc++
237 poldek --noask -u rpm-build
238 poldek --upgrade-dist
239
240
241 for DIR in dev proc sys; do
242 mount -o bind /$DIR $CHDIR/$DIR
243 done
244
245 chroot $CHDIR useradd -m $USER
246 cp -a $CHDIR/$CHHOME/{tmp,rpm}
247 cp -a $CHDIR/$CHHOME/tmp $CHDIR/BUILD
248 cp -a $CHDIR/$CHHOME/{.bashrc,.rpmmacros}
249 cat <<-'EOM' > $CHDIR/$CHHOME/.rpmmacros
250 %_builddir /BUILD
251 %buildroot %{_builddir}/%{name}-%{version}-root-%(id -u -n)
252 %_rpmdir %{_topdir}/cleanRPMS
253 %distribution CleanPLD
254 %_binary_payload w1.gzdio
255EOM
256 cat <<-'EORC' > $CHDIR/$CHHOME/.builderrc
257 TITLECHANGE=no
258EORC
259 set +e
260}
261
262build_mount_home() {
263 mount -o bind $HOME/rpm $CHDIR/$CHHOME/rpm
264}
265
266if ! $BUILD && ! $INSTALL; then
267 exit
268fi
269
270if $CLEAN; then
271 su $USER -c "poldek -s $RPMS_FROM --mkidx"
272
273 # rm -f installed/$build_pkg
274
275 info "Preparing $CHNAME"
276 build_prepare_root
277 build_mount_home
278fi
279
280echo $$ > $CHDIR/.pid
281
282print_installed() {
283 echo=$1
284 if [ -r installed/$build_pkg ]; then
285 $echo "$(cat installed/$build_pkg | awk '{print $1}' | sort -u \
286 | awk '{br=br ", " $1} END{gsub(/^, /, "- BR: ", br ); print br}')"
287 cat installed/$build_pkg
288 fi
289}
290
291addlist() {
292 LIST="$1"
293
294 print_installed info
295 echo "*** $build_pkg $(date --rfc-3339=seconds) ***" >> $LIST
296 print_installed echo >> $LIST
297}
298
299builddie() {
300 LIST="$1"; shift
301 CODE="$1"; shift
302 MSG="$*"
303
304 $CLEANAFTER && clean
305 title "failed !"
306
307 addlist "ERROR_$LIST"
308 die $CODE "$MSG"
309}
310
311LAST_INSTALL=""
312poldek_install() {
313 I="$1";
314 # Nothing to install
315 [ -n "$I" ] || return 1
316 # Installing same packets second time
317 [ "$LAST_INSTALL" != "$I" ] || return 1
318 LAST_INSTALL="$I"
319
320 info "Installing" $I
321 poldek -O "ignore=$IGNORE" -u $I | tee $$.poldek_install
322 ret=
323 if grep -q "Preparing... ##################################################" $$.poldek_install \
324 && ! grep -q "file .* from install of .* conflicts with file from package" $$.poldek_install
325 then
326 info "Poldek:" $I "installed"
327 ret=0
328 elif grep -q "Nothing to do" $$.poldek_install; then
329 warn "Poldek:" $I "installed already"
330 ret=1
331 fi
332 rm $$.poldek_install
333 [ -n "$ret" ] && return $ret
334
335 # try harder
336 poldek -u $I && return 0
337 poldek -u $I && return 0
338 warn "Poldek:" "Could not install" $I
339 return 1
340}
341
342if $INSTALL; then
343 poldek_install "$*"
344 exit
345fi
346
347while true; do
348 info "Building $build_pkg in $CHNAME"
349 rebuilddb
350 buildlog="buildlogs/$build_pkg"
351 if [ -r $buildlog ]; then
352 i=1
353 while [ -r $buildlog.$i ]; do
354 i=$((i+1))
355 done
356 info "moving $buildlog to $buildlog.$i"
357 mv $buildlog $buildlog.$i
358 fi
359 title "building"
360 { chroot $CHDIR su $USER -c "$CHHOME/rpm/packages/builder -nn -bb $build_pkg $builder_options" 2>&1; echo $? > ecode; } | tee $buildlog
361
362 ECODE=$(< ecode)
363 rm -f ecode
364
365 if grep -q "error: Failed build dependencies:" $buildlog; then
366 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 }')
367 INSTALL=$(poldek -O "ignore=$IGNORE" --shcmd="$SEARCH" | awk '{ if ( p ) { print; p = 0; } } / package\(s\) found:$/ { p = 1 }' | sed 's/^\(.*\)-.*-.*$/\1/' | sort -u)
368
369 if poldek_install "$INSTALL"; then
370 info "Deps installed"
371 continue
372 else
373 addlist ERROR_BRINSTALL
374 die 4 "Cannot install BRs"
375 fi
376 fi
377
378 ./findbr $CHDIR/BUILD $buildlog > $$.installed
379 installed_something=false
380 while read pkg msg; do
381 if poldek_install $pkg; then
382 info "findbr:" $pkg "installed"
383 echo "$pkg $msg" >> installed/$build_pkg
384 ./addbr $build_pkg "$pkg" "$msg"
385 installed_something=true
386 else
387 warn "findbr:" $pkg "not installed"
388 fi
389 done < $$.installed
390 rm -f $$.installed
391 $installed_something && continue
392
393 if [ $ECODE -eq 0 ]; then
394 $CLEANAFTER && clean
395 addlist BUILT_OK
396 info "$build_pkg built OK !"
397 title "OK !"
398 exit 0
399 else
400 builddie UNKNOWN 1 "Got error but dunno what to do !"
401 fi
402done
403
404
405# vim: ts=4 sw=4 filetype=sh
This page took 0.627446 seconds and 4 git commands to generate.