cookutils view cook @ rev 429

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