cookutils view cook @ rev 593

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