cookutils view cook @ rev 443

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