cookutils view cook @ rev 475

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