cookutils view cook @ rev 594

cook: add AUFS_NOT_RAMFS
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Mar 14 10:09:03 2013 +0100 (2013-03-14)
parents f4e45b94f0d8
children 8fbd30a8686a
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 grep -q ^AUFS_NOT_RAMFS $receipt && base=/mnt/aufsmnt$$
862 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
863 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
864 mkdir ${base}root ${base}rw || return
866 echo "Setup aufs chroot..."
868 # Sanity check
869 for i in / /proc /sys /dev/shm /home ; do
870 case " $AUFS_MOUNTS " in
871 *\ $i\ *) ;;
872 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
873 esac
874 done
875 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
876 mount --bind $mnt ${base}root$mnt
877 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
878 echo "Aufs mountage failure"
879 umount ${base}root
880 rmdir ${base}*
881 return
882 fi
883 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
884 done
886 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
887 status=$?
889 echo "Leaving aufs chroot..."
890 tac ${base}rw/aufs-umount.sh | sh
891 rm -rf ${base}rw
892 umount ${base}root
893 rmdir $base*
894 # Dont install pkg twice... it's done after
895 #install_package
896 exit $status
897 }
899 # Create a XML feed for freshly built packages.
900 gen_rss() {
901 pubdate=$(date "+%a, %d %b %Y %X")
902 cat > $FEEDS/$pkg.xml << EOT
903 <item>
904 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
905 <link>${COOKER_URL}?pkg=$PACKAGE</link>
906 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
907 <pubDate>$pubdate</pubDate>
908 <description>$SHORT_DESC</description>
909 </item>
910 EOT
911 }
913 # Truncate stdout log file to $1 Mb.
914 loglimit()
915 {
916 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
917 tee /dev/stderr | dd bs=1k count=$((1024*${1:-$DEFAULT_LOG_LIMIT})) conv=noerror 2> /dev/null
918 else
919 tee /dev/stderr
920 fi
921 }
923 #
924 # Commands
925 #
927 case "$1" in
928 usage|help|-u|-h)
929 usage ;;
930 list-wok)
931 gettext -e "\nList of packages in:"; echo " $WOK"
932 separator
933 cd $WOK && ls -1
934 separator
935 echo -n "Packages: " && ls | wc -l
936 newline ;;
937 activity)
938 cat $activity ;;
939 search)
940 # Just a simple search function, we dont need more actually.
941 query="$2"
942 newline
943 gettext "Search results for:"; echo " $query"
944 separator
945 cd $WOK && ls -1 | grep "$query"
946 separator && newline ;;
947 setup)
948 # Setup a build environment
949 check_root
950 echo "Cook: setup environment" | log
951 newline
952 gettext "Setting up your environment"; newline
953 separator && cd $SLITAZ
954 init_db_files
955 gettext "Checking for packages to install..."; echo
956 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
957 # ARCH-setup or 'cross check-env' should be used before: cook setup
958 case "$ARCH" in
959 arm|x86_64)
960 if [ ! -x "/usr/bin/cross" ]; then
961 gettext "ERROR: cross is not installed"; echo
962 exit 1
963 fi
964 gettext "Using config file: /etc/slitaz/cross.conf"; echo
965 . /etc/slitaz/cross.conf ;;
966 esac
967 for pkg in $SETUP_PKGS; do
968 if [ "$forced" ]; then
969 tazpkg -gi $pkg --forced
970 else
971 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
972 fi
973 done
975 # Handle --options
976 case "$2" in
977 --wok)
978 hg clone $WOK_URL wok || exit 1 ;;
979 --stable)
980 hg clone $WOK_URL-stable wok || exit 1 ;;
981 --undigest)
982 hg clone $WOK_URL-undigest wok || exit 1 ;;
983 --tiny)
984 hg clone $WOK_URL-tiny wok || exit 1 ;;
985 esac
987 # SliTaz group and permissions
988 if ! grep -q ^slitaz /etc/group; then
989 gettext -e "Adding group: slitaz\n"
990 addgroup slitaz
991 fi
992 gettext -e "Setting permissions for slitaz group...\n"
993 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
994 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
995 separator
996 gettext -e "All done, ready to cook packages :-)\n\n" ;;
997 *-setup)
998 # Setup for cross compiling.
999 arch=${1%-setup}
1000 check_root
1001 echo "Cook: setup $arch cross environment" | log
1002 newline
1003 boldify $(gettext "Setting up your $arch cross environment")
1004 separator
1005 init_db_files
1006 sed -i \
1007 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1008 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1009 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1010 /etc/slitaz/cook.conf
1011 case "$arch" in
1012 arm)
1013 sed -i \
1014 -e s'/CFLAGS=.*/CFLAGS="-march=armv6 -O2"/' \
1015 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux-gnueabi/' \
1016 -e s'/xorg-dev/""/' \
1017 /etc/slitaz/cook.conf ;;
1018 x86_64)
1019 sed -i \
1020 -e s'/CFLAGS=.*/CFLAGS=""/' \
1021 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux/' \
1022 /etc/slitaz/cook.conf ;;
1023 esac
1024 . /etc/slitaz/cook.conf
1025 sysroot=$CROSS_TREE/sysroot
1026 tools=/cross/$arch/tools
1027 root=$sysroot
1028 CC=$tools/bin/${HOST_SYSTEM}-gcc
1029 echo "Target arch : $ARCH"
1030 echo "Configure args : $CONFIGURE_ARGS"
1031 echo "Arch sysroot : $sysroot"
1032 echo "Tools prefix : $tools/bin"
1033 # Tell the packages manager where to find packages.
1034 echo "Packages DB : ${root}$DB"
1035 mkdir -p ${root}$INSTALLED
1036 cd ${root}$DB && rm -f *.bak
1037 for list in packages.list packages.desc packages.equiv packages.md5
1038 do
1039 rm -f $list && ln -s $SLITAZ/packages/$list $list
1040 done
1041 # We must have the cross compiled glibc-base installed or default
1042 # i486 package will be used as dep by tazpkg and then break the
1043 # cross environment
1044 if [ ! -f "${root}$INSTALLED/glibc-base/receipt" ]; then
1045 colorize 36 "WARNING: (e)glibc-base is not installed in sysroot"
1046 fi
1047 # Show GCC version or warn if not yet compiled.
1048 if [ -x $CC ]; then
1049 echo "Cross compiler : ${HOST_SYSTEM}-gcc"
1050 else
1051 colorize 36 "C compiler is missing: ${HOST_SYSTEM}-gcc"
1052 echo "Run 'cross compile' to cook a toolchain"
1053 fi
1054 separator && newline ;;
1055 test)
1056 # Test a cook environment.
1057 echo "Cook test: testing the cook environment" | log
1058 [ ! -d "$WOK" ] && exit 1
1059 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1060 cook cooktest ;;
1061 new)
1062 # Create the package folder and an empty receipt.
1063 pkg="$2"
1064 [ "$pkg" ] || usage
1065 newline
1066 if [ -d "$WOK/$pkg" ]; then
1067 echo -n "$pkg " && gettext "package already exists."
1068 echo -e "\n" && exit 1
1069 fi
1070 gettext "Creating"; echo -n " $WOK/$pkg"
1071 mkdir $WOK/$pkg && cd $WOK/$pkg && status
1072 gettext "Preparing the package receipt..."
1073 cp $DATA/receipt .
1074 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1075 status && newline
1077 # Interactive mode, asking and seding.
1078 case "$3" in
1079 --interactive|-x)
1080 gettext -e "Entering interactive mode...\n"
1081 separator
1082 echo "Package : $pkg"
1083 # Version.
1084 echo -n "Version : " ; read anser
1085 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
1086 # Category.
1087 echo -n "Category : " ; read anser
1088 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
1089 # Short description.
1090 echo -n "Short desc : " ; read anser
1091 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
1092 # Maintainer.
1093 echo -n "Maintainer : " ; read anser
1094 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
1095 # License.
1096 echo -n "License : " ; read anser
1097 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$anser\""/ receipt
1098 # Web site.
1099 echo -n "Web site : " ; read anser
1100 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
1101 newline
1102 # Wget URL.
1103 echo "Wget URL to download source tarball."
1104 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
1105 echo -n "Wget url : " ; read anser
1106 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
1107 # Ask for a stuff dir.
1108 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
1109 if [ "$anser" = "y" ]; then
1110 echo -n "Creating the stuff directory..."
1111 mkdir $WOK/$pkg/stuff && status
1112 fi
1113 # Ask for a description file.
1114 echo -n "Are you going to write a description ? (y/N) : " ; read anser
1115 if [ "$anser" = "y" ]; then
1116 echo -n "Creating the description.txt file..."
1117 newline > $WOK/$pkg/description.txt && status
1118 fi
1119 separator
1120 gettext -e "Receipt is ready to use.\n"
1121 newline ;;
1122 esac ;;
1123 list)
1124 # Cook a list of packages (better use the Cooker since it will order
1125 # packages before executing cook).
1126 check_root
1127 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
1128 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
1129 echo -e " $2\n" && exit 1
1130 echo "Cook list starting: $2" | log
1131 for pkg in $(cat $2)
1132 do
1133 cook $pkg || broken
1134 done ;;
1135 clean-wok)
1136 check_root
1137 gettext -e "\nCleaning all packages files..."
1138 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1139 status && newline ;;
1140 clean-src)
1141 check_root
1142 gettext -e "\nCleaning all packages sources..."
1143 rm -rf $WOK/*/source
1144 status && newline ;;
1145 pkgdb)
1146 # Create suitable packages list for TazPKG and only for built packages
1147 # as well as flavors files for TazLiTo. We dont need logs since we do it
1148 # manually to ensure everything is fine before syncing the mirror.
1149 case "$2" in
1150 --flavors)
1151 continue ;;
1152 *)
1153 [ "$2" ] && PKGS="$2"
1154 [ ! -d "$PKGS" ] && \
1155 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1 ;;
1156 esac
1157 time=$(date +%s)
1158 flavors=$SLITAZ/flavors
1159 live=$SLITAZ/live
1160 echo "cook:pkgdb" > $command
1161 echo "Cook pkgdb: Creating all packages lists" | log
1162 newline
1163 gettext "Creating lists for: "; echo "$PKGS"
1164 separator
1165 gettext "Cook pkgdb started: "; date "+%Y-%m-%d %H:%M"
1166 cd $PKGS
1167 rm -f packages.*
1168 gettext -e "Creating: packages.list\n"
1169 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1170 gettext -e "Creating: packages.md5\n"
1171 md5sum *.tazpkg > $PKGS/packages.md5
1172 md5sum packages.md5 | cut -f1 -d' ' > ID
1173 gettext -e "Creating lists from: "; echo "$WOK"
1174 cd $WOK
1175 for pkg in *
1176 do
1177 unset_receipt
1178 . $pkg/receipt
1179 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1180 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1181 if [ -s $pkg/taz/*/receipt ]; then
1182 . $pkg/taz/*/receipt
1183 fi
1184 # packages.desc lets us search easily in DB
1185 cat >> $PKGS/packages.desc << EOT
1186 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1187 EOT
1188 # packages.txt used by tazpkg and tazpkg-web also to provide
1189 # a human readable package list with version and description.
1190 cat >> $PKGS/packages.txt << EOT
1191 $PACKAGE
1192 ${VERSION}$EXTRAVERSION
1193 $SHORT_DESC
1194 $PACKED_SIZE ($UNPACKED_SIZE installed)
1196 EOT
1197 # packages.equiv is used by tazpkg install to check depends.
1198 for i in $PROVIDE; do
1199 DEST=""
1200 echo $i | fgrep -q : && DEST="${i#*:}:"
1201 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1202 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1203 $PKGS/packages.equiv
1204 else
1205 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1206 fi
1207 done
1208 # files.list provides a list of all packages files.
1209 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1210 $PKGS/files.list
1211 fi
1212 done
1214 # Display list size.
1215 gettext -e "Done: packages.desc\n"
1216 gettext -e "Done: packages.txt\n"
1217 gettext -e "Done: packages.equiv\n"
1219 # files.list.lzma
1220 gettext -e "Creating: files.list.lzma\n"
1221 cd $PKGS && lzma e files.list files.list.lzma
1222 rm -f files.list
1224 # Display some info.
1225 separator
1226 nb=$(ls $PKGS/*.tazpkg | wc -l)
1227 time=$(($(date +%s) - $time))
1228 echo -e "Packages: $nb - Time: ${time}s\n"
1230 # Create all flavors files at once. Do we really need code to monitor
1231 # flavors changes ? Lets just build them with packages lists before
1232 # syncing the mirror.
1233 [ "$2" == "--flavors" ] || exit 1
1234 [ ! -d "$flavors" ] && echo -e "Missing flavors: $flavors\n" && exit 1
1235 [ -d "$live" ] || mkdir -p $live
1236 gettext "Creating flavors files in:"; echo " $live"
1237 echo "Cook pkgdb: Creating all flavors" | log
1238 separator
1239 gettext -e "Recharging lists to use latest packages...\n"
1240 tazpkg recharge >/dev/null 2>/dev/null
1242 # We need a custom tazlito config to set working dir to /home/slitaz.
1243 if [ ! -f "$live/tazlito.conf" ]; then
1244 echo "Creating configuration file: tazlito.conf"
1245 cp /etc/tazlito/tazlito.conf $live
1246 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1247 $live/tazlito.conf
1248 fi
1250 # Update Hg flavors repo and pack.
1251 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
1253 cd $live
1254 echo "Starting to generate flavors..."
1255 rm -f flavors.list *.flavor
1256 for i in $flavors/*
1257 do
1258 fl=$(basename $i)
1259 echo "Packing flavor: $(basename $i)"
1260 tazlito pack-flavor $fl >/dev/null || exit 1
1261 tazlito show-flavor $fl --brief --noheader 2> \
1262 /dev/null >> flavors.list
1263 done
1264 cp -f $live/*.flavor $live/flavors.list $PKGS
1265 separator && gettext "Flavors size: "; du -sh $live | awk '{print $1}'
1266 newline && rm -f $command
1267 separator && gettext "Cook pkgdb end: "; date "+%Y-%m-%d %H:%M";;
1268 *)
1269 # Just cook and generate a package.
1270 check_root
1271 time=$(date +%s)
1272 pkg="$1"
1273 [ -z "$pkg" ] && usage
1274 receipt="$WOK/$pkg/receipt"
1275 check_pkg_in_wok && newline
1277 unset inst
1278 unset_receipt
1279 . $receipt
1281 # Handle cross compilation.
1283 # CROSS_NOTE: Actually we are running an ARM cooker but running
1284 # the cooker and build each commit in wok is not possible since
1285 # we dont cook the full wok for this arch. For ARM we need a set
1286 # of packages to handle a touch screen desktop, servers but not
1287 # erland.
1289 # The temporary solution is to build only reviewed and tested
1290 # packages with HOST_ARCH set in receipt.
1291 case "$ARCH" in
1292 arm)
1293 if [ ! "$HOST_ARCH" ]; then
1294 echo "cook: HOST_ARCH is not set in $pkg receipt"
1295 echo "cook: This package is not included in: $ARCH"
1296 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1297 echo "Cook skip: $pkg is not included in: $ARCH" | log
1298 newline && exit 1
1299 fi ;;
1300 esac
1302 # Some packages are not included in some arch or fail to cross compile.
1303 : ${HOST_ARCH=i486}
1304 if ! $(echo "$HOST_ARCH" | fgrep -q $ARCH); then
1305 echo "cook: HOST_ARCH=$HOST_ARCH"
1306 echo "cook: $pkg doesn't cook or is not included in: $ARCH"
1307 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1308 echo "Cook skip: $pkg doesn't cook or is not included in: $ARCH" | log
1309 newline && exit 1
1310 fi
1312 # Skip blocked, 3 lines also for the Cooker.
1313 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1314 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
1315 fi
1317 try_aufs_chroot "$@"
1319 # Log and source receipt.
1320 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1321 echo "cook:$pkg" > $command
1323 # Display and log info if cook process stopped.
1324 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
1325 tee -a $LOGS/$pkg.log' INT
1327 # Handle --options
1328 case "$2" in
1329 --clean|-c)
1330 gettext -e "Cleaning:"; echo -n " $pkg"
1331 cd $WOK/$pkg && rm -rf install taz source
1332 status && newline && exit 0 ;;
1333 --install|-i)
1334 inst='yes' ;;
1335 --getsrc|-gs)
1336 gettext "Getting source for:"; echo " $pkg"
1337 separator && get_source
1338 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
1339 --block|-b)
1340 gettext "Blocking:"; echo -n " $pkg"
1341 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1342 status && newline && exit 0 ;;
1343 --unblock|-ub)
1344 gettext "Unblocking:"; echo -n " $pkg"
1345 sed -i "/^${pkg}$/"d $blocked
1346 status && newline && exit 0 ;;
1347 --pack)
1348 if [ -d $WOK/$pkg/taz ]; then
1349 rm -rf $WOK/$pkg/taz
1350 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1351 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1352 clean_log
1353 else
1354 gettext "Need to build $pkg." && exit 0
1355 fi
1356 exit 0 ;;
1357 esac
1359 # Check if wanted is built now so we have separate log files.
1360 for wanted in $WANTED ; do
1361 if grep -q "^$wanted$" $blocked; then
1362 echo "WANTED package is blocked: $wanted" | tee $LOGS/$pkg.log
1363 newline && rm -f $command && exit 1
1364 fi
1365 if grep -q "^$wanted$" $broken; then
1366 echo "WANTED package is broken: $wanted" | tee $LOGS/$pkg.log
1367 newline && rm -f $command && exit 1
1368 fi
1369 if [ ! -d "$WOK/$wanted/install" ]; then
1370 cook "$wanted" || exit 1
1371 fi
1372 done
1374 # Cook and pack or exit on error and log everything.
1375 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1376 remove_deps | tee -a $LOGS/$pkg.log
1377 cookit_quality
1378 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1379 clean_log
1381 # Exit if any error in packing.
1382 if grep -Eq '(^ERROR|No such file or directory)' $LOGS/$pkg.log; then
1383 debug_info | tee -a $LOGS/$pkg.log
1384 rm -f $command && exit 1
1385 fi
1387 # Create an XML feed
1388 gen_rss
1390 # Time and summary
1391 time=$(($(date +%s) - $time))
1392 summary | tee -a $LOGS/$pkg.log
1393 newline
1395 # We may want to install/update.
1396 install_package
1398 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1399 # You want automation: use the Cooker Build Bot.
1400 rm -f $command ;;
1401 esac
1403 exit 0