cookutils view cook @ rev 367

cook: handle HOST_ARCH (some package may bor build for an arch)
author Christophe Lincoln <pankso@slitaz.org>
date Thu May 10 04:28:16 2012 +0200 (2012-05-10)
parents c75f13234af0
children 897463926883
line source
1 #!/bin/sh
2 #
3 # Cook - A tool to cook and generate SliTaz packages. Read the README
4 # before adding or modifing any code in cook!
5 #
6 # Copyright (C) SliTaz GNU/Linux - GNU gpl v3
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
9 . /lib/libtaz.sh
11 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
12 [ -f "cook.conf" ] && . ./cook.conf
14 # Share DB and status with the Cooker.
15 activity="$CACHE/activity"
16 command="$CACHE/command"
17 broken="$CACHE/broken"
18 blocked="$CACHE/blocked"
20 # Old style compatibility
21 SOURCES_REPOSITORY=$SRC
23 #
24 # Functions
25 #
27 usage() {
28 cat << EOT
30 $(echo -e "\033[1m$(gettext "Usage:")\033[0m") cook [package|command] [list|--option]
32 $(echo -e "\033[1m$(gettext "Commands:")\033[0m")
33 usage|help $(gettext "Display this short usage.")
34 setup $(gettext "Setup your build environment.")
35 arm-setup $(gettext "Create packages DB lists and flavors.")
36 test $(gettext "Test environment and cook a package.")
37 list-wok $(gettext "List packages in the wok.")
38 search $(gettext "Simple packages search function.")
39 new $(gettext "Create a new package with a receipt".)
40 list $(gettext "Cook a list of packages.")
41 clean-wok $(gettext "Clean-up all packages files.")
42 clean-src $(gettext "Clean-up all packages sources.")
43 pkgdb $(gettext "Create packages DB lists and flavors.")
45 $(echo -e "\033[1m$(gettext "Options:")\033[0m")
46 --clean|-c Cook : $(gettext "clean the package in the wok.")
47 --install|-i Cook : $(gettext "cook and install the package.")
48 --getsrc|-gs Cook : $(gettext "get the package source tarball.")
49 --block|-b Cook : $(gettext "Block a package so cook will skip it.")
50 --unblock|-ub Cook : $(gettext "Unblock a blocked package.")
51 --interactive|-x New : $(gettext "create a receipt interactively.")
52 --wok|-w Setup: $(gettext "clone the cooking wok from Hg repo.")
53 --stable Setup: $(gettext "clone the stable wok from Hg repo.")
54 --undigest Setup: $(gettext "clone the undigest wok from Hg repo.")
55 --flavors Pkgdb: $(gettext "create up-to-date flavors files.")
57 EOT
58 exit 0
59 }
61 # Log activities, we want first letter capitalized.
62 log() {
63 grep ^[A-Z] | \
64 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
65 }
67 # We don't want these escapes in web interface.
68 clean_log() {
69 sed -i -e s'|\[70G\[ \[1;32m| |' \
70 -e s'|\[0;39m \]||' $LOGS/$pkg.log
71 }
73 # Log broken packages.
74 broken() {
75 if ! grep -q "^$pkg$" $broken; then
76 echo "$pkg" >> $broken
77 fi
78 }
80 # Be sure package exists in wok.
81 check_pkg_in_wok() {
82 if [ ! -d "$WOK/$pkg" ]; then
83 gettext -e "\nUnable to find package in the wok:"
84 echo -e " $pkg\n" && exit 1
85 fi
86 }
88 if_empty_value() {
89 if [ -z "$value" ]; then
90 gettext "QA: empty variable:"; echo -e " ${var}=\"\"\n"
91 exit 1
92 fi
93 }
95 # Initialize files used in $CACHE
96 init_db_files() {
97 gettext "Creating directories structure in:"; echo " $SLITAZ"
98 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS
99 gettext "Creating DB files in:"; echo " $CACHE"
100 for f in $activity $command $broken $blocked
101 do
102 touch $f
103 done
104 }
106 # QA: check a receipt consistency before building.
107 receipt_quality() {
108 gettext -e "QA: checking package receipt...\n"
109 unset online
110 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
111 online="online"
112 fi
113 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
114 do
115 unset value
116 value="$(. $receipt ; eval echo \$$var)"
117 case "$var" in
118 PACKAGE|VERSION|SHORT_DESC)
119 if_empty_value ;;
120 CATEGORY)
121 [ -z "$value" ] && value="empty"
122 valid="base-system x-window utilities network graphics \
123 multimedia office development system-tools security games \
124 misc meta non-free"
125 if ! echo "$valid" | grep -q -w "$value"; then
126 gettext "QA: unknown category:"; echo -e " $value\n"
127 exit 1
128 fi ;;
129 WEB_SITE)
130 # We don't check WGET_URL since if dl is needed it will fail.
131 # Break also if we're not online. Here error is not fatal.
132 if_empty_value
133 [ -z "$online" ] || break
134 if ! busybox wget -T 12 -s $value 2>/dev/null; then
135 gettext "QA: Unable to reach:"; echo -e " $value"
136 fi ;;
137 esac
138 done
139 }
141 # Executed before sourcing a receipt.
142 unset_receipt() {
143 unset DEPENDS BUILD_DEPENDS WANTED EXTRAVERSION WGET_URL PROVIDE TARBALL
144 unset HOST_ARCH CROSS_BUG
145 }
147 # Paths used in receipt and by cook itself.
148 set_paths() {
149 pkgdir=$WOK/$PACKAGE
150 src=$pkgdir/source/$PACKAGE-$VERSION
151 taz=$pkgdir/taz
152 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
153 fs=$pack/fs
154 stuff=$pkgdir/stuff
155 install=$pkgdir/install
156 if [ "$WANTED" ]; then
157 wanted=${WANTED%% *}
158 src=$WOK/$wanted/source/$wanted-$VERSION
159 install=$WOK/$wanted/install
160 wanted_stuff=$WOK/$wanted/stuff
161 fi
162 # Kernel version is set from linux-api-headers since it is part of toolchain.
163 if [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
164 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d '"' -f 2)
165 fi
166 # Old way compatibility.
167 _pkg=$install
168 }
170 # Create source tarball when URL is a SCM.
171 create_tarball() {
172 gettext "Creating tarball: "; echo "$tarball"
173 if [ "$LZMA_SRC" ]; then
174 tar -c $pkgsrc | lzma e $SRC/$tarball -si || exit 1
175 else
176 tar cjf $tarball $pkgsrc || exit 1
177 mv $tarball $SRC && rm -rf $pkgsrc
178 fi
179 }
181 # Get package source. For SCM we are in cache so clone here and create a
182 # tarball here.
183 get_source() {
184 pwd=$(pwd)
185 pkgsrc=${SOURCE:-$PACKAGE}-$VERSION
186 tarball=$pkgsrc.tar.bz2
187 [ "$LZMA_SRC" ] && tarball=$pkgsrc.tar.lzma
188 case "$WGET_URL" in
189 http://*|ftp://*)
190 # Busybox Wget is better!
191 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
192 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
193 https://*)
194 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
195 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
196 hg*|mercurial*)
197 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
198 url=${WGET_URL#hg|}
199 else
200 url=${WGET_URL#mercurial|}
201 fi
202 gettext -e "Getting source from Hg...\n"
203 echo "URL: $url"
204 gettext "Cloning to: "; echo "$pwd/$pkgsrc"
205 if [ "$BRANCH" ]; then
206 echo "Hg branch: $BRANCH"
207 hg clone $url --rev $BRANCH $pkgsrc || \
208 (echo "ERROR: hg clone $url --rev $BRANCH" && exit 1)
209 else
210 hg clone $url $pkgsrc || (echo "ERROR: hg clone $url" && exit 1)
211 fi
212 rm -rf $pkgsrc/.hg
213 create_tarball ;;
214 git*)
215 url=${WGET_URL#git|}
216 gettext -e "Getting source from Git...\n"
217 echo "URL: $url"
218 git clone $url $pkgsrc || (echo "ERROR: git clone $url" && exit 1)
219 if [ "$BRANCH" ]; then
220 echo "Git branch: $BRANCH"
221 cd $pkgsrc && git checkout $BRANCH && cd ..
222 fi
223 create_tarball ;;
224 cvs*)
225 url=${WGET_URL#cvs|}
226 mod=$PACKAGE
227 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
228 gettext -e "Getting source from CVS...\n"
229 echo "URL: $url"
230 [ "$CVS_MODULE" ] && echo "CVS module: $mod"
231 gettext "Cloning to: "; echo "$pwd/$mod"
232 cvs -d:$url co $mod && mv $mod $pkgsrc
233 create_tarball ;;
234 svn*|subversion*)
235 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
236 url=${WGET_URL#svn|}
237 else
238 url=${WGET_URL#subversion|}
239 fi
240 gettext -e "Getting source from SVN...\n"
241 echo "URL: $url"
242 if [ "$BRANCH" ]; then
243 echo t | svn co $url -r $BRANCH $pkgsrc
244 else
245 echo t | svn co $url $pkgsrc
246 fi
247 create_tarball ;;
248 *)
249 gettext -e "\nERROR: Unable to handle:"; echo -e " $WGET_URL \n" | \
250 tee -a $LOGS/$PACKAGE.log
251 exit 1 ;;
252 esac
253 }
255 # Extract source package.
256 extract_source() {
257 if [ ! -s "$SRC/$TARBALL" ]; then
258 local url
259 url="http://mirror.slitaz.org/sources/packages"
260 url=$url/${TARBALL:0:1}/$TARBALL
261 gettext "Getting source from mirror:"; echo " $url"
262 busybox wget -c -P $SRC $url || echo -e "ERROR: wget $url"
263 fi
264 gettext "Extracting:"; echo " $TARBALL"
265 case "$TARBALL" in
266 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
267 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
268 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
269 *.tar) tar xf $SRC/$TARBALL ;;
270 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
271 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
272 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
273 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
274 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
275 *) cp $SRC/$TARBALL $(pwd) ;;
276 esac
277 }
279 # Display cooked package summary.
280 summary() {
281 cd $WOK/$pkg
282 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
283 fs=$(du -sh taz/* | awk '{print $1}')
284 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
285 files=$(cat taz/$pkg-*/files.list | wc -l)
286 cookdate=$(date "+%Y-%m-%d %H:%M")
287 sec=$time
288 div=$(( ($time + 30) / 60))
289 [ "$div" != 0 ] && min="~ ${div}m"
290 gettext "Summary for:"; echo " $PACKAGE $VERSION"
291 separator
292 [ "$prod" ] && echo "Produced : $prod"
293 cat << EOT
294 Packed : $fs
295 Compressed : $size
296 Files : $files
297 Cook time : ${sec}s $min
298 Cook date : $cookdate
299 Arch type : $ARCH
300 $(separator)
301 EOT
302 }
304 # Display debugging error info.
305 debug_info() {
306 echo -e "\nDebug information"
307 separator
308 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
309 for error in \
310 ERROR "No package" "cp: can't" "can't open" "can't cd" \
311 "error:" "fatal error:"
312 do
313 fgrep "$error" $LOGS/$pkg.log
314 done
315 separator && echo ""
316 }
318 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
319 # so some packages need to copy these files with the receipt and genpkg_rules.
320 copy_generic_files()
321 {
322 # $LOCALE is set in cook.conf
323 if [ "$LOCALE" ]; then
324 if [ -d "$install/usr/share/locale" ]; then
325 mkdir -p $fs/usr/share/locale
326 for i in $LOCALE
327 do
328 if [ -d "$install/usr/share/locale/$i" ]; then
329 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
330 fi
331 done
332 fi
333 fi
335 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
336 if [ "$GENERIC_PIXMAPS" != "no" ]; then
337 if [ -d "$install/usr/share/pixmaps" ]; then
338 mkdir -p $fs/usr/share/pixmaps
339 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
340 $fs/usr/share/pixmaps 2>/dev/null || continue
341 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
342 $fs/usr/share/pixmaps 2>/dev/null || continue
343 fi
345 # Custom or homemade PNG pixmap can be in stuff.
346 if [ -f "$stuff/$PACKAGE.png" ]; then
347 mkdir -p $fs/usr/share/pixmaps
348 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
349 fi
350 fi
352 # Desktop entry (.desktop).
353 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
354 if [ "$GENERIC_MENUS" != "no" ]; then
355 if [ -d "$install/usr/share/applications" ] && [ "$WANTED" == "" ]; then
356 cp -a $install/usr/share/applications $fs/usr/share
357 fi
358 fi
360 # Homemade desktop file(s) can be in stuff.
361 if [ -d "$stuff/applications" ]; then
362 mkdir -p $fs/usr/share
363 cp -a $stuff/applications $fs/usr/share
364 fi
365 if [ -f "$stuff/$PACKAGE.desktop" ]; then
366 mkdir -p $fs/usr/share/applications
367 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
368 fi
369 }
371 # Find and strip : --strip-all (-s) or --strip-debug on static libs as well
372 # as removing uneeded files like in Python packages.
373 strip_package()
374 {
375 gettext "Executing strip on all files..."
376 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
377 do
378 if [ -d "$dir" ]; then
379 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
380 fi
381 done
382 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
383 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
384 status
386 # Remove Python .pyc and .pyo from packages.
387 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
388 gettext "Removing Python compiled files..."
389 find $fs -type f -name "*.pyc" -delete 2>/dev/null
390 find $fs -type f -name "*.pyo" -delete 2>/dev/null
391 status
392 fi
394 # Remove Perl perllocal.pod and .packlist from packages.
395 if echo "$DEPENDS" | fgrep -q "perl"; then
396 gettext "Removing Perl compiled files..."
397 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
398 find $fs -type f -name ".packlist" -delete 2>/dev/null
399 status
400 fi
401 }
403 # Remove installed deps.
404 remove_deps() {
405 # Now remove installed build deps.
406 diff="$CACHE/installed.cook.diff"
407 if [ -s "$CACHE/installed.cook.diff" ]; then
408 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
409 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
410 gettext "Build dependencies to remove:"; echo " $nb"
411 gettext "Removing:"
412 for dep in $deps
413 do
414 echo -n " $dep"
415 echo 'y' | tazpkg remove $dep >/dev/null
416 done
417 echo -e "\n"
418 # Keep the last diff for debug and info.
419 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
420 fi
421 }
423 # The main cook function.
424 cookit() {
425 echo "Cook: $PACKAGE $VERSION"
426 separator
427 set_paths
429 # Handle cross compilation
430 if [ "$HOST_ARCH" ] && [ ! $(echo "$HOST_ARCH" | fgrep $ARCH) ]; then
431 echo "ERROR: This package dont build on: $ARCH" && exit 1
432 fi
433 case "$ARCH" in
434 arm|x86_64)
435 echo "cook: adding /usr/cross/$ARCH/bin to PATH"
436 export PATH=$PATH:/usr/cross/$ARCH/bin
437 echo "cook: using C compiler $HOST_SYSTEM-gcc"
438 export CC=${HOST_SYSTEM}-gcc
439 export CXX=${HOST_SYSTEM}-g++ ;;
440 esac
442 [ "$QA" ] && receipt_quality
443 cd $pkgdir
444 rm -rf install taz source
446 # Disable -pipe if less than 512Mb free RAM.
447 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
448 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
449 gettext -e "Disabling -pipe compile flag: $free RAM\n"
450 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
451 CXXFLAGS="${CXXFLAGS/-pipe}" && \
452 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
453 fi
454 unset free
456 # Export flags and path to be used by make and receipt.
457 DESTDIR=$pkgdir/install
458 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
459 #LDFLAGS
461 # Check for build deps and handle implicit depends of *-dev packages
462 # (ex: libusb-dev :: libusb).
463 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
464 touch $CACHE/installed.local $CACHE/installed.web
465 [ "$BUILD_DEPENDS" ] && gettext -e "Checking build dependencies...\n"
466 for dep in $BUILD_DEPENDS
467 do
468 implicit=${dep%-dev}
469 for i in $dep $implicit
470 do
471 if [ ! -f "$INSTALLED/$i/receipt" ]; then
472 # Try local package first. In some cases implicit doesn't exist, ex:
473 # libboost-dev exists but not libboost, so check if we got vers.
474 unset vers
475 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
476 if [ -f "$PKGS/$i-$vers.tazpkg" ]; then
477 echo $i-$vers.tazpkg >> $CACHE/installed.local
478 else
479 # Priority to package version in wok (maybe more up-to-date)
480 # than the mirrored one.
481 if [ "$vers" ]; then
482 if fgrep -q $i-$vers $DB/packages.list; then
483 echo $i >> $CACHE/installed.web
484 else
485 # So package exists in wok but not available.
486 gettext "Missing dep (wok/pkg):"; echo " $i $vers"
487 echo $i >> $CACHE/missing.dep
488 fi
489 else
490 # Package is not in wok but may be in repo.
491 if fgrep -q $i-$vers $DB/packages.list; then
492 echo $i >> $CACHE/installed.web
493 else
494 echo "ERROR: unknown dep $i" && exit 1
495 fi
496 fi
497 fi
498 fi
499 done
500 done
502 # Get the list of installed packages
503 cd $INSTALLED && ls -1 > $CACHE/installed.list
505 # Have we a missing build dep to cook ?
506 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
507 gettext -e "Auto cook config is set : AUTO_COOK\n"
508 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
509 for i in $(uniq $CACHE/missing.dep)
510 do
511 (gettext "Building dep (wok/pkg) :"; echo " $i $vers") | \
512 tee -a $LOGS/$PACKAGE.log.$$
513 cook $i || (echo -e "ERROR: can't cook dep '$i'\n" && \
514 fgrep "remove: " $LOGS/$i.log && \
515 fgrep "Removing: " $LOGS/$i.log && echo "") | \
516 tee -a $LOGS/$PACKAGE.log.$$ && break
517 done
518 rm -f $CACHE/missing.dep
519 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
520 fi
522 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
523 # is enabled and cook fails we have ERROR in log, if no auto cook we have
524 # missing dep in cached file.
525 if fgrep -q "ERROR:" $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
526 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
527 echo "ERROR: missing dep $nb" && exit 1
528 fi
530 # Install local packages.
531 cd $PKGS
532 for i in $(uniq $CACHE/installed.local)
533 do
534 gettext "Installing dep (pkg/local):"; echo " $i"
535 tazpkg install $i >/dev/null
536 done
538 # Install web or cached packages (if mirror is set to $PKGS we only
539 # use local packages).
540 for i in $(uniq $CACHE/installed.web)
541 do
542 gettext "Installing dep (web/cache):"; echo " $i"
543 tazpkg get-install $i >/dev/null
544 done
546 # If a cook failed deps are removed.
547 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
548 [ ! -s "installed.cook.diff" ] && \
549 busybox diff installed.list installed.cook > installed.cook.diff
550 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
552 # Get source tarball and make sure we have source dir named:
553 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
554 # tarball if it exists.
555 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
556 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
557 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
558 LZMA_SRC=""
559 else
560 get_source || exit 1
561 fi
562 fi
563 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
564 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
565 if ! extract_source ; then
566 get_source
567 extract_source || exit 1
568 fi
569 if [ "$LZMA_SRC" ]; then
570 cd $pkgdir/source
571 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
572 mv tmp tmp-1 && mkdir tmp
573 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
574 fi
575 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
576 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
577 fi
578 fi
579 cd $pkgdir/source/tmp
580 # Some archives are not well done and don't extract to one dir (ex lzma).
581 files=$(ls | wc -l)
582 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
583 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
584 mv * ../$PACKAGE-$VERSION/$TARBALL
585 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
586 mv * ../$PACKAGE-$VERSION
587 cd .. && rm -rf tmp
588 fi
590 # Execute receipt rules.
591 if grep -q ^compile_rules $receipt; then
592 echo "Executing: compile_rules"
593 echo "CFLAGS : $CFLAGS"
594 #echo "LDFLAGS : $LDFLAGS"
595 [ -d "$src" ] && cd $src
596 compile_rules $@ || exit 1
597 # Stay compatible with _pkg
598 [ -d "$src/_pkg" ] && mv $src/_pkg $install
599 # QA: compile_rules success so valid.
600 mkdir -p $install
601 else
602 # QA: No compile_rules so no error, valid.
603 mkdir -p $install
604 fi
605 separator && echo ""
607 # Execute testsuite.
608 if grep -q ^testsuite $receipt; then
609 echo "Running testsuite"
610 separator
611 testsuite $@ || exit 1
612 separator && echo ""
613 fi
614 }
616 # Cook quality assurance.
617 cookit_quality() {
618 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
619 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
620 fi
621 # ERROR can be echoed any time in cookit()
622 if fgrep -q ERROR: $LOGS/$pkg.log; then
623 debug_info | tee -a $LOGS/$pkg.log
624 rm -f $command && exit 1
625 fi
626 }
628 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
629 # but it doesn't handle EXTRAVERSION.
630 packit() {
631 set_paths
633 # Handle cross compilation
634 case "$ARCH" in
635 arm|x86_64) VERSION="$VERSION-$ARCH" ;;
636 esac
638 echo "Pack: $PACKAGE $VERSION"
639 separator
641 if grep -q ^genpkg_rules $receipt; then
642 gettext -e "Executing: genpkg_rules\n"
643 set -e && cd $pkgdir && mkdir -p $fs
644 genpkg_rules || echo -e "\nERROR: genpkg_rules failed\n" >> \
645 $LOGS/$pkg.log
646 else
647 gettext "No packages rules: meta package"; echo
648 mkdir -p $fs
649 fi
651 # First QA check to stop now if genpkg_rules failed.
652 if fgrep -q ERROR: $LOGS/$pkg.log; then
653 exit 1
654 fi
656 cd $taz
657 for file in receipt description.txt
658 do
659 [ ! -f "../$file" ] && continue
660 gettext "Copying"; echo -n " $file..."
661 cp -f ../$file $pack && chown 0.0 $pack/$file && status
662 done
663 copy_generic_files
665 # Create files.list with redirecting find output.
666 gettext "Creating the list of files..." && cd $fs
667 find . -type f -print > ../files.list
668 find . -type l -print >> ../files.list
669 cd .. && sed -i s/'^.'/''/ files.list
670 status
672 # Strip and stuff files.
673 strip_package
675 # Md5sum of files.
676 gettext "Creating md5sum of files..."
677 while read file; do
678 [ -L "fs$file" ] && continue
679 [ -f "fs$file" ] || continue
680 case "$file" in
681 /lib/modules/*/modules.*|*.pyc) continue ;;
682 esac
683 md5sum "fs$file" | sed 's/ fs/ /'
684 done < files.list > md5sum
685 status
686 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
687 description.txt 2> /dev/null | awk \
688 '{ sz=$1 } END { print sz }')
690 # Build cpio archives.
691 gettext "Compressing the fs... "
692 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
693 rm -rf fs
694 status
695 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
696 md5sum description.txt 2> /dev/null | awk \
697 '{ sz=$1 } END { print sz }')
698 gettext "Updating receipt sizes..."
699 sed -i s/^PACKED_SIZE.*$// receipt
700 sed -i s/^UNPACKED_SIZE.*$// receipt
701 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
702 status
704 # Set extra version.
705 if [ "$EXTRAVERSION" ]; then
706 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
707 sed -i s/^EXTRAVERSION.*$// receipt
708 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
709 status
710 fi
712 # Compress.
713 gettext "Creating full cpio archive... "
714 find . -print | cpio -o -H newc --quiet > \
715 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
716 status
717 gettext "Restoring original package tree... "
718 unlzma -c fs.cpio.lzma | cpio -idm --quiet
719 status
720 rm fs.cpio.lzma && cd ..
722 # QA and give info.
723 tazpkg=$(ls *.tazpkg)
724 packit_quality
725 separator && gettext "Package:"; echo -e " $tazpkg\n"
726 }
728 # Verify package quality and consistency.
729 packit_quality() {
730 #gettext "QA: Checking for broken link..."
731 #link=$(find $fs/usr -type l -follow)
732 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
733 #status
735 # Exit if any error found in log file.
736 if fgrep -q ERROR: $LOGS/$pkg.log; then
737 rm -f $command && exit 1
738 fi
740 gettext "QA: Checking for empty package..."
741 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
742 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
743 echo -e "\nERROR: empty package"
744 rm -f $command && exit 1
745 else
746 # Ls sort by name so the first file is the one we want.
747 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
748 status
749 if [ -f "$old" ]; then
750 gettext "Removing old: $(basename $old)"
751 rm -f $old && status
752 fi
753 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
754 sed -i /^${pkg}$/d $broken
755 #gettext "Removing source tree..."
756 #rm -f $WOK/$pkg/source && status
757 fi
758 }
760 mkinstall_list() {
761 local pkg
762 for pkg in $@ ; do
763 case " $INSTALL_LIST " in
764 *\ $pkg\ *) continue ;;
765 *) if [ -s /home/slitaz/wok/$pkg/receipt ]; then
766 unset DEPENDS
767 . /home/slitaz/wok/$pkg/receipt
768 INSTALL_LIST="$INSTALL_LIST $pkg"
769 [ -n "$DEPENDS" ] && mkinstall_list $DEPENDS
770 fi
771 echo $pkg
772 esac
773 done
774 }
776 tac()
777 {
778 sed '1!G;h;$!d' $1
779 }
781 # Launch the cook command into a chroot jail protected by aufs.
782 # The current filesystems are used read-only and updates are
783 # stored in a separate branch.
784 try_aufs_chroot() {
786 base=/dev/shm/aufsmnt$$
788 # Can we setup the chroot ? Is it already done ?
789 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
790 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
791 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
792 mkdir ${base}root ${base}rw || return
794 echo "Setup aufs chroot..."
796 # Sanity check
797 for i in / /proc /sys /dev/shm /home ; do
798 case " $AUFS_MOUNTS " in
799 *\ $i\ *) ;;
800 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
801 esac
802 done
803 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
804 mount --bind $mnt ${base}root$mnt
805 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
806 echo "Aufs mountage failure"
807 umount ${base}root
808 rmdir ${base}*
809 return
810 fi
811 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
812 done
814 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
815 status=$?
817 echo "Leaving aufs chroot..."
818 tac ${base}rw/aufs-umount.sh | sh
819 rm -rf ${base}rw
820 umount ${base}root
821 rmdir $base*
823 # Install package if requested
824 if [ "$inst" ]; then
825 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
826 cd $PKGS && tazpkg install \
827 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
828 else
829 gettext -e "Unable to install package, build has failed.\n\n"
830 exit 1
831 fi
832 fi
834 # Install package if part of the chroot to keep env up-to-date.
835 if [ -d "$INSTALLED/$pkg" ]; then
836 . /etc/slitaz/cook.conf
837 . $WOK/$pkg/taz/$pkg-*/receipt
838 echo "Updating chroot environment..."
839 echo "Updating chroot: $pkg (${VERSION}${EXTRAVERSION})" | log
840 cd $PKGS && tazpkg install \
841 $pkg-${VERSION}${EXTRAVERSION}.tazpkg --forced
842 fi
843 exit $status
844 }
846 # Create a XML feed for freshly builded package.
847 gen_rss() {
848 pubdate=$(date "+%a, %d %b %Y %X")
849 cat > $FEEDS/$pkg.xml << EOT
850 <item>
851 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
852 <link>${COOKER_URL}?pkg=$PACKAGE</link>
853 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
854 <pubDate>$pubdate</pubDate>
855 <description>$SHORT_DESC</description>
856 </item>
857 EOT
858 }
860 #
861 # Commands
862 #
864 case "$1" in
865 usage|help|-u|-h)
866 usage ;;
867 list-wok)
868 gettext -e "\nList of packages in:"; echo " $WOK"
869 separator
870 cd $WOK && ls -1
871 separator
872 echo -n "Packages: " && ls | wc -l
873 echo "" ;;
874 search)
875 # Just a simple search function, we dont need more actually.
876 query="$2"
877 gettext -e "\nSearch results for:"; echo " $query"
878 separator
879 cd $WOK && ls -1 | grep "$query"
880 separator && echo "" ;;
881 setup)
882 # Setup a build environment
883 check_root
884 echo "Cook: setting up the environment" | log
885 gettext -e "\nSetting up your environment\n"
886 separator && cd $SLITAZ
887 init_db_files
888 gettext -e "Checking for packages to install...\n"
889 case " $@ " in
890 *\ --reinstall\ *)
891 INSTALL_LIST=""
892 for pkg in $(mkinstall_list $SETUP_PKGS); do
893 tazpkg get-install $pkg --forced
894 done ;;
895 *)
896 for pkg in $SETUP_PKGS
897 do
898 [ ! -f "$INSTALLED/$pkg/receipt" ] &&
899 tazpkg get-install $pkg
900 done ;;
901 esac
903 # Handle --options
904 case "$2" in
905 --wok|-w)
906 hg clone $WOK_URL wok || exit 1 ;;
907 --stable)
908 hg clone $WOK_URL-stable wok || exit 1 ;;
909 --undigest)
910 hg clone $WOK_URL-undigest wok || exit 1 ;;
911 esac
913 # SliTaz group and permissions
914 if ! grep -q ^slitaz /etc/group; then
915 gettext -e "Adding group: slitaz\n"
916 addgroup slitaz
917 fi
918 gettext -e "Setting permissions for slitaz group...\n"
919 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
920 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
921 separator
922 gettext -e "All done, ready to cook packages :-)\n\n" ;;
923 arm-setup)
924 # Setup fro cross ARM compiling.
925 sed -i \
926 -e s'/ARCH=.*/ARCH="arm"/' \
927 -e s'/CFLAGS=.*/CFLAGS=""/' \
928 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
929 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux-gnueabi/' \
930 /etc/slitaz/cook.conf
931 . /etc/slitaz/cook.conf
932 echo "Target arch : $ARCH"
933 echo "Configure args: $CONFIGURE_ARGS"
934 if [ -x /usr/cross/$ARCH/bin/${HOST_SYSTEM}-gcc ]; then
935 echo "Cross compiler: ${HOST_SYSTEM}-gcc"
936 else
937 echo "ERROR: C compiler is missing: ${HOST_SYSTEM}-gcc"
938 echo "Run 'cross compile' for cook a toolchain"
939 fi ;;
940 test)
941 # Test a cook environment.
942 echo "Cook test: testing the cook environment" | log
943 [ ! -d "$WOK" ] && exit 1
944 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
945 cook cooktest ;;
946 new)
947 # Create the package folder and an empty receipt.
948 pkg="$2"
949 [ "$pkg" ] || usage
950 echo ""
951 if [ -d "$WOK/$pkg" ]; then
952 echo -n "$pkg " && gettext "package already exists."
953 echo -e "\n" && exit 1
954 fi
955 gettext "Creating"; echo -n " $WOK/$pkg"
956 mkdir $WOK/$pkg && cd $WOK/$pkg && status
957 gettext "Preparing the package receipt..."
958 cp $DATA/receipt .
959 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
960 status && echo ""
962 # Interactive mode, asking and seding.
963 case "$3" in
964 --interactive|-x)
965 gettext -e "Entering interactive mode...\n"
966 separator
967 echo "Package : $pkg"
968 # Version.
969 echo -n "Version : " ; read anser
970 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
971 # Category.
972 echo -n "Category : " ; read anser
973 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
974 # Short description.
975 echo -n "Short desc : " ; read anser
976 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
977 # Maintainer.
978 echo -n "Maintainer : " ; read anser
979 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
980 # Web site.
981 echo -n "Web site : " ; read anser
982 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
983 echo ""
984 # Wget URL.
985 echo "Wget URL to download source tarball."
986 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
987 echo -n "Wget url : " ; read anser
988 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
989 # Ask for a stuff dir.
990 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
991 if [ "$anser" = "y" ]; then
992 echo -n "Creating the stuff directory..."
993 mkdir $WOK/$pkg/stuff && status
994 fi
995 # Ask for a description file.
996 echo -n "Are you going to write a description ? (y/N) : " ; read anser
997 if [ "$anser" = "y" ]; then
998 echo -n "Creating the description.txt file..."
999 echo "" > $WOK/$pkg/description.txt && status
1000 fi
1001 separator
1002 gettext -e "Receipt is ready to use.\n"
1003 echo "" ;;
1004 esac ;;
1005 list)
1006 # Cook a list of packages (better use the Cooker since it will order
1007 # packages before executing cook).
1008 check_root
1009 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
1010 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
1011 echo -e " $2\n" && exit 1
1012 echo "Cook list starting: $2" | log
1013 for pkg in $(cat $2)
1014 do
1015 cook $pkg || broken
1016 done ;;
1017 clean-wok)
1018 check_root
1019 gettext -e "\nCleaning all packages files..."
1020 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1021 status && echo "" ;;
1022 clean-src)
1023 check_root
1024 gettext -e "\nCleaning all packages sources..."
1025 rm -rf $WOK/*/source
1026 status && echo "" ;;
1027 pkgdb)
1028 # Create suitable packages list for TazPKG and only for built packages
1029 # as well as flavors files for TazLiTo. We dont need logs since we do it
1030 # manually to ensure everything is fine before syncing the mirror.
1031 case "$2" in
1032 --flavors)
1033 continue ;;
1034 *)
1035 [ "$2" ] && PKGS="$2"
1036 [ ! -d "$PKGS" ] && \
1037 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1 ;;
1038 esac
1039 time=$(date +%s)
1040 flavors=$SLITAZ/flavors
1041 live=$SLITAZ/live
1042 echo "cook:pkgdb" > $command
1043 echo "Cook pkgdb: Creating all packages lists" | log
1044 echo ""
1045 gettext "Creating lists for: "; echo "$PKGS"
1046 separator
1047 gettext "Cook pkgdb started: "; date "+%Y-%m-%d %H:%M"
1048 cd $PKGS
1049 rm -f packages.*
1050 gettext -e "Creating: packages.list\n"
1051 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1052 gettext -e "Creating: packages.md5\n"
1053 md5sum *.tazpkg > $PKGS/packages.md5
1054 md5sum packages.md5 | cut -f1 -d' ' > ID
1055 gettext -e "Creating lists from: "; echo "$WOK"
1056 cd $WOK
1057 for pkg in *
1058 do
1059 unset_receipt
1060 . $pkg/receipt
1061 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1062 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1063 if [ -s $pkg/taz/*/receipt ]; then
1064 . $pkg/taz/*/receipt
1065 fi
1066 # packages.desc lets us search easily in DB
1067 cat >> $PKGS/packages.desc << EOT
1068 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1069 EOT
1070 # packages.txt used by tazpkg and tazpkg-web also to provide
1071 # a human readable package list with version and description.
1072 cat >> $PKGS/packages.txt << EOT
1073 $PACKAGE
1074 ${VERSION}$EXTRAVERSION
1075 $SHORT_DESC
1076 $PACKED_SIZE ($UNPACKED_SIZE installed)
1078 EOT
1079 # packages.equiv is used by tazpkg install to check depends.
1080 for i in $PROVIDE; do
1081 DEST=""
1082 echo $i | fgrep -q : && DEST="${i#*:}:"
1083 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1084 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1085 $PKGS/packages.equiv
1086 else
1087 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1088 fi
1089 done
1090 # files.list provides a list of all packages files.
1091 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1092 $PKGS/files.list
1093 fi
1094 done
1096 # Display list size.
1097 gettext -e "Done: packages.desc\n"
1098 gettext -e "Done: packages.txt\n"
1099 gettext -e "Done: packages.equiv\n"
1101 # files.list.lzma
1102 gettext -e "Creating: files.list.lzma\n"
1103 cd $PKGS && lzma e files.list files.list.lzma
1104 rm -f files.list
1106 # Display some info.
1107 separator
1108 nb=$(ls $PKGS/*.tazpkg | wc -l)
1109 time=$(($(date +%s) - $time))
1110 echo -e "Packages: $nb - Time: ${time}s\n"
1112 # Create all flavors files at once. Do we really need code to monitor
1113 # flavors changes ? Lets just build them with packages lists before
1114 # syncing the mirror.
1115 [ "$2" == "--flavors" ] || exit 1
1116 [ ! -d "$flavors" ] && echo -e "Missing flavors: $flavors\n" && exit 1
1117 [ -d "$live" ] || mkdir -p $live
1118 gettext "Creating flavors files in:"; echo " $live"
1119 echo "Cook pkgdb: Creating all flavors" | log
1120 separator
1121 gettext -e "Recharging lists to use latest packages...\n"
1122 tazpkg recharge >/dev/null 2>/dev/null
1124 # We need a custom tazlito config to set working dir to /home/slitaz.
1125 if [ ! -f "$live/tazlito.conf" ]; then
1126 echo "Creating configuration file: tazlito.conf"
1127 cp /etc/tazlito/tazlito.conf $live
1128 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1129 $live/tazlito.conf
1130 fi
1132 # Update Hg flavors repo and pack.
1133 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
1135 cd $live
1136 echo "Starting to generate flavors..."
1137 rm -f flavors.list *.flavor
1138 for i in $flavors/*
1139 do
1140 fl=$(basename $i)
1141 echo "Packing flavor: $(basename $i)"
1142 tazlito pack-flavor $fl >/dev/null || exit 1
1143 tazlito show-flavor $fl --brief --noheader 2> \
1144 /dev/null >> flavors.list
1145 done
1146 cp -f $live/*.flavor $live/flavors.list $PKGS
1147 separator && gettext "Flavors size: "; du -sh $live | awk '{print $1}'
1148 echo "" && rm -f $command ;;
1149 *)
1150 # Just cook and generate a package.
1151 check_root
1152 time=$(date +%s)
1153 pkg="$1"
1154 [ -z "$pkg" ] && usage
1155 receipt="$WOK/$pkg/receipt"
1156 check_pkg_in_wok && echo ""
1158 # Skip blocked, 3 lines also for the Cooker.
1159 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1160 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
1161 fi
1163 try_aufs_chroot "$@"
1165 # Log and source receipt.
1166 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1167 echo "cook:$pkg" > $command
1169 # Display and log info if cook process stopped.
1170 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
1171 tee -a $LOGS/$pkg.log' INT
1173 unset inst
1174 unset_receipt
1175 . $receipt
1177 # Handle --options
1178 case "$2" in
1179 --clean|-c)
1180 gettext -e "Cleaning:"; echo -n " $pkg"
1181 cd $WOK/$pkg && rm -rf install taz source
1182 status && echo "" && exit 0 ;;
1183 --install|-i)
1184 inst='yes' ;;
1185 --getsrc|-gs)
1186 gettext "Getting source for:"; echo " $pkg"
1187 separator && get_source
1188 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
1189 --block|-b)
1190 gettext "Blocking:"; echo -n " $pkg"
1191 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1192 status && echo "" && exit 0 ;;
1193 --unblock|-ub)
1194 gettext "Unblocking:"; echo -n " $pkg"
1195 sed -i "/^${pkg}$/"d $blocked
1196 status && echo "" && exit 0 ;;
1198 esac
1200 # Check if wanted is built now so we have separate log files.
1201 for wanted in $WANTED ; do
1202 if grep -q "^$wanted$" $blocked; then
1203 echo "WANTED package is blocked: $wanted" | tee $LOGS/$pkg.log
1204 echo "" && rm -f $command && exit 1
1205 fi
1206 if grep -q "^$wanted$" $broken; then
1207 echo "WANTED package is broken: $wanted" | tee $LOGS/$pkg.log
1208 echo "" && rm -f $command && exit 1
1209 fi
1210 if [ ! -d "$WOK/$wanted/install" ]; then
1211 cook "$wanted" || exit 1
1212 fi
1213 done
1215 # Cook and pack or exit on error and log everything.
1216 cookit $@ 2>&1 | tee $LOGS/$pkg.log
1217 remove_deps | tee -a $LOGS/$pkg.log
1218 cookit_quality
1219 packit 2>&1 | tee -a $LOGS/$pkg.log
1220 clean_log
1222 # Exit if any error in packing.
1223 if grep -q ^ERROR $LOGS/$pkg.log; then
1224 debug_info | tee -a $LOGS/$pkg.log
1225 rm -f $command && exit 1
1226 fi
1228 # Create an XML feed
1229 gen_rss
1231 # Time and summary
1232 time=$(($(date +%s) - $time))
1233 summary | tee -a $LOGS/$pkg.log
1234 echo ""
1236 # Install package if requested
1237 if [ "$inst" ]; then
1238 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1239 cd $PKGS && tazpkg install \
1240 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1241 else
1242 gettext -e "Unable to install package, build has failed.\n\n"
1243 exit 1
1244 fi
1245 fi
1247 # Install package if part of the chroot to keep env up-to-date.
1248 if [ -d "$INSTALLED/$PACKAGE" ] && [ -z "$AUFS_MOUNTS" ]; then
1249 echo "Updating chroot environment..."
1250 echo "Updating chroot: $PACKAGE (${VERSION}${EXTRAVERSION})" | log
1251 cd $PKGS && tazpkg install \
1252 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1253 fi
1255 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1256 # You want automation: use the Cooker Build Bot.
1257 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
1258 rm -f $command ;;
1259 esac
1261 exit 0