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