cookutils view cook @ rev 381

cook: one check is sufficiante
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 12 22:04:31 2012 +0200 (2012-05-12)
parents 4fea0cdc9cfd
children 6d02863a68ab
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_BUGS
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-tools.
430 case "$ARCH" in
431 arm|x86_64)
432 # CROSS_COMPILE is used by at leat Busybox and the kernel to set
433 # the cross-tools prefix.
434 echo "cook: adding /usr/cross/$ARCH/bin to PATH"
435 export PATH=$PATH:/usr/cross/$ARCH/bin
436 export CROSS_COMPILE=$HOST_SYSTEM-
437 echo "cook: using cross-tools: $CROSS_COMPILE"
438 export CC=${HOST_SYSTEM}-gcc
439 export CXX=${HOST_SYSTEM}-g++
440 export AR=${HOST_SYSTEM}-ar
441 export AS=${HOST_SYSTEM}-as
442 export RANLIB=${HOST_SYSTEM}-ranlib
443 export LD=${HOST_SYSTEM}-ld
444 export STRIP=${HOST_SYSTEM}-strip ;;
445 esac
447 [ "$QA" ] && receipt_quality
448 cd $pkgdir
449 rm -rf install taz source
451 # Disable -pipe if less than 512Mb free RAM.
452 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
453 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
454 gettext -e "Disabling -pipe compile flag: $free RAM\n"
455 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
456 CXXFLAGS="${CXXFLAGS/-pipe}" && \
457 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
458 fi
459 unset free
461 # Export flags and path to be used by make and receipt.
462 DESTDIR=$pkgdir/install
463 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
464 #LDFLAGS
466 # Check for build deps and handle implicit depends of *-dev packages
467 # (ex: libusb-dev :: libusb).
468 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
469 touch $CACHE/installed.local $CACHE/installed.web
470 [ "$BUILD_DEPENDS" ] && gettext -e "Checking build dependencies...\n"
471 for dep in $BUILD_DEPENDS
472 do
473 implicit=${dep%-dev}
474 for i in $dep $implicit
475 do
476 if [ ! -f "$INSTALLED/$i/receipt" ]; then
477 # Try local package first. In some cases implicit doesn't exist, ex:
478 # libboost-dev exists but not libboost, so check if we got vers.
479 unset vers
480 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
481 if [ -f "$PKGS/$i-$vers.tazpkg" ]; then
482 echo $i-$vers.tazpkg >> $CACHE/installed.local
483 else
484 # Priority to package version in wok (maybe more up-to-date)
485 # than the mirrored one.
486 if [ "$vers" ]; then
487 if fgrep -q $i-$vers $DB/packages.list; then
488 echo $i >> $CACHE/installed.web
489 else
490 # So package exists in wok but not available.
491 gettext "Missing dep (wok/pkg):"; echo " $i $vers"
492 echo $i >> $CACHE/missing.dep
493 fi
494 else
495 # Package is not in wok but may be in repo.
496 if fgrep -q $i-$vers $DB/packages.list; then
497 echo $i >> $CACHE/installed.web
498 else
499 echo "ERROR: unknown dep $i" && exit 1
500 fi
501 fi
502 fi
503 fi
504 done
505 done
507 # Get the list of installed packages
508 cd $INSTALLED && ls -1 > $CACHE/installed.list
510 # Have we a missing build dep to cook ?
511 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
512 gettext -e "Auto cook config is set : AUTO_COOK\n"
513 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
514 for i in $(uniq $CACHE/missing.dep)
515 do
516 (gettext "Building dep (wok/pkg) :"; echo " $i $vers") | \
517 tee -a $LOGS/$PACKAGE.log.$$
518 cook $i || (echo -e "ERROR: can't cook dep '$i'\n" && \
519 fgrep "remove: " $LOGS/$i.log && \
520 fgrep "Removing: " $LOGS/$i.log && echo "") | \
521 tee -a $LOGS/$PACKAGE.log.$$ && break
522 done
523 rm -f $CACHE/missing.dep
524 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
525 fi
527 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
528 # is enabled and cook fails we have ERROR in log, if no auto cook we have
529 # missing dep in cached file.
530 if fgrep -q "ERROR:" $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
531 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
532 echo "ERROR: missing dep $nb" && exit 1
533 fi
535 # Install local packages.
536 cd $PKGS
537 for i in $(uniq $CACHE/installed.local)
538 do
539 gettext "Installing dep (pkg/local):"; echo " $i"
540 tazpkg install $i >/dev/null
541 done
543 # Install web or cached packages (if mirror is set to $PKGS we only
544 # use local packages).
545 for i in $(uniq $CACHE/installed.web)
546 do
547 gettext "Installing dep (web/cache):"; echo " $i"
548 tazpkg get-install $i >/dev/null
549 done
551 # If a cook failed deps are removed.
552 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
553 [ ! -s "installed.cook.diff" ] && \
554 busybox diff installed.list installed.cook > installed.cook.diff
555 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
557 # Get source tarball and make sure we have source dir named:
558 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
559 # tarball if it exists.
560 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
561 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
562 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
563 LZMA_SRC=""
564 else
565 get_source || exit 1
566 fi
567 fi
568 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
569 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
570 if ! extract_source ; then
571 get_source
572 extract_source || exit 1
573 fi
574 if [ "$LZMA_SRC" ]; then
575 cd $pkgdir/source
576 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
577 mv tmp tmp-1 && mkdir tmp
578 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
579 fi
580 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
581 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
582 fi
583 fi
584 cd $pkgdir/source/tmp
585 # Some archives are not well done and don't extract to one dir (ex lzma).
586 files=$(ls | wc -l)
587 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
588 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
589 mv * ../$PACKAGE-$VERSION/$TARBALL
590 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
591 mv * ../$PACKAGE-$VERSION
592 cd .. && rm -rf tmp
593 fi
595 # Execute receipt rules.
596 if grep -q ^compile_rules $receipt; then
597 echo "Executing: compile_rules"
598 echo "CFLAGS : $CFLAGS"
599 #echo "LDFLAGS : $LDFLAGS"
600 [ -d "$src" ] && cd $src
601 compile_rules $@ || exit 1
602 # Stay compatible with _pkg
603 [ -d "$src/_pkg" ] && mv $src/_pkg $install
604 # QA: compile_rules success so valid.
605 mkdir -p $install
606 else
607 # QA: No compile_rules so no error, valid.
608 mkdir -p $install
609 fi
610 separator && echo ""
612 # Execute testsuite.
613 if grep -q ^testsuite $receipt; then
614 echo "Running testsuite"
615 separator
616 testsuite $@ || exit 1
617 separator && echo ""
618 fi
619 }
621 # Cook quality assurance.
622 cookit_quality() {
623 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
624 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
625 fi
626 # ERROR can be echoed any time in cookit()
627 if fgrep -q ERROR: $LOGS/$pkg.log; then
628 debug_info | tee -a $LOGS/$pkg.log
629 rm -f $command && exit 1
630 fi
631 }
633 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
634 # but it doesn't handle EXTRAVERSION.
635 packit() {
636 set_paths
638 # Handle cross compilation
639 case "$ARCH" in
640 arm|x86_64) VERSION="$VERSION-$ARCH" ;;
641 esac
643 echo "Pack: $PACKAGE $VERSION"
644 separator
646 if grep -q ^genpkg_rules $receipt; then
647 gettext -e "Executing: genpkg_rules\n"
648 set -e && cd $pkgdir && mkdir -p $fs
649 genpkg_rules || echo -e "\nERROR: genpkg_rules failed\n" >> \
650 $LOGS/$pkg.log
651 else
652 gettext "No packages rules: meta package"; echo
653 mkdir -p $fs
654 fi
656 # First QA check to stop now if genpkg_rules failed.
657 if fgrep -q ERROR: $LOGS/$pkg.log; then
658 exit 1
659 fi
661 cd $taz
662 for file in receipt description.txt
663 do
664 [ ! -f "../$file" ] && continue
665 gettext "Copying"; echo -n " $file..."
666 cp -f ../$file $pack && chown 0.0 $pack/$file && status
667 done
668 copy_generic_files
670 # Create files.list with redirecting find output.
671 gettext "Creating the list of files..." && cd $fs
672 find . -type f -print > ../files.list
673 find . -type l -print >> ../files.list
674 cd .. && sed -i s/'^.'/''/ files.list
675 status
677 # Strip and stuff files.
678 strip_package
680 # Md5sum of files.
681 gettext "Creating md5sum of files..."
682 while read file; do
683 [ -L "fs$file" ] && continue
684 [ -f "fs$file" ] || continue
685 case "$file" in
686 /lib/modules/*/modules.*|*.pyc) continue ;;
687 esac
688 md5sum "fs$file" | sed 's/ fs/ /'
689 done < files.list > md5sum
690 status
691 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
692 description.txt 2> /dev/null | awk \
693 '{ sz=$1 } END { print sz }')
695 # Build cpio archives.
696 gettext "Compressing the fs... "
697 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
698 rm -rf fs
699 status
700 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
701 md5sum description.txt 2> /dev/null | awk \
702 '{ sz=$1 } END { print sz }')
703 gettext "Updating receipt sizes..."
704 sed -i s/^PACKED_SIZE.*$// receipt
705 sed -i s/^UNPACKED_SIZE.*$// receipt
706 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
707 status
709 # Set extra version.
710 if [ "$EXTRAVERSION" ]; then
711 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
712 sed -i s/^EXTRAVERSION.*$// receipt
713 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
714 status
715 fi
717 # Compress.
718 gettext "Creating full cpio archive... "
719 find . -print | cpio -o -H newc --quiet > \
720 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
721 status
722 gettext "Restoring original package tree... "
723 unlzma -c fs.cpio.lzma | cpio -idm --quiet
724 status
725 rm fs.cpio.lzma && cd ..
727 # QA and give info.
728 tazpkg=$(ls *.tazpkg)
729 packit_quality
730 separator && gettext "Package:"; echo -e " $tazpkg\n"
731 }
733 # Verify package quality and consistency.
734 packit_quality() {
735 #gettext "QA: Checking for broken link..."
736 #link=$(find $fs/usr -type l -follow)
737 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
738 #status
740 # Exit if any error found in log file.
741 if fgrep -q ERROR: $LOGS/$pkg.log; then
742 rm -f $command && exit 1
743 fi
745 gettext "QA: Checking for empty package..."
746 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
747 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
748 echo -e "\nERROR: empty package"
749 rm -f $command && exit 1
750 else
751 # Ls sort by name so the first file is the one we want.
752 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
753 status
754 if [ -f "$old" ]; then
755 gettext "Removing old: $(basename $old)"
756 rm -f $old && status
757 fi
758 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
759 sed -i /^${pkg}$/d $broken
760 #gettext "Removing source tree..."
761 #rm -f $WOK/$pkg/source && status
762 fi
763 }
765 mkinstall_list() {
766 local pkg
767 for pkg in $@ ; do
768 case " $INSTALL_LIST " in
769 *\ $pkg\ *) continue ;;
770 *) if [ -s /home/slitaz/wok/$pkg/receipt ]; then
771 unset DEPENDS
772 . /home/slitaz/wok/$pkg/receipt
773 INSTALL_LIST="$INSTALL_LIST $pkg"
774 [ -n "$DEPENDS" ] && mkinstall_list $DEPENDS
775 fi
776 echo $pkg
777 esac
778 done
779 }
781 tac()
782 {
783 sed '1!G;h;$!d' $1
784 }
786 # Launch the cook command into a chroot jail protected by aufs.
787 # The current filesystems are used read-only and updates are
788 # stored in a separate branch.
789 try_aufs_chroot() {
791 base=/dev/shm/aufsmnt$$
793 # Can we setup the chroot ? Is it already done ?
794 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
795 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
796 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
797 mkdir ${base}root ${base}rw || return
799 echo "Setup aufs chroot..."
801 # Sanity check
802 for i in / /proc /sys /dev/shm /home ; do
803 case " $AUFS_MOUNTS " in
804 *\ $i\ *) ;;
805 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
806 esac
807 done
808 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
809 mount --bind $mnt ${base}root$mnt
810 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
811 echo "Aufs mountage failure"
812 umount ${base}root
813 rmdir ${base}*
814 return
815 fi
816 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
817 done
819 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
820 status=$?
822 echo "Leaving aufs chroot..."
823 tac ${base}rw/aufs-umount.sh | sh
824 rm -rf ${base}rw
825 umount ${base}root
826 rmdir $base*
828 # Install package if requested
829 if [ "$inst" ]; then
830 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
831 cd $PKGS && tazpkg install \
832 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
833 else
834 gettext -e "Unable to install package, build has failed.\n\n"
835 exit 1
836 fi
837 fi
839 # Skip install if target host dont match build system.
840 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
841 # Install package if part of the chroot to keep env up-to-date.
842 if [ -d "$INSTALLED/$pkg" ] && [ "$build" == "$ARCH" ]; then
843 . /etc/slitaz/cook.conf
844 . $WOK/$pkg/taz/$pkg-*/receipt
845 echo "Updating $ARCH chroot environment..."
846 echo "Updating chroot: $pkg (${VERSION}${EXTRAVERSION})" | log
847 cd $PKGS && tazpkg install \
848 $pkg-${VERSION}${EXTRAVERSION}.tazpkg --forced
849 fi
850 exit $status
851 }
853 # Create a XML feed for freshly builded package.
854 gen_rss() {
855 pubdate=$(date "+%a, %d %b %Y %X")
856 cat > $FEEDS/$pkg.xml << EOT
857 <item>
858 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
859 <link>${COOKER_URL}?pkg=$PACKAGE</link>
860 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
861 <pubDate>$pubdate</pubDate>
862 <description>$SHORT_DESC</description>
863 </item>
864 EOT
865 }
867 #
868 # Commands
869 #
871 case "$1" in
872 usage|help|-u|-h)
873 usage ;;
874 list-wok)
875 gettext -e "\nList of packages in:"; echo " $WOK"
876 separator
877 cd $WOK && ls -1
878 separator
879 echo -n "Packages: " && ls | wc -l
880 echo "" ;;
881 activity)
882 cat $activity ;;
883 search)
884 # Just a simple search function, we dont need more actually.
885 query="$2"
886 gettext -e "\nSearch results for:"; echo " $query"
887 separator
888 cd $WOK && ls -1 | grep "$query"
889 separator && echo "" ;;
890 setup)
891 # Setup a build environment
892 check_root
893 echo "Cook: setting up the environment" | log
894 gettext -e "\nSetting up your environment\n"
895 separator && cd $SLITAZ
896 init_db_files
897 gettext -e "Checking for packages to install...\n"
898 case " $@ " in
899 *\ --reinstall\ *)
900 INSTALL_LIST=""
901 for pkg in $(mkinstall_list $SETUP_PKGS); do
902 tazpkg get-install $pkg --forced
903 done ;;
904 *)
905 for pkg in $SETUP_PKGS
906 do
907 [ ! -f "$INSTALLED/$pkg/receipt" ] &&
908 tazpkg get-install $pkg
909 done ;;
910 esac
912 # Handle --options
913 case "$2" in
914 --wok|-w)
915 hg clone $WOK_URL wok || exit 1 ;;
916 --stable)
917 hg clone $WOK_URL-stable wok || exit 1 ;;
918 --undigest)
919 hg clone $WOK_URL-undigest wok || exit 1 ;;
920 esac
922 # SliTaz group and permissions
923 if ! grep -q ^slitaz /etc/group; then
924 gettext -e "Adding group: slitaz\n"
925 addgroup slitaz
926 fi
927 gettext -e "Setting permissions for slitaz group...\n"
928 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
929 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
930 separator
931 gettext -e "All done, ready to cook packages :-)\n\n" ;;
932 arm-setup)
933 # Setup fro cross ARM compiling.
934 sed -i \
935 -e s'/ARCH=.*/ARCH="arm"/' \
936 -e s'/CFLAGS=.*/CFLAGS="-march=armv6"/' \
937 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
938 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux-gnueabi/' \
939 /etc/slitaz/cook.conf
940 . /etc/slitaz/cook.conf
941 echo "Target arch : $ARCH"
942 echo "Configure args: $CONFIGURE_ARGS"
943 if [ -x /usr/cross/$ARCH/bin/${HOST_SYSTEM}-gcc ]; then
944 echo "Cross compiler: ${HOST_SYSTEM}-gcc"
945 else
946 echo "ERROR: C compiler is missing: ${HOST_SYSTEM}-gcc"
947 echo "Run 'cross compile' for cook a toolchain"
948 fi ;;
949 test)
950 # Test a cook environment.
951 echo "Cook test: testing the cook environment" | log
952 [ ! -d "$WOK" ] && exit 1
953 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
954 cook cooktest ;;
955 new)
956 # Create the package folder and an empty receipt.
957 pkg="$2"
958 [ "$pkg" ] || usage
959 echo ""
960 if [ -d "$WOK/$pkg" ]; then
961 echo -n "$pkg " && gettext "package already exists."
962 echo -e "\n" && exit 1
963 fi
964 gettext "Creating"; echo -n " $WOK/$pkg"
965 mkdir $WOK/$pkg && cd $WOK/$pkg && status
966 gettext "Preparing the package receipt..."
967 cp $DATA/receipt .
968 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
969 status && echo ""
971 # Interactive mode, asking and seding.
972 case "$3" in
973 --interactive|-x)
974 gettext -e "Entering interactive mode...\n"
975 separator
976 echo "Package : $pkg"
977 # Version.
978 echo -n "Version : " ; read anser
979 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
980 # Category.
981 echo -n "Category : " ; read anser
982 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
983 # Short description.
984 echo -n "Short desc : " ; read anser
985 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
986 # Maintainer.
987 echo -n "Maintainer : " ; read anser
988 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
989 # Web site.
990 echo -n "Web site : " ; read anser
991 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
992 echo ""
993 # Wget URL.
994 echo "Wget URL to download source tarball."
995 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
996 echo -n "Wget url : " ; read anser
997 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
998 # Ask for a stuff dir.
999 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
1000 if [ "$anser" = "y" ]; then
1001 echo -n "Creating the stuff directory..."
1002 mkdir $WOK/$pkg/stuff && status
1003 fi
1004 # Ask for a description file.
1005 echo -n "Are you going to write a description ? (y/N) : " ; read anser
1006 if [ "$anser" = "y" ]; then
1007 echo -n "Creating the description.txt file..."
1008 echo "" > $WOK/$pkg/description.txt && status
1009 fi
1010 separator
1011 gettext -e "Receipt is ready to use.\n"
1012 echo "" ;;
1013 esac ;;
1014 list)
1015 # Cook a list of packages (better use the Cooker since it will order
1016 # packages before executing cook).
1017 check_root
1018 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
1019 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
1020 echo -e " $2\n" && exit 1
1021 echo "Cook list starting: $2" | log
1022 for pkg in $(cat $2)
1023 do
1024 cook $pkg || broken
1025 done ;;
1026 clean-wok)
1027 check_root
1028 gettext -e "\nCleaning all packages files..."
1029 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1030 status && echo "" ;;
1031 clean-src)
1032 check_root
1033 gettext -e "\nCleaning all packages sources..."
1034 rm -rf $WOK/*/source
1035 status && echo "" ;;
1036 pkgdb)
1037 # Create suitable packages list for TazPKG and only for built packages
1038 # as well as flavors files for TazLiTo. We dont need logs since we do it
1039 # manually to ensure everything is fine before syncing the mirror.
1040 case "$2" in
1041 --flavors)
1042 continue ;;
1043 *)
1044 [ "$2" ] && PKGS="$2"
1045 [ ! -d "$PKGS" ] && \
1046 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1 ;;
1047 esac
1048 time=$(date +%s)
1049 flavors=$SLITAZ/flavors
1050 live=$SLITAZ/live
1051 echo "cook:pkgdb" > $command
1052 echo "Cook pkgdb: Creating all packages lists" | log
1053 echo ""
1054 gettext "Creating lists for: "; echo "$PKGS"
1055 separator
1056 gettext "Cook pkgdb started: "; date "+%Y-%m-%d %H:%M"
1057 cd $PKGS
1058 rm -f packages.*
1059 gettext -e "Creating: packages.list\n"
1060 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1061 gettext -e "Creating: packages.md5\n"
1062 md5sum *.tazpkg > $PKGS/packages.md5
1063 md5sum packages.md5 | cut -f1 -d' ' > ID
1064 gettext -e "Creating lists from: "; echo "$WOK"
1065 cd $WOK
1066 for pkg in *
1067 do
1068 unset_receipt
1069 . $pkg/receipt
1070 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1071 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1072 if [ -s $pkg/taz/*/receipt ]; then
1073 . $pkg/taz/*/receipt
1074 fi
1075 # packages.desc lets us search easily in DB
1076 cat >> $PKGS/packages.desc << EOT
1077 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1078 EOT
1079 # packages.txt used by tazpkg and tazpkg-web also to provide
1080 # a human readable package list with version and description.
1081 cat >> $PKGS/packages.txt << EOT
1082 $PACKAGE
1083 ${VERSION}$EXTRAVERSION
1084 $SHORT_DESC
1085 $PACKED_SIZE ($UNPACKED_SIZE installed)
1087 EOT
1088 # packages.equiv is used by tazpkg install to check depends.
1089 for i in $PROVIDE; do
1090 DEST=""
1091 echo $i | fgrep -q : && DEST="${i#*:}:"
1092 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1093 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1094 $PKGS/packages.equiv
1095 else
1096 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1097 fi
1098 done
1099 # files.list provides a list of all packages files.
1100 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1101 $PKGS/files.list
1102 fi
1103 done
1105 # Display list size.
1106 gettext -e "Done: packages.desc\n"
1107 gettext -e "Done: packages.txt\n"
1108 gettext -e "Done: packages.equiv\n"
1110 # files.list.lzma
1111 gettext -e "Creating: files.list.lzma\n"
1112 cd $PKGS && lzma e files.list files.list.lzma
1113 rm -f files.list
1115 # Display some info.
1116 separator
1117 nb=$(ls $PKGS/*.tazpkg | wc -l)
1118 time=$(($(date +%s) - $time))
1119 echo -e "Packages: $nb - Time: ${time}s\n"
1121 # Create all flavors files at once. Do we really need code to monitor
1122 # flavors changes ? Lets just build them with packages lists before
1123 # syncing the mirror.
1124 [ "$2" == "--flavors" ] || exit 1
1125 [ ! -d "$flavors" ] && echo -e "Missing flavors: $flavors\n" && exit 1
1126 [ -d "$live" ] || mkdir -p $live
1127 gettext "Creating flavors files in:"; echo " $live"
1128 echo "Cook pkgdb: Creating all flavors" | log
1129 separator
1130 gettext -e "Recharging lists to use latest packages...\n"
1131 tazpkg recharge >/dev/null 2>/dev/null
1133 # We need a custom tazlito config to set working dir to /home/slitaz.
1134 if [ ! -f "$live/tazlito.conf" ]; then
1135 echo "Creating configuration file: tazlito.conf"
1136 cp /etc/tazlito/tazlito.conf $live
1137 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1138 $live/tazlito.conf
1139 fi
1141 # Update Hg flavors repo and pack.
1142 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
1144 cd $live
1145 echo "Starting to generate flavors..."
1146 rm -f flavors.list *.flavor
1147 for i in $flavors/*
1148 do
1149 fl=$(basename $i)
1150 echo "Packing flavor: $(basename $i)"
1151 tazlito pack-flavor $fl >/dev/null || exit 1
1152 tazlito show-flavor $fl --brief --noheader 2> \
1153 /dev/null >> flavors.list
1154 done
1155 cp -f $live/*.flavor $live/flavors.list $PKGS
1156 separator && gettext "Flavors size: "; du -sh $live | awk '{print $1}'
1157 echo "" && rm -f $command ;;
1158 *)
1159 # Just cook and generate a package.
1160 check_root
1161 time=$(date +%s)
1162 pkg="$1"
1163 [ -z "$pkg" ] && usage
1164 receipt="$WOK/$pkg/receipt"
1165 check_pkg_in_wok && echo ""
1167 unset inst
1168 unset_receipt
1169 . $receipt
1171 # Handle cross compilation.
1173 # CROSS_NOTE: Actually we are running an ARM cooker but running
1174 # the cooker and build each commit in wok is not possible since
1175 # we dont cook the full wok for this arch. For ARM we need a set
1176 # of packages to handle a touch sreen desktop, servers but not
1177 # erland.
1179 # The temporary solution is to build only reviewed and tested
1180 # packages with HOST_ARCH set in receipt.
1181 case "$ARCH" in
1182 arm)
1183 if [ ! "$HOST_ARCH" ]; then
1184 echo "cook: HOST_ARCH is not set in $pkg receipt"
1185 echo "cook: This package is not include in: $ARCH"
1186 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1187 echo "Cook skip: $pkg is not include in: $ARCH" | log
1188 echo "" && exit 1
1189 fi ;;
1190 esac
1192 # Some packages are not include in some arch or fails to cross compile.
1193 if ! $(echo "$HOST_ARCH" | fgrep -q $ARCH); then
1194 echo "cook: HOST_ARCH=$HOST_ARCH"
1195 echo "cook: $pkg dont cook or is not include in: $ARCH"
1196 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1197 echo "Cook skip: $pkg dont cook or is not include in: $ARCH" | log
1198 echo "" && exit 1
1199 fi
1201 # Skip blocked, 3 lines also for the Cooker.
1202 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1203 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
1204 fi
1206 try_aufs_chroot "$@"
1208 # Log and source receipt.
1209 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1210 echo "cook:$pkg" > $command
1212 # Display and log info if cook process stopped.
1213 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
1214 tee -a $LOGS/$pkg.log' INT
1216 # Handle --options
1217 case "$2" in
1218 --clean|-c)
1219 gettext -e "Cleaning:"; echo -n " $pkg"
1220 cd $WOK/$pkg && rm -rf install taz source
1221 status && echo "" && exit 0 ;;
1222 --install|-i)
1223 inst='yes' ;;
1224 --getsrc|-gs)
1225 gettext "Getting source for:"; echo " $pkg"
1226 separator && get_source
1227 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
1228 --block|-b)
1229 gettext "Blocking:"; echo -n " $pkg"
1230 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1231 status && echo "" && exit 0 ;;
1232 --unblock|-ub)
1233 gettext "Unblocking:"; echo -n " $pkg"
1234 sed -i "/^${pkg}$/"d $blocked
1235 status && echo "" && exit 0 ;;
1237 esac
1239 # Check if wanted is built now so we have separate log files.
1240 for wanted in $WANTED ; do
1241 if grep -q "^$wanted$" $blocked; then
1242 echo "WANTED package is blocked: $wanted" | tee $LOGS/$pkg.log
1243 echo "" && rm -f $command && exit 1
1244 fi
1245 if grep -q "^$wanted$" $broken; then
1246 echo "WANTED package is broken: $wanted" | tee $LOGS/$pkg.log
1247 echo "" && rm -f $command && exit 1
1248 fi
1249 if [ ! -d "$WOK/$wanted/install" ]; then
1250 cook "$wanted" || exit 1
1251 fi
1252 done
1254 # Cook and pack or exit on error and log everything.
1255 cookit $@ 2>&1 | tee $LOGS/$pkg.log
1256 remove_deps | tee -a $LOGS/$pkg.log
1257 cookit_quality
1258 packit 2>&1 | tee -a $LOGS/$pkg.log
1259 clean_log
1261 # Exit if any error in packing.
1262 if grep -q ^ERROR $LOGS/$pkg.log; then
1263 debug_info | tee -a $LOGS/$pkg.log
1264 rm -f $command && exit 1
1265 fi
1267 # Create an XML feed
1268 gen_rss
1270 # Time and summary
1271 time=$(($(date +%s) - $time))
1272 summary | tee -a $LOGS/$pkg.log
1273 echo ""
1275 # Install package if requested
1276 if [ "$inst" ]; then
1277 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1278 cd $PKGS && tazpkg install \
1279 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1280 else
1281 gettext -e "Unable to install package, build has failed.\n\n"
1282 exit 1
1283 fi
1284 fi
1286 # Skip install if target host dont match build system.
1287 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
1288 # Install package if part of the chroot to keep env up-to-date.
1289 if [ -d "$INSTALLED/$PACKAGE" ] && [ -z "$AUFS_MOUNTS" ] && \
1290 [ "$build" == "$ARCH" ]; then
1291 echo "Updating chroot environment..."
1292 echo "Updating chroot: $PACKAGE (${VERSION}${EXTRAVERSION})" | log
1293 cd $PKGS && tazpkg install \
1294 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1295 fi
1297 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1298 # You want automation: use the Cooker Build Bot.
1299 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
1300 rm -f $command ;;
1301 esac
1303 exit 0