cookutils view cook @ rev 422

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