cookutils view cook @ rev 425

cross: glibc --enable-kernel=2.6.32
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 19 23:40:17 2012 +0200 (2012-05-19)
parents b2edbfaef132
children 539039df832c
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 *-setup $(gettext "Setup a cross environment.")
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 # Set root path when cross compiling. ARM tested but not x86_64
539 case "$ARCH" in
540 arm) root=$CROSS_PREFIX ;;
541 esac
543 # Install local packages.
544 cd $PKGS
545 for i in $(uniq $CACHE/installed.local)
546 do
547 gettext "Installing dep (pkg/local):"; echo " $i"
548 tazpkg install $i --root=$root >/dev/null
549 done
551 # Install web or cached packages (if mirror is set to $PKGS we only
552 # use local packages).
553 for i in $(uniq $CACHE/installed.web)
554 do
555 gettext "Installing dep (web/cache):"; echo " $i"
556 tazpkg get-install $i --root=$root >/dev/null
557 done
559 # If a cook failed deps are removed.
560 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
561 [ ! -s "installed.cook.diff" ] && \
562 busybox diff installed.list installed.cook > installed.cook.diff
563 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
565 # Get source tarball and make sure we have source dir named:
566 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
567 # tarball if it exists.
568 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
569 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
570 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
571 LZMA_SRC=""
572 else
573 get_source || exit 1
574 fi
575 fi
576 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
577 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
578 if ! extract_source ; then
579 get_source
580 extract_source || exit 1
581 fi
582 if [ "$LZMA_SRC" ]; then
583 cd $pkgdir/source
584 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
585 mv tmp tmp-1 && mkdir tmp
586 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
587 fi
588 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
589 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
590 fi
591 fi
592 cd $pkgdir/source/tmp
593 # Some archives are not well done and don't extract to one dir (ex lzma).
594 files=$(ls | wc -l)
595 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
596 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
597 mv * ../$PACKAGE-$VERSION/$TARBALL
598 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
599 mv * ../$PACKAGE-$VERSION
600 cd .. && rm -rf tmp
601 fi
603 # Execute receipt rules.
604 if grep -q ^compile_rules $receipt; then
605 echo "Executing: compile_rules"
606 echo "CFLAGS : $CFLAGS"
607 #echo "LDFLAGS : $LDFLAGS"
608 [ -d "$src" ] && cd $src
609 compile_rules $@ || exit 1
610 # Stay compatible with _pkg
611 [ -d "$src/_pkg" ] && mv $src/_pkg $install
612 # QA: compile_rules success so valid.
613 mkdir -p $install
614 else
615 # QA: No compile_rules so no error, valid.
616 mkdir -p $install
617 fi
618 separator && echo ""
620 # Execute testsuite.
621 if grep -q ^testsuite $receipt; then
622 echo "Running testsuite"
623 separator
624 testsuite $@ || exit 1
625 separator && echo ""
626 fi
627 }
629 # Cook quality assurance.
630 cookit_quality() {
631 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
632 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
633 fi
634 # ERROR can be echoed any time in cookit()
635 if fgrep -q ERROR: $LOGS/$pkg.log; then
636 debug_info | tee -a $LOGS/$pkg.log
637 rm -f $command && exit 1
638 fi
639 }
641 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
642 # but it doesn't handle EXTRAVERSION.
643 packit() {
644 set_paths
646 # Handle cross compilation
647 case "$ARCH" in
648 arm|x86_64) VERSION="$VERSION-$ARCH" ;;
649 esac
651 echo "Pack: $PACKAGE $VERSION"
652 separator
654 if grep -q ^genpkg_rules $receipt; then
655 gettext -e "Executing: genpkg_rules\n"
656 set -e && cd $pkgdir && mkdir -p $fs
657 genpkg_rules || echo -e "\nERROR: genpkg_rules failed\n" >> \
658 $LOGS/$pkg.log
659 else
660 gettext "No packages rules: meta package"; echo
661 mkdir -p $fs
662 fi
664 # First QA check to stop now if genpkg_rules failed.
665 if fgrep -q ERROR: $LOGS/$pkg.log; then
666 exit 1
667 fi
669 cd $taz
670 for file in receipt description.txt
671 do
672 [ ! -f "../$file" ] && continue
673 gettext "Copying"; echo -n " $file..."
674 cp -f ../$file $pack && chown 0.0 $pack/$file && status
675 done
676 copy_generic_files
678 # Create files.list with redirecting find output.
679 gettext "Creating the list of files..." && cd $fs
680 find . -type f -print > ../files.list
681 find . -type l -print >> ../files.list
682 cd .. && sed -i s/'^.'/''/ files.list
683 status
685 # Strip and stuff files.
686 strip_package
688 # Md5sum of files.
689 gettext "Creating md5sum of files..."
690 while read file; do
691 [ -L "fs$file" ] && continue
692 [ -f "fs$file" ] || continue
693 case "$file" in
694 /lib/modules/*/modules.*|*.pyc) continue ;;
695 esac
696 md5sum "fs$file" | sed 's/ fs/ /'
697 done < files.list > md5sum
698 status
699 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
700 description.txt 2> /dev/null | awk \
701 '{ sz=$1 } END { print sz }')
703 # Build cpio archives.
704 gettext "Compressing the fs... "
705 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
706 rm -rf fs
707 status
708 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
709 md5sum description.txt 2> /dev/null | awk \
710 '{ sz=$1 } END { print sz }')
711 gettext "Updating receipt sizes..."
712 sed -i s/^PACKED_SIZE.*$// receipt
713 sed -i s/^UNPACKED_SIZE.*$// receipt
714 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
715 status
717 # Set extra version.
718 if [ "$EXTRAVERSION" ]; then
719 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
720 sed -i s/^EXTRAVERSION.*$// receipt
721 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
722 status
723 fi
725 # Compress.
726 gettext "Creating full cpio archive... "
727 find . -print | cpio -o -H newc --quiet > \
728 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
729 status
730 gettext "Restoring original package tree... "
731 unlzma -c fs.cpio.lzma | cpio -idm --quiet
732 status
733 rm fs.cpio.lzma && cd ..
735 # QA and give info.
736 tazpkg=$(ls *.tazpkg)
737 packit_quality
738 separator && gettext "Package:"; echo -e " $tazpkg\n"
739 }
741 # Verify package quality and consistency.
742 packit_quality() {
743 #gettext "QA: Checking for broken link..."
744 #link=$(find $fs/usr -type l -follow)
745 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
746 #status
748 # Exit if any error found in log file.
749 if fgrep -q ERROR: $LOGS/$pkg.log; then
750 rm -f $command && exit 1
751 fi
753 gettext "QA: Checking for empty package..."
754 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
755 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
756 echo -e "\nERROR: empty package"
757 rm -f $command && exit 1
758 else
759 # Ls sort by name so the first file is the one we want.
760 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
761 status
762 if [ -f "$old" ]; then
763 gettext "Removing old: $(basename $old)"
764 rm -f $old && status
765 fi
766 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
767 sed -i /^${pkg}$/d $broken
768 #gettext "Removing source tree..."
769 #rm -f $WOK/$pkg/source && status
770 fi
771 }
773 tac() {
774 sed '1!G;h;$!d' $1
775 }
777 # Launch the cook command into a chroot jail protected by aufs.
778 # The current filesystems are used read-only and updates are
779 # stored in a separate branch.
780 try_aufs_chroot() {
782 base=/dev/shm/aufsmnt$$
784 # Can we setup the chroot ? Is it already done ?
785 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
786 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
787 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
788 mkdir ${base}root ${base}rw || return
790 echo "Setup aufs chroot..."
792 # Sanity check
793 for i in / /proc /sys /dev/shm /home ; do
794 case " $AUFS_MOUNTS " in
795 *\ $i\ *) ;;
796 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
797 esac
798 done
799 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
800 mount --bind $mnt ${base}root$mnt
801 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
802 echo "Aufs mountage failure"
803 umount ${base}root
804 rmdir ${base}*
805 return
806 fi
807 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
808 done
810 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
811 status=$?
813 echo "Leaving aufs chroot..."
814 tac ${base}rw/aufs-umount.sh | sh
815 rm -rf ${base}rw
816 umount ${base}root
817 rmdir $base*
819 # Install package if requested
820 if [ "$inst" ]; then
821 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
822 cd $PKGS && tazpkg install \
823 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
824 else
825 gettext -e "Unable to install package, build has failed.\n\n"
826 exit 1
827 fi
828 fi
830 # Skip install if target host doesn't match build system.
831 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
832 # Install package if part of the chroot to keep env up-to-date.
833 if [ -d "$INSTALLED/$pkg" ] && [ "$build" == "$ARCH" ]; then
834 . /etc/slitaz/cook.conf
835 . $WOK/$pkg/taz/$pkg-*/receipt
836 echo "Updating $ARCH chroot environment..."
837 echo "Updating chroot: $pkg (${VERSION}${EXTRAVERSION})" | log
838 cd $PKGS && tazpkg install \
839 $pkg-${VERSION}${EXTRAVERSION}.tazpkg --forced
840 fi
841 exit $status
842 }
844 # Create a XML feed for freshly built packages.
845 gen_rss() {
846 pubdate=$(date "+%a, %d %b %Y %X")
847 cat > $FEEDS/$pkg.xml << EOT
848 <item>
849 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
850 <link>${COOKER_URL}?pkg=$PACKAGE</link>
851 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
852 <pubDate>$pubdate</pubDate>
853 <description>$SHORT_DESC</description>
854 </item>
855 EOT
856 }
858 #
859 # Commands
860 #
862 case "$1" in
863 usage|help|-u|-h)
864 usage ;;
865 list-wok)
866 gettext -e "\nList of packages in:"; echo " $WOK"
867 separator
868 cd $WOK && ls -1
869 separator
870 echo -n "Packages: " && ls | wc -l
871 echo "" ;;
872 activity)
873 cat $activity ;;
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 "Checking for packages to install..."; echo
889 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
890 # ARCH-setup or 'cross check-env' should be used before: cook setup
891 case "$ARCH" in
892 arm|x86_64)
893 if [ ! -x "/usr/bin/cross" ]; then
894 gettext "ERROR: cross is not installed"; echo
895 exit 1
896 fi
897 gettext "Using config file: /etc/slitaz/cross.conf"; echo
898 . /etc/slitaz/cross.conf ;;
899 esac
900 for pkg in $SETUP_PKGS; do
901 if [ "$forced" ]; then
902 tazpkg -gi $pkg --forced
903 else
904 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
905 fi
906 done
908 # Handle --options
909 case "$2" in
910 --wok)
911 hg clone $WOK_URL wok || exit 1 ;;
912 --stable)
913 hg clone $WOK_URL-stable wok || exit 1 ;;
914 --undigest)
915 hg clone $WOK_URL-undigest wok || exit 1 ;;
916 --tiny)
917 hg clone $WOK_URL-tiny wok || exit 1 ;;
918 esac
920 # SliTaz group and permissions
921 if ! grep -q ^slitaz /etc/group; then
922 gettext -e "Adding group: slitaz\n"
923 addgroup slitaz
924 fi
925 gettext -e "Setting permissions for slitaz group...\n"
926 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
927 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
928 separator
929 gettext -e "All done, ready to cook packages :-)\n\n" ;;
930 *-setup)
931 # Setup for cross compiling.
932 arch=${1%-setup}
933 check_root
934 echo ""
935 boldify $(gettext "Setting up your cross environment")
936 separator
937 init_db_files
938 sed -i \
939 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
940 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
941 /etc/slitaz/cook.conf
942 case "$arch" in
943 arm)
944 sed -i \
945 -e s'/CFLAGS=.*/CFLAGS="-march=armv6"/' \
946 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux-gnueabi/' \
947 -e s'/xorg-dev/""/' \
948 /etc/slitaz/cook.conf ;;
949 x86_64)
950 sed -i \
951 -e s'/CFLAGS=.*/CFLAGS=""/' \
952 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux/' \
953 /etc/slitaz/cook.conf ;;
954 esac
955 . /etc/slitaz/cook.conf
956 echo "Target arch : $ARCH"
957 echo "Configure args : $CONFIGURE_ARGS"
958 if [ "$SYSROOT" ]; then
959 echo "Arch sysroot : $SYSROOT"
960 CC=/usr/bin/${HOST_SYSTEM}-gcc
961 else
962 echo "Additional path : /usr/cross/$ARCH/bin"
963 CC=/usr/cross/$ARCH/bin/${HOST_SYSTEM}-gcc
964 fi
965 if [ -x $CC ]; then
966 echo "Cross compiler : ${HOST_SYSTEM}-gcc"
967 else
968 colorize "C compiler is missing: ${HOST_SYSTEM}-gcc" 36
969 echo "Run 'cross compile' to cook a toolchain"
970 fi
971 separator && echo "" ;;
972 test)
973 # Test a cook environment.
974 echo "Cook test: testing the cook environment" | log
975 [ ! -d "$WOK" ] && exit 1
976 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
977 cook cooktest ;;
978 new)
979 # Create the package folder and an empty receipt.
980 pkg="$2"
981 [ "$pkg" ] || usage
982 echo ""
983 if [ -d "$WOK/$pkg" ]; then
984 echo -n "$pkg " && gettext "package already exists."
985 echo -e "\n" && exit 1
986 fi
987 gettext "Creating"; echo -n " $WOK/$pkg"
988 mkdir $WOK/$pkg && cd $WOK/$pkg && status
989 gettext "Preparing the package receipt..."
990 cp $DATA/receipt .
991 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
992 status && echo ""
994 # Interactive mode, asking and seding.
995 case "$3" in
996 --interactive|-x)
997 gettext -e "Entering interactive mode...\n"
998 separator
999 echo "Package : $pkg"
1000 # Version.
1001 echo -n "Version : " ; read anser
1002 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
1003 # Category.
1004 echo -n "Category : " ; read anser
1005 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
1006 # Short description.
1007 echo -n "Short desc : " ; read anser
1008 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
1009 # Maintainer.
1010 echo -n "Maintainer : " ; read anser
1011 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
1012 # Web site.
1013 echo -n "Web site : " ; read anser
1014 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
1015 echo ""
1016 # Wget URL.
1017 echo "Wget URL to download source tarball."
1018 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
1019 echo -n "Wget url : " ; read anser
1020 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
1021 # Ask for a stuff dir.
1022 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
1023 if [ "$anser" = "y" ]; then
1024 echo -n "Creating the stuff directory..."
1025 mkdir $WOK/$pkg/stuff && status
1026 fi
1027 # Ask for a description file.
1028 echo -n "Are you going to write a description ? (y/N) : " ; read anser
1029 if [ "$anser" = "y" ]; then
1030 echo -n "Creating the description.txt file..."
1031 echo "" > $WOK/$pkg/description.txt && status
1032 fi
1033 separator
1034 gettext -e "Receipt is ready to use.\n"
1035 echo "" ;;
1036 esac ;;
1037 list)
1038 # Cook a list of packages (better use the Cooker since it will order
1039 # packages before executing cook).
1040 check_root
1041 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
1042 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
1043 echo -e " $2\n" && exit 1
1044 echo "Cook list starting: $2" | log
1045 for pkg in $(cat $2)
1046 do
1047 cook $pkg || broken
1048 done ;;
1049 clean-wok)
1050 check_root
1051 gettext -e "\nCleaning all packages files..."
1052 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1053 status && echo "" ;;
1054 clean-src)
1055 check_root
1056 gettext -e "\nCleaning all packages sources..."
1057 rm -rf $WOK/*/source
1058 status && echo "" ;;
1059 pkgdb)
1060 # Create suitable packages list for TazPKG and only for built packages
1061 # as well as flavors files for TazLiTo. We dont need logs since we do it
1062 # manually to ensure everything is fine before syncing the mirror.
1063 case "$2" in
1064 --flavors)
1065 continue ;;
1066 *)
1067 [ "$2" ] && PKGS="$2"
1068 [ ! -d "$PKGS" ] && \
1069 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1 ;;
1070 esac
1071 time=$(date +%s)
1072 flavors=$SLITAZ/flavors
1073 live=$SLITAZ/live
1074 echo "cook:pkgdb" > $command
1075 echo "Cook pkgdb: Creating all packages lists" | log
1076 echo ""
1077 gettext "Creating lists for: "; echo "$PKGS"
1078 separator
1079 gettext "Cook pkgdb started: "; date "+%Y-%m-%d %H:%M"
1080 cd $PKGS
1081 rm -f packages.*
1082 gettext -e "Creating: packages.list\n"
1083 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1084 gettext -e "Creating: packages.md5\n"
1085 md5sum *.tazpkg > $PKGS/packages.md5
1086 md5sum packages.md5 | cut -f1 -d' ' > ID
1087 gettext -e "Creating lists from: "; echo "$WOK"
1088 cd $WOK
1089 for pkg in *
1090 do
1091 unset_receipt
1092 . $pkg/receipt
1093 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1094 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1095 if [ -s $pkg/taz/*/receipt ]; then
1096 . $pkg/taz/*/receipt
1097 fi
1098 # packages.desc lets us search easily in DB
1099 cat >> $PKGS/packages.desc << EOT
1100 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1101 EOT
1102 # packages.txt used by tazpkg and tazpkg-web also to provide
1103 # a human readable package list with version and description.
1104 cat >> $PKGS/packages.txt << EOT
1105 $PACKAGE
1106 ${VERSION}$EXTRAVERSION
1107 $SHORT_DESC
1108 $PACKED_SIZE ($UNPACKED_SIZE installed)
1110 EOT
1111 # packages.equiv is used by tazpkg install to check depends.
1112 for i in $PROVIDE; do
1113 DEST=""
1114 echo $i | fgrep -q : && DEST="${i#*:}:"
1115 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1116 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1117 $PKGS/packages.equiv
1118 else
1119 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1120 fi
1121 done
1122 # files.list provides a list of all packages files.
1123 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1124 $PKGS/files.list
1125 fi
1126 done
1128 # Display list size.
1129 gettext -e "Done: packages.desc\n"
1130 gettext -e "Done: packages.txt\n"
1131 gettext -e "Done: packages.equiv\n"
1133 # files.list.lzma
1134 gettext -e "Creating: files.list.lzma\n"
1135 cd $PKGS && lzma e files.list files.list.lzma
1136 rm -f files.list
1138 # Display some info.
1139 separator
1140 nb=$(ls $PKGS/*.tazpkg | wc -l)
1141 time=$(($(date +%s) - $time))
1142 echo -e "Packages: $nb - Time: ${time}s\n"
1144 # Create all flavors files at once. Do we really need code to monitor
1145 # flavors changes ? Lets just build them with packages lists before
1146 # syncing the mirror.
1147 [ "$2" == "--flavors" ] || exit 1
1148 [ ! -d "$flavors" ] && echo -e "Missing flavors: $flavors\n" && exit 1
1149 [ -d "$live" ] || mkdir -p $live
1150 gettext "Creating flavors files in:"; echo " $live"
1151 echo "Cook pkgdb: Creating all flavors" | log
1152 separator
1153 gettext -e "Recharging lists to use latest packages...\n"
1154 tazpkg recharge >/dev/null 2>/dev/null
1156 # We need a custom tazlito config to set working dir to /home/slitaz.
1157 if [ ! -f "$live/tazlito.conf" ]; then
1158 echo "Creating configuration file: tazlito.conf"
1159 cp /etc/tazlito/tazlito.conf $live
1160 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1161 $live/tazlito.conf
1162 fi
1164 # Update Hg flavors repo and pack.
1165 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
1167 cd $live
1168 echo "Starting to generate flavors..."
1169 rm -f flavors.list *.flavor
1170 for i in $flavors/*
1171 do
1172 fl=$(basename $i)
1173 echo "Packing flavor: $(basename $i)"
1174 tazlito pack-flavor $fl >/dev/null || exit 1
1175 tazlito show-flavor $fl --brief --noheader 2> \
1176 /dev/null >> flavors.list
1177 done
1178 cp -f $live/*.flavor $live/flavors.list $PKGS
1179 separator && gettext "Flavors size: "; du -sh $live | awk '{print $1}'
1180 echo "" && rm -f $command ;;
1181 *)
1182 # Just cook and generate a package.
1183 check_root
1184 time=$(date +%s)
1185 pkg="$1"
1186 [ -z "$pkg" ] && usage
1187 receipt="$WOK/$pkg/receipt"
1188 check_pkg_in_wok && echo ""
1190 unset inst
1191 unset_receipt
1192 . $receipt
1194 # Handle cross compilation.
1196 # CROSS_NOTE: Actually we are running an ARM cooker but running
1197 # the cooker and build each commit in wok is not possible since
1198 # we dont cook the full wok for this arch. For ARM we need a set
1199 # of packages to handle a touch screen desktop, servers but not
1200 # erland.
1202 # The temporary solution is to build only reviewed and tested
1203 # packages with HOST_ARCH set in receipt.
1204 case "$ARCH" in
1205 arm)
1206 if [ ! "$HOST_ARCH" ]; then
1207 echo "cook: HOST_ARCH is not set in $pkg receipt"
1208 echo "cook: This package is not included in: $ARCH"
1209 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1210 echo "Cook skip: $pkg is not included in: $ARCH" | log
1211 echo "" && exit 1
1212 fi ;;
1213 esac
1215 # Some packages are not included in some arch or fail to cross compile.
1216 : ${HOST_ARCH=i486}
1217 if ! $(echo "$HOST_ARCH" | fgrep -q $ARCH); then
1218 echo "cook: HOST_ARCH=$HOST_ARCH"
1219 echo "cook: $pkg doesn't cook or is not included in: $ARCH"
1220 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1221 echo "Cook skip: $pkg doesn't cook or is not included in: $ARCH" | log
1222 echo "" && exit 1
1223 fi
1225 # Skip blocked, 3 lines also for the Cooker.
1226 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1227 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
1228 fi
1230 try_aufs_chroot "$@"
1232 # Log and source receipt.
1233 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1234 echo "cook:$pkg" > $command
1236 # Display and log info if cook process stopped.
1237 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
1238 tee -a $LOGS/$pkg.log' INT
1240 # Handle --options
1241 case "$2" in
1242 --clean|-c)
1243 gettext -e "Cleaning:"; echo -n " $pkg"
1244 cd $WOK/$pkg && rm -rf install taz source
1245 status && echo "" && exit 0 ;;
1246 --install|-i)
1247 inst='yes' ;;
1248 --getsrc|-gs)
1249 gettext "Getting source for:"; echo " $pkg"
1250 separator && get_source
1251 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
1252 --block|-b)
1253 gettext "Blocking:"; echo -n " $pkg"
1254 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1255 status && echo "" && exit 0 ;;
1256 --unblock|-ub)
1257 gettext "Unblocking:"; echo -n " $pkg"
1258 sed -i "/^${pkg}$/"d $blocked
1259 status && echo "" && exit 0 ;;
1261 esac
1263 # Check if wanted is built now so we have separate log files.
1264 for wanted in $WANTED ; do
1265 if grep -q "^$wanted$" $blocked; then
1266 echo "WANTED package is blocked: $wanted" | tee $LOGS/$pkg.log
1267 echo "" && rm -f $command && exit 1
1268 fi
1269 if grep -q "^$wanted$" $broken; then
1270 echo "WANTED package is broken: $wanted" | tee $LOGS/$pkg.log
1271 echo "" && rm -f $command && exit 1
1272 fi
1273 if [ ! -d "$WOK/$wanted/install" ]; then
1274 cook "$wanted" || exit 1
1275 fi
1276 done
1278 # Cook and pack or exit on error and log everything.
1279 cookit $@ 2>&1 | tee $LOGS/$pkg.log
1280 remove_deps | tee -a $LOGS/$pkg.log
1281 cookit_quality
1282 packit 2>&1 | tee -a $LOGS/$pkg.log
1283 clean_log
1285 # Exit if any error in packing.
1286 if grep -q ^ERROR $LOGS/$pkg.log; then
1287 debug_info | tee -a $LOGS/$pkg.log
1288 rm -f $command && exit 1
1289 fi
1291 # Create an XML feed
1292 gen_rss
1294 # Time and summary
1295 time=$(($(date +%s) - $time))
1296 summary | tee -a $LOGS/$pkg.log
1297 echo ""
1299 # Install package if requested
1300 if [ "$inst" ]; then
1301 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1302 cd $PKGS && tazpkg install \
1303 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1304 else
1305 gettext -e "Unable to install package, build has failed.\n\n"
1306 exit 1
1307 fi
1308 fi
1310 # Skip install if target host dont match build system.
1311 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
1312 # Install package if part of the chroot to keep env up-to-date.
1313 if [ -d "$INSTALLED/$PACKAGE" ] && [ -z "$AUFS_MOUNTS" ] && \
1314 [ "$build" == "$ARCH" ]; then
1315 echo "Updating chroot environment..."
1316 echo "Updating chroot: $PACKAGE (${VERSION}${EXTRAVERSION})" | log
1317 cd $PKGS && tazpkg install \
1318 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1319 fi
1321 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1322 # You want automation: use the Cooker Build Bot.
1323 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
1324 rm -f $command ;;
1325 esac
1327 exit 0