cookutils view cook @ rev 439

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