cookutils view cook @ rev 571

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