cookutils view cook @ rev 580

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