cookutils view cook @ rev 577

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