cookutils view cook @ rev 586

cook: Add loglimit function.
author Christopher Rogers <slaxemulator@gmail.com>
date Fri Feb 08 03:25:37 2013 +0000 (2013-02-08)
parents 0cd1e2c82dc7
children 156eb61b493b
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
10 . /usr/lib/slitaz/libcookorder.sh
11 . /usr/lib/slitaz/libcookiso.sh
13 COMMAND="$1"
15 #
16 # Functions
17 #
19 usage() {
20 cat << EOT
22 $(echo -e "\033[1m$(gettext "Usage:")\033[0m") cook [package|command] [list|--option]
24 $(echo -e "\033[1m$(gettext "Commands:")\033[0m")
25 usage|help $(gettext "Display this short usage.")
26 setup $(gettext "Setup your build environment.")
27 *-setup $(gettext "Setup a cross environment.")
28 test $(gettext "Test environment and cook a package.")
29 list-wok $(gettext "List packages in the wok.")
30 search $(gettext "Simple packages search function.")
31 new $(gettext "Create a new package with a receipt".)
32 list $(gettext "Cook a list of packages.")
33 clean-wok $(gettext "Clean-up all packages files.")
34 clean-src $(gettext "Clean-up all packages sources.")
35 upwok $(gettext "Update wok.")
36 gen-wok-db $(gettext "Build cook order files.")
37 gen-src $(gettext "Build source list.")
38 check-incoming $(gettext "Move incoming packages to packages folder.")
39 gen-cooklist $(gettext "Make cook order list.")
40 check-src $(gettext "Check upstream tarball for package in the wok.")
41 maintainers $(gettext "List all maintainers in the wok.")
42 maintained-by $(gettext "List packages maintained by a contributor.")
43 tags $(gettext "List all tags used in wok receipts.")
44 pkgdb $(gettext "Create packages DB lists and flavors.")
45 unbuild $(gettext "List all unbuild packages.")
47 $(echo -e "\033[1m$(gettext "Options:")\033[0m")
48 --clean|-c Cook : $(gettext "clean the package in the wok.")
49 --install|-i Cook : $(gettext "cook and install the package.")
50 --getsrc|-gs Cook : $(gettext "get the package source tarball.")
51 --block|-b Cook : $(gettext "Block a package so cook will skip it.")
52 --unblock|-ub Cook : $(gettext "Unblock a blocked package.")
53 --interactive|-x New : $(gettext "create a receipt interactively.")
54 --local Upwok : $(gettext "update wok local changes in wok-hg.")
55 --wok|-w Setup : $(gettext "clone the cooking wok from Hg repo.")
56 --stable Setup : $(gettext "clone the stable wok from Hg repo.")
57 --undigest Setup : $(gettext "clone the undigest wok from Hg repo.")
58 --tiny Setup: $(gettext "clone the tiny SliTaz wok from Hg repo.")
59 --forced Setup: $(gettext "force reinstall of chroot packages.")
60 --flavors Pkgdb : $(gettext "create up-to-date flavors files.")
61 --full Unbuild : $(gettext "create a full unbuild list.")
62 --list Unbuild : $(gettext "Copy unbuild list into your cooklist.")
64 EOT
65 exit 0
66 }
68 # We don't want these escapes in web interface.
69 clean_log() {
70 sed -i -e s'|\[70G\[ \[1;32m| |' \
71 -e s'|\[0;39m \]||' $LOGS/$pkg.log
72 }
74 # check if $value is empty
75 if_empty_value() {
76 if [ -z "$value" ]; then
77 gettext "QA: empty variable:"; echo -e " ${var}=\"\"\n"
78 exit 1
79 fi
80 }
82 # QA: check a receipt consistency before building.
83 receipt_quality() {
84 gettext -e "QA: checking package receipt...\n"
85 unset online
86 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
87 online="online"
88 fi
89 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
90 do
91 unset value
92 value="$(. $receipt ; eval echo \$$var)"
93 case "$var" in
94 PACKAGE|VERSION|SHORT_DESC)
95 if_empty_value ;;
96 CATEGORY)
97 [ -z "$value" ] && value="empty"
98 valid="$PKGS_CATEGORIES"
99 if ! echo "$valid" | grep -q -w "$value"; then
100 gettext "QA: unknown category:"; echo -e " $value\n"
101 exit 1
102 fi ;;
103 WEB_SITE)
104 # We don't check WGET_URL since if dl is needed it will fail.
105 # Break also if we're not online. Here error is not fatal.
106 if_empty_value
107 [ -z "$online" ] || break
108 case $value in
109 https://*)
110 if ! wget -T $TIMEOUT --spider --no-check-certificate $value 2>/dev/null; then
111 gettext "QA: Unable to reach:"; echo -e " $value"
112 fi ;;
113 http://*|ftp://*)
114 if ! busybox wget -T $TIMEOUT -s $value 2>/dev/null; then
115 gettext "QA: Unable to reach:"; echo -e " $value"
116 fi ;;
117 esac
118 esac
119 done
120 }
122 # Paths used in receipt and by cook itself.
123 set_paths() {
124 pkgdir=$WOK/$PACKAGE
125 basesrc=$pkgdir/source
126 tmpsrc=$basesrc/tmp
127 src=$basesrc/$PACKAGE-$VERSION
128 taz=$pkgdir/taz
129 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
130 fs=$pack/fs
131 stuff=$pkgdir/stuff
132 install=$pkgdir/install
133 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
134 lzma_tarball="$pkgsrc.tar.lzma"
135 orig_tarball="$TARBALL"
136 if [ "$PATCH" ]; then
137 [ "${PTARBALL}" ] || PTARBALL="$(basename $PATCH)"
138 fi
139 if [ "$WANTED" ]; then
140 basesrc=$WOK/$WANTED/source
141 src=$basesrc/$WANTED-$VERSION
142 install=$WOK/$WANTED/install
143 wanted_stuff=$WOK/$WANTED/stuff
144 fi
145 if [ "$SOURCE" ]; then
146 source_stuff=$WOK/$SOURCE/stuff
147 fi
148 # Kernel version is set from linux
149 if [ -f "$WOK/linux/receipt" ]; then
150 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d '"' -f 2)
151 kbasevers=${kvers:0:3}
152 fi
153 # Python version
154 if [ -f "$WOK/python/receipt" ]; then
155 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d '"' -f 2)
156 fi
157 # perl version for some packages needed it
158 if [ -f "$WOK/perl/receipt" ]; then
159 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d '"' -f 2)
160 fi
161 # Old way compatibility.
162 _pkg=$install
163 }
165 # Create source tarball when URL is a SCM.
166 create_tarball() {
167 local tarball
168 tarball=$pkgsrc.tar.bz2
169 [ "$LZMA_SRC" ] && tarball=$lzma_tarball
170 gettext "Creating tarball: "; echo "$tarball"
171 if [ "$LZMA_SRC" ]; then
172 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
173 LZMA_SRC=""
174 else
175 tar cjf $tarball $pkgsrc || exit 1
176 mv $tarball $SRC && rm -rf $pkgsrc
177 fi
178 TARBALL=$tarball
179 }
181 # Get package source. For SCM we are in cache so clone here and create a
182 # tarball here.
183 get_source() {
184 pwd=$(pwd)
185 for file in $@; do
186 gettext "Getting source from url:"; echo " ${file#*|}"
187 if [ "$file" = "$PATCH" -o "$file" = "$orig_url_patch" ]; then
188 SAVE_FILE="$SRC/$PTARBALL"
189 else
190 SAVE_FILE="$SRC/$TARBALL"
191 fi
192 case "$file" in
193 http://*|ftp://*)
194 # Busybox Wget is better!
195 busybox wget $WGET_OPTIONS -T $TIMEOUT -c -O $SAVE_FILE $file || \
196 (echo -e "ERROR: wget $file" && exit 1) ;;
197 https://*)
198 wget $WGET_OPTIONS -T $TIMEOUT -c --no-check-certificate -O $SAVE_FILE $file || \
199 (echo -e "ERROR: wget $file" && exit 1) ;;
200 hg*|mercurial*)
201 if $(echo "$file" | fgrep -q "hg|"); then
202 url=${file#hg|}
203 else
204 url=${file#mercurial|}
205 fi
206 gettext -e "Getting source from Hg...\n"
207 echo "URL: $url"
208 gettext "Cloning to: "; echo "$pwd/$pkgsrc"
209 if [ "$BRANCH" ]; then
210 echo "Hg branch: $BRANCH"
211 hg clone $url --rev $BRANCH $pkgsrc || \
212 (echo "ERROR: hg clone $url --rev $BRANCH" && exit 1)
213 else
214 hg clone $url $pkgsrc || (echo "ERROR: hg clone $url" && exit 1)
215 fi
216 create_tarball ;;
217 git*)
218 [ -f $INSTALLED/git/receipt ] || tazpkg get-install git
219 url=${file#git|}
220 gettext -e "Getting source from Git...\n"
221 echo "URL: $url"
222 git clone $url $pkgsrc || (echo "ERROR: git clone $url" && exit 1)
223 if [ "$BRANCH" ]; then
224 echo "Git branch: $BRANCH"
225 cd $pkgsrc && git checkout $BRANCH && cd ..
226 fi
227 create_tarball ;;
228 bzr*|bazaar*)
229 [ -f $INSTALLED/bazaar/receipt ] || tazpkg get-install bazaar
230 if $(echo "$file" | fgrep -q "bzr|"); then
231 url=${file#bzr|}
232 else
233 url=${file#bazaar|}
234 fi
235 gettext -e "Getting source from BZR...\n"
236 echo "URL: $url"
237 bzr branch $url $pkgsrc
238 create_tarball ;;
239 cvs*)
240 [ -f $INSTALLED/cvs/receipt ] || tazpkg get-install cvs
241 url=${file#cvs|}
242 mod=$PACKAGE
243 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
244 gettext -e "Getting source from CVS...\n"
245 echo "URL: $url"
246 [ "$CVS_MODULE" ] && echo "CVS module: $mod"
247 gettext "Cloning to: "; echo "$pwd/$mod"
248 cvs -d:$url co $mod && mv $mod $pkgsrc
249 create_tarball ;;
250 svn*|subversion*)
251 [ -f $INSTALLED/subversion/receipt ] || tazpkg get-install subversion
252 if $(echo "$file" | fgrep -q "svn|"); then
253 url=${file#svn|}
254 else
255 url=${file#subversion|}
256 fi
257 gettext -e "Getting source from SVN...\n"
258 echo "URL: $url"
259 if [ "$BRANCH" ]; then
260 echo t | svn co $url -r $BRANCH $pkgsrc
261 else
262 echo t | svn co $url $pkgsrc
263 fi
264 create_tarball ;;
265 *)
266 gettext -e "\nERROR: Unable to handle:"; echo -e " $file \n" | \
267 tee -a $LOGS/$PACKAGE.log
268 exit 1 ;;
269 esac
270 done
271 }
273 # get source tarball
274 # $1 = --extract
275 getsrc() {
276 gettext "Getting source for:"; echo " $pkg"
277 set_paths
278 [ -f "$SRC/$lzma_tarball" ] && \
279 TARBALL="$lzma_tarball"
281 # Get source tarball and make sure we have source dir named:
282 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
283 # tarball if it exists.
284 look_for_cookopt !unpack && unpack="no"
285 look_for_cookopt !repack_src && LZMA_SRC=""
286 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! "$unpack" ] && [ ! "$cook_code" ]; then
287 [ -d $tmpsrc ] && rm -rf $tmpsrc
288 mkdir -p $tmpsrc && cd $tmpsrc
289 fi
291 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
292 separator && download
293 fi
295 if [ "$WGET_URL" ] && [ -f "$SRC/$TARBALL" ] && [ ! "$unpack" ] && [ ! "$cook_code" ]; then
296 [ "$TARBALL" = "$lzma_tarball" ] && LZMA_SRC=""
297 if [ "$1" = "--extract" ]; then
298 extract_source || exit 1
299 if [ ! -f "$SRC/$lzma_tarball" ] && [ "$LZMA_SRC" ]; then
300 echo -e "Repacking source."
301 repack_source || exit 1
302 fi
303 extract_path || exit 1
304 if [ -f $SRC/$TARBALL ]; then
305 [ -d $tmpsrc ] && rm -rf $tmpsrc
306 fi
307 fi
308 fi
310 # This is to make sure if PATCH equals something it will be downloaded
311 # checks are done in download functions
312 if [ "$PATCH" ] && [ ! "$cook_code" ]; then
313 if [ ! -f "$SRC/$PTARBALL" ]; then
314 separator && download
315 fi
316 fi
318 echo -e "Tarball: $SRC/$TARBALL"
319 [ "$PATCH" ] && echo -e "Patch: $SRC/$PTARBALL"
320 }
322 # the base function to download sources when offline
323 # This is to make sure source can be download when local-mirror
324 # script is in use.
325 download_base() {
326 local URLS url alt_url orig_url orig_url_patch
327 url="$ONLINE_SRC_REPOSITORY"
328 if [ "$SOURCE" ]; then
329 alt_url="${url}${SOURCE:0:1}/$SOURCE-${KBASEVER:-$VERSION}.tar.lzma"
330 else
331 alt_url="${url}${PACKAGE:0:1}/$PACKAGE-${KBASEVER:-$VERSION}.tar.lzma"
332 fi
333 orig_url="${url}${TARBALL:0:1}/$TARBALL"
334 [ "$PATCH" ] && orig_url_patch="${url}${PTARBALL:0:1}/$PTARBALL"
335 URLS="$@ $alt_url $orig_url $orig_url_patch"
336 [ "$LAN_MIRROR" ] && URLS="$alt_url $orig_url $orig_url_patch $@"
337 if [ "$WGET_URL" = "$orig_url" ]; then
338 [ "$TARBALL" = "$lzma_tarball" ] && LZMA_SRC=""
339 get_source $@
340 elif [ "$WGET_URL" = "$alt_url" ]; then
341 LZMA_SRC=""
342 get_source $@
343 else
344 for i in $URLS; do
345 if [ "$1" = "$PATCH" ]; then
346 [ ! -f "$SRC/$PTARBALL" ] || continue
347 else
348 [ ! -f "$SRC/$TARBALL" ] || continue
349 fi
350 case $i in
351 ${url}*)
352 [ "$i" = "$alt_url" ] && TARBALL="$(basename $alt_url)"
353 [ "$i" = "$alt_url" ] && LZMA_SRC=""
354 get_source $i
355 ;;
356 *)
357 get_source $i ;;
358 esac
359 done
360 fi
361 }
363 # Get source from multible urls
364 download() {
365 if [ ! -s "$SRC/$TARBALL" ]; then
366 download_base $WGET_URL
367 [ -f "$SRC/$TARBALL" ] || broken
368 fi
370 if [ "$PATCH" ]; then
371 if [ ! -s "$SRC/$PTARBALL" ]; then
372 download_base $PATCH
373 [ -f "$SRC/$PTARBALL" ] || broken
374 fi
375 fi
376 }
378 # Extract source package.
379 extract_source() {
380 gettext "Extracting:"; echo " $TARBALL"
381 case "$TARBALL" in
382 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
383 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
384 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
385 *.tar) tar xf $SRC/$TARBALL ;;
386 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
387 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
388 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
389 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
390 *.deb) ar vx $SRC/$TARBALL
391 [ ! -d $tmpsrc/$PACKAGE-$VERSION ] && mkdir -p $tmpsrc/$PACKAGE-$VERSION
392 cd $tmpsrc/$PACKAGE-$VERSION
393 tar -xvzf $tmpsrc/data.tar.gz
394 [ -f $tmpsrc/data.tar.gz ] && rm -f $tmpsrc/data.tar.gz
395 [ -f $tmpsrc/control.tar.gz ] && rm -f $tmpsrc/control.tar.gz
396 [ -f $tmpsrc/debian-binary ] && rm -f $tmpsrc/debian-binary ;;
397 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
398 *.7z) 7zr x $SRC/$TARBALL ;;
399 *) cp $SRC/$TARBALL $(pwd) ;;
400 esac
401 chown -R 0.0 $(pwd)
402 }
404 # Repack source tarball as .tar.lzma
405 # The source tarball is extracted as $tmpsrc/$pkgsrc path
406 # This way the source has a clean path when building
407 repack_source() {
409 # Some archives are not well done and don't extract to one dir (ex lzma).
410 files=$(ls | wc -l)
411 [ "$files" == 1 ] && [ -d "$(ls)" ] && [ ! -d "$pkgsrc" ] && mv * $tmpsrc/$pkgsrc
412 if [ ! -d "$tmpsrc/$pkgsrc" ]; then
413 cd $basesrc
414 if [ "$(ls -A tmp | wc -l)" -gt 1 ] || [ -f "$(echo tmp/*)" ]; then
415 mv tmp tmp-1 && mkdir tmp
416 mv tmp-1 tmp/$pkgsrc
417 fi
418 fi
419 if [ -d "$tmpsrc/$pkgsrc" ]; then
420 gettext "Repacking source is enabled:"; echo " LZMA_SRC"
421 TARBALL=$lzma_tarball
422 cd $tmpsrc
423 if [ -x /usr/bin/optipng ]; then
424 [ "$SHRINKPNG" ] && find -name "*.png" -type f | xargs -i optipng "{}"
425 fi
426 tar -c * | lzma e $SRC/$TARBALL -si $LZMA_SET_DIR
427 if [ $REMOVE_ORIG_TARBALL ]; then
428 if [ -f $SRC/$TARBALL ]; then
429 [ -f $SRC/$orig_tarball ] && rm -f $SRC/$orig_tarball
430 fi
431 fi
432 fi
433 }
435 # Display cooked package summary.
436 summary() {
437 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
438 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
439 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
440 size=$(du -sh $INCOMING/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
441 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
442 [ "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
443 cookdate=$(date "+%Y-%m-%d %H:%M")
444 sec=$time
445 div=$(( ($time + 30) / 60))
446 [ "$div" != 0 ] && min="~ ${div}m"
447 gettext "Summary for:"; echo " $PACKAGE $VERSION"
448 separator
449 [ "$srcdir" ] && echo "Source dir : $srcdir"
450 [ "$TARBALL" ] && echo "Src file : $TARBALL"
451 [ "$srcsize" ] && echo "Src size : $srcsize"
452 [ "$prod" ] && echo "Produced : $prod"
453 cat << EOT
454 Packed : $fs
455 Compressed : $size
456 Files : $files
457 Cook time : ${sec}s $min
458 Cook date : $cookdate
459 Host arch : $ARCH
460 $(separator)
461 EOT
462 }
464 # Display debugging error info.
465 debug_info() {
466 echo -e "\nDebug information"
467 separator
468 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
469 for error in \
470 ERROR "No package" "cp: can't" "can't open" "can't cd" \
471 "error:" "fatal error:" "rm: can't remove" "cp: can't stat" \
472 "undefined reference to" "Unable to connect to" \
473 "link: cannot find the library" "CMake Error"
474 do
475 fgrep "$error" $LOGS/$pkg.log
476 done
477 separator && newline
478 }
480 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
481 # so some packages need to copy these files with the receipt and genpkg_rules.
482 copy_generic_files()
483 {
484 # $LOCALE is set in cook.conf
485 if [ "$LOCALE" -a "$WANTED" = "" ]; then
486 if [ -d "$install/usr/share/locale" ]; then
487 mkdir -p $fs/usr/share/locale
488 for i in $LOCALE
489 do
490 if [ -d "$install/usr/share/locale/$i" ]; then
491 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
492 fi
493 done
494 fi
495 fi
497 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
498 if [ "$GENERIC_PIXMAPS" != "no" ]; then
499 if [ -d "$install/usr/share/pixmaps" ]; then
500 mkdir -p $fs/usr/share/pixmaps
501 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
502 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
503 $fs/usr/share/pixmaps
504 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
505 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
506 $fs/usr/share/pixmaps
507 fi
508 fi
510 # Custom or homemade PNG pixmap can be in stuff.
511 if [ -f "$stuff/$PACKAGE.png" ]; then
512 mkdir -p $fs/usr/share/pixmaps
513 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
514 fi
515 fi
517 # Desktop entry (.desktop).
518 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
519 if [ "$GENERIC_MENUS" != "no" ]; then
520 if [ -d "$install/usr/share/applications" ] && [ "$WANTED" == "" ]; then
521 mkdir -p $fs/usr/share
522 cp -a $install/usr/share/applications $fs/usr/share
523 fi
524 fi
526 # Homemade desktop file(s) can be in stuff.
527 if [ -d "$stuff/applications" ]; then
528 mkdir -p $fs/usr/share
529 cp -a $stuff/applications $fs/usr/share
530 fi
531 if [ -f "$stuff/$PACKAGE.desktop" ]; then
532 mkdir -p $fs/usr/share/applications
533 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
534 fi
536 # Add custom licenses
537 if [ -d "$stuff/licenses" ]; then
538 mkdir -p $fs/usr/share/licenses
539 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
540 fi
541 }
543 # Find and strip : --strip-all (-s) or --strip-debug on static libs as well
544 # as removing uneeded files like in Python packages. Cross compiled binaries
545 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
546 strip_package()
547 {
548 case "$ARCH" in
549 arm|x86_64) export STRIP=${HOST_SYSTEM}-strip ;;
550 *) export STRIP=strip ;;
551 esac
552 gettext "Executing strip on all files..."
553 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
554 do
555 if [ -d "$dir" ]; then
556 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
557 fi
558 done
559 find $fs -name "*.so*" -exec $STRIP -s '{}' 2>/dev/null \;
560 find $fs -name "*.a" -exec $STRIP --strip-debug '{}' 2>/dev/null \;
561 status
563 # Remove Python .pyc and .pyo from packages.
564 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
565 gettext "Removing Python compiled files..."
566 find $fs -type f -name "*.pyc" -delete 2>/dev/null
567 find $fs -type f -name "*.pyo" -delete 2>/dev/null
568 status
569 fi
571 # Remove Perl perllocal.pod and .packlist from packages.
572 if echo "$DEPENDS" | fgrep -q "perl"; then
573 gettext "Removing Perl compiled files..."
574 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
575 find $fs -type f -name ".packlist" -delete 2>/dev/null
576 status
577 fi
578 }
580 # Remove installed deps.
581 remove_deps() {
582 # Now remove installed build deps.
583 diff="$CACHE/installed.cook.diff"
584 if [ -s "$CACHE/installed.cook.diff" ]; then
585 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
586 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
587 gettext "Build dependencies to remove:"; echo " $nb"
588 gettext "Removing:"
589 for dep in $deps
590 do
591 echo -n " $dep"
592 tazpkg remove $dep --auto --root=/ >/dev/null
593 done
594 echo -e "\n"
595 # Keep the last diff for debug and info.
596 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
597 fi
598 }
600 # extract path of source tarball
601 # This is for the getsrc --extract option
602 extract_path()
603 {
604 # Some archives are not well done and don't extract to one dir (ex lzma).
605 files=$(ls | wc -l)
606 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
607 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
608 mv * ../$PACKAGE-$VERSION/$TARBALL
609 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
610 mv * ../$PACKAGE-$VERSION
611 cd .. && rm -rf tmp
612 if [ "$TOUCH_FILES" ]; then
613 echo "Touching source files to update timestamp"
614 echo "May take a bit"
615 find $src -type f -exec touch "{}" \;
616 fi
617 }
619 # The main cook function.
620 cookit() {
621 echo "Cook: $PACKAGE $VERSION"
622 separator
623 set_paths
625 # Handle cross-tools.
626 case "$ARCH" in
627 arm|x86_64)
628 # CROSS_COMPILE is used by at least Busybox and the kernel to set
629 # the cross-tools prefix but first check if sysroot is used.
630 # the cross-tools prefix. Sysroot the the root of our target arch
631 sysroot=$CROSS_TREE/sysroot
632 tools=$CROSS_TREE/tools
633 # Set root path when cross compiling. ARM tested but not x86_64
634 # When cross compiling we must install build deps in $sysroot.
635 arch="-${ARCH}"
636 root=$sysroot
637 echo "$ARCH sysroot: $sysroot"
638 echo "Adding $tools/bin to PATH"
639 export PATH=$PATH:$tools/bin
640 export PKG_CONFIG_PATH=$sysroot/usr/lib/pkgconfig
641 export CROSS_COMPILE=${HOST_SYSTEM}-
642 echo "Using cross-tools: $CROSS_COMPILE"
643 if [ "$ARCH" == "x86_64" ]; then
644 export CC="${HOST_SYSTEM}-gcc -m64"
645 export CXX="${HOST_SYSTEM}-g++ -m64"
646 else
647 export CC=${HOST_SYSTEM}-gcc
648 export CXX=${HOST_SYSTEM}-g++
649 fi
650 export AR=${HOST_SYSTEM}-ar
651 export AS=${HOST_SYSTEM}-as
652 export RANLIB=${HOST_SYSTEM}-ranlib
653 export LD=${HOST_SYSTEM}-ld
654 export STRIP=${HOST_SYSTEM}-strip ;;
655 *)
656 root="/" ;;
657 esac
659 [ "$QA" ] && receipt_quality
660 cd $pkgdir
661 rm -rf install taz source
663 # Disable -pipe if less than 512Mb free RAM.
664 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
665 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
666 gettext -e "Disabling -pipe compile flag: $free RAM\n"
667 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
668 CXXFLAGS="${CXXFLAGS/-pipe}" && \
669 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
670 fi
671 unset free
673 # Export flags and path to be used by make and receipt.
674 DESTDIR=$pkgdir/install
675 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
676 #export LDFLAGS
678 if [ ! "$WANTED" ] && [ "$TARBALL" ]; then
679 getsrc --extract
680 fi
682 # Check for build deps and handle implicit depends of *-dev packages
683 # (ex: libusb-dev :: libusb).
684 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
685 touch $CACHE/installed.local $CACHE/installed.web
686 look_for_cookopt !auto_dep && AUTO_DEP=""
687 if [ "$AUTO_DEP" -a ! "$WANTED" ]; then
688 BDEPS=$(scan $PACKAGE --look_for=bdep --with_dev | \
689 grep -v $(for i in $(look_for_rwanted) $PACKAGE; do echo " -e ^$i$"; done))
690 else
691 BDEPS="$BUILD_DEPENDS"
692 fi
693 [ "$BDEPS" ] && gettext -e "Checking build dependencies...\n"
694 [ "$root" != "/" ] && echo "Using packages DB: ${root}$DB"
695 for dep in $BDEPS
696 do
697 for i in $dep
698 do
699 if [ ! -f "${root}$INSTALLED/$i/receipt" ]; then
700 # Try local package first. In some cases implicit doesn't exist, ex:
701 # libboost-dev exists but not libboost, so check if we got vers.
702 unset vers
703 [ -f $WOK/$i/receipt ] || continue
704 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
705 if [ -f "$INCOMING/$i-${vers}_${kbasevers}.tazpkg" ]; then
706 echo $i-${vers}_${kbasevers}.tazpkg >> $CACHE/installed.local
707 elif [ -f "$PKGS/$i-${vers}_${kbasevers}.tazpkg" ]; then
708 echo $i-${vers}_${kbasevers}.tazpkg >> $CACHE/installed.local
709 elif [ -f "$INCOMING/$i-$vers.tazpkg" ]; then
710 echo $i-$vers.tazpkg >> $CACHE/installed.local
711 elif [ -f "$PKGS/$i-$vers.tazpkg" ]; then
712 echo $i-$vers.tazpkg >> $CACHE/installed.local
713 else
714 # Priority to package version in wok (maybe more up-to-date)
715 # than the mirrored one.
716 if [ "$vers" ]; then
717 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
718 echo $i >> $CACHE/installed.web
719 else
720 # So package exists in wok but not available.
721 gettext "Missing dep (wok/pkg):"; echo " $i $vers"
722 echo $i >> $CACHE/missing.dep
723 fi
724 else
725 # Package is not in wok but may be in online repo.
726 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
727 echo $i >> $CACHE/installed.web
728 else
729 echo "ERROR: unknown dep $i" && exit 1
730 fi
731 fi
732 fi
733 fi
734 done
735 done
737 # Get the list of installed packages
738 ls -1 ${root}$INSTALLED > $CACHE/installed.list
740 # Have we a missing build dep to cook ?
741 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
742 gettext -e "Auto cook config is set : AUTO_COOK\n"
743 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
744 for i in $(uniq $CACHE/missing.dep)
745 do
746 (gettext "Building dep (wok/pkg) :"; echo " $i $vers") | \
747 tee -a $LOGS/$PACKAGE.log.$$
748 cook $i || (echo -e "ERROR: can't cook dep '$i'\n" && \
749 fgrep "remove: " $LOGS/$i.log && \
750 fgrep "Removing: " $LOGS/$i.log && newline) | \
751 tee -a $LOGS/$PACKAGE.log.$$ && break
752 done
753 rm -f $CACHE/missing.dep
754 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
755 fi
757 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
758 # is enabled and cook fails we have ERROR in log, if no auto cook we have
759 # missing dep in cached file.
760 if fgrep -q "ERROR:" $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
761 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
762 echo "ERROR: missing dep $nb" && exit 1
763 fi
765 # Install local packages: package-version${arch}
766 for i in $(uniq $CACHE/installed.local)
767 do
768 if [ -f "$INCOMING/$i" ]; then
769 gettext "Installing dep (pkg/local):"; echo " $i"
770 tazpkg install $INCOMING/$i --root=$root >/dev/null
771 elif [ -f "$PKGS/$i" ]; then
772 gettext "Installing dep (pkg/local):"; echo " $i"
773 tazpkg install $PKGS/$i --root=$root >/dev/null
774 fi
775 done
777 # Install web or cached packages (if mirror is set to $PKGS we only
778 # use local packages).
779 for i in $(uniq $CACHE/installed.web)
780 do
781 gettext "Installing dep (web/cache):"; echo " $i"
782 tazpkg get-install $i --root=$root >/dev/null
783 done
785 # If a cook failed deps are removed.
786 ls -1 ${root}$INSTALLED > $CACHE/installed.cook
787 [ ! -s "$CACHE/installed.cook.diff" ] && \
788 busybox diff $CACHE/installed.list $CACHE/installed.cook > $CACHE/installed.cook.diff
789 deps=$(cat $CACHE/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
791 # Execute receipt rules.
792 if [ $(grep ^compile_rules $receipt) ] && [ "$cook_code" = "" ]; then
793 echo "Executing: compile_rules"
794 echo "CFLAGS : $CFLAGS"
795 #echo "LDFLAGS : $LDFLAGS"
796 [ -d "$src" ] && cd $src
797 compile_rules $@ || broken
798 [ "$cook_code" ] && exit 1
799 # Stay compatible with _pkg
800 [ -d "$src/_pkg" ] && mv $src/_pkg $install
801 # QA: compile_rules success so valid.
802 mkdir -p $install
803 else
804 # QA: No compile_rules so no error, valid.
805 mkdir -p $install
806 fi
807 separator && newline
809 # Execute testsuite.
810 if grep -q ^testsuite $receipt; then
811 echo "Running testsuite"
812 separator
813 testsuite $@ || exit 1
814 separator && newline
815 fi
816 }
818 # Cook quality assurance.
819 cookit_quality() {
820 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
821 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
822 fi
823 # ERROR can be echoed any time in cookit()
824 if grep -Eq '(ERROR:|undefined reference to)' $LOGS/$pkg.log; then
825 debug_info | tee -a $LOGS/$pkg.log
826 rm -f $command && exit 1
827 fi
828 }
830 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
831 # but it doesn't handle EXTRAVERSION.
832 packit() {
833 set_paths
835 # Handle cross compilation
836 case "$ARCH" in
837 arm|x86_64) arch="-$ARCH" ;;
838 esac
840 echo "Pack: $PACKAGE ${VERSION}${arch}"
841 separator
843 if grep -q ^genpkg_rules $receipt; then
844 gettext -e "Executing: genpkg_rules\n"
845 set -e && cd $pkgdir && mkdir -p $fs
846 genpkg_rules || (broken && echo -e "\nERROR: genpkg_rules failed\n" >> \
847 $LOGS/$pkg.log)
848 else
849 gettext "No packages rules: meta package"; echo
850 mkdir -p $fs
851 fi
853 # First QA check to stop now if genpkg_rules failed.
854 if grep -Eq '(^ERROR|No such file or directory)' $LOGS/$pkg.log; then
855 broken && exit 1
856 fi
858 cd $taz
859 for file in receipt description.txt
860 do
861 [ ! -f "../$file" ] && continue
862 gettext "Copying"; echo -n " $file..."
863 cp -f ../$file $pack && chown 0.0 $pack/$file && status
864 done
865 copy_generic_files
867 # Create files.list with redirecting find output.
868 gettext "Creating the list of files..." && cd $fs
869 find . -type f -print > ../files.list
870 find . -type l -print >> ../files.list
871 cd .. && sed -i s/'^.'/''/ files.list
872 status
874 # Strip and stuff files.
875 look_for_cookopt !strip && STRIP="n"
876 [ "$STRIP" ] || strip_package
878 # Md5sum of files.
879 gettext "Creating $CHECKSUM of files..."
880 while read file; do
881 [ -L "fs$file" ] && continue
882 [ -f "fs$file" ] || continue
883 case "$file" in
884 /lib/modules/*/modules.*|*.pyc) continue ;;
885 esac
886 $CHECKSUM "fs$file" | sed 's/ fs/ /'
887 done < files.list > "$CHECKSUM"
888 status
889 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
890 description.txt 2> /dev/null | awk \
891 '{ sz=$1 } END { print sz }')
893 if [ "$UPCOOKLIST" ]; then
894 check_so_files
895 fi
897 # Generate md5 of cooking stuff to look for commit later.
898 gen_cookmd5
899 echo -e "\n# md5sum of cooking stuff :" >> receipt
900 cat $WOK/$PACKAGE/md5 | sed 's/^/# /' >> receipt
902 # Build cpio archives.
903 gettext "Compressing the fs... "
904 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si $LZMA_SET_DIR
905 rm -rf fs
906 status
907 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
908 $CHECKSUM description.txt 2> /dev/null | awk \
909 '{ sz=$1 } END { print sz }')
910 gettext "Updating receipt sizes..."
911 sed -i s/^PACKED_SIZE.*$// receipt
912 sed -i s/^UNPACKED_SIZE.*$// receipt
913 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
914 status
916 # Set extra version.
917 if [ "$EXTRAVERSION" ]; then
918 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
919 sed -i s/^EXTRAVERSION.*$// receipt
920 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
921 status
922 fi
924 # Compress.
925 gettext "Creating full cpio archive... "
926 find . -print | cpio -o -H newc --quiet > \
927 ../$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg
928 status
929 gettext "Restoring original package tree... "
930 unlzma -c fs.cpio.lzma | cpio -idm --quiet
931 status
932 rm fs.cpio.lzma && cd ..
934 if [ "$UPCOOKLIST" ]; then
935 check_recook_rdeps
936 fi
938 # QA and give info.
939 tazpkg=$(ls *.tazpkg)
940 packit_quality
941 separator && gettext "Package:"; echo -e " $tazpkg\n"
942 }
944 # Verify package quality and consistency.
945 packit_quality() {
946 #gettext "QA: Checking for broken link..."
947 #link=$(find $fs/usr -type l -follow)
948 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
949 #status
951 # Exit if any error found in log file.
952 if grep -Eq '(^ERROR|No such file or directory)' $LOGS/$pkg.log; then
953 rm -f $command && exit 1
954 fi
956 gettext "QA: Checking for empty package..."
957 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
958 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
959 echo -e "\nERROR: empty package"
960 rm -f $command && exit 1
961 else
962 # Ls sort by name so the first file is the one we want.
963 old=$(ls $INCOMING/$pkg-[0-9]*.tazpkg 2>/dev/null | head -n 1)
964 status
965 if [ -f "$old" ]; then
966 gettext "Removing old: $(basename $old)"
967 rm -f $old && status
968 fi
969 mv -f $pkgdir/taz/$pkg-*.tazpkg $INCOMING
970 sed -i /^${pkg}$/d $broken
971 fi
972 }
974 # Install package on --install or update the chroot.
975 install_package()
976 {
977 local pkg build
978 case "$ARCH" in
979 arm|x86_64)
980 arch="-${ARCH}"
981 root=$CROSS_TREE/sysroot ;;
982 *)
983 root="/" ;;
984 esac
985 # Install package if requested but skip install if target host doesn't
986 # match build system or it will break the build chroot.
987 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
988 for pkg in $PACKAGE; do
989 if [ -f "$inst" ] && [ "$build" == "$ARCH" ]; then
990 if [ -f "$INCOMING/$pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg" ]; then
991 echo "Updating $ARCH chroot environment..."
992 echo "Updating chroot: $pkg (${VERSION}${EXTRAVERSION}${arch})" | log
993 tazpkg install \
994 $INCOMING/$pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg --root=$root --forced
995 else
996 gettext -e "Unable to install package, build has failed.\n\n"
997 exit 1
998 fi
999 fi
1000 done
1002 # Install package if part of the chroot to keep env up-to-date.
1003 if [ -f "${root}$INSTALLED/$pkg/receipt" ]; then
1004 . /etc/slitaz/cook.conf
1005 . $WOK/$pkg/taz/$pkg-*/receipt
1006 echo "Updating $ARCH chroot environment..."
1007 echo "Updating chroot: $pkg (${VERSION}${EXTRAVERSION}${arch})" | log
1008 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg" ]; then
1009 tazpkg install \
1010 $PKGS/$pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg \
1011 --forced --root=$root
1012 elif [ -f "$INCOMING/$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg" ]; then
1013 tazpkg install \
1014 $INCOMING/$pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg \
1015 --forced --root=$root
1016 fi
1017 fi
1020 tac()
1022 sed '1!G;h;$!d' $1
1025 # this function is to build the unbuild list
1026 unbuild()
1028 check_root
1029 get_options_list="full list"
1030 get_options
1031 [ -f $unbuild ] && rm -rf $unbuild
1032 LIST="$fullco"
1033 [ -f "$1" ] && LIST="$1"
1034 #[ "$full" ] && LIST=$(ls $WOK)
1035 if [ -f "$1" -a "$full" ]; then
1036 COMMAND=gen-cooklist
1037 gen_cook_list
1038 LIST="$tmp/cooklist"
1039 fi
1040 for pkg in $(cat $LIST | grep -v ^#); do
1041 unset VERSION PACKAGE
1042 [ -f $WOK/$pkg/receipt ] || continue
1043 . $WOK/$pkg/receipt
1044 if [ ! -f $INCOMING/$PACKAGE-${VERSION}*.tazpkg -a ! -f $PKGS/$PACKAGE-${VERSION}*.tazpkg ]; then
1045 echo "$PACKAGE" && echo "$PACKAGE" >> $unbuild
1046 fi
1047 done
1048 unset pkg
1049 [ "$list" ] && cp -a $unbuild $cooklist
1052 # Launch the cook command into a chroot jail protected by aufs.
1053 # The current filesystems are used read-only and updates are
1054 # stored in a separate branch.
1055 try_aufs_chroot() {
1057 base=/dev/shm/aufsmnt$$
1059 # Can we setup the chroot ? Is it already done ?
1060 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1061 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1062 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1063 mkdir ${base}root ${base}rw || return
1065 echo "Setup aufs chroot..."
1067 # Sanity check
1068 for i in / /proc /sys /dev/shm /dev/pts /home ; do
1069 case " $AUFS_MOUNTS " in
1070 *\ $i\ *) ;;
1071 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1072 esac
1073 done
1074 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
1075 mount --bind $mnt ${base}root$mnt
1076 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1077 echo "Aufs mountage failure"
1078 umount ${base}root
1079 rmdir ${base}*
1080 return
1081 fi
1082 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1083 done
1085 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1086 status=$?
1088 echo "Leaving aufs chroot..."
1089 tac ${base}rw/aufs-umount.sh | sh
1090 rm -rf ${base}rw
1091 umount ${base}root
1092 rmdir $base*
1094 # Install package if requested
1095 install_package
1096 exit $status
1099 # Create a XML feed for freshly built package.
1100 gen_rss() {
1101 pubdate=$(date "+%a, %d %b %Y %X")
1102 cat > $FEEDS/$pkg.xml << EOT
1103 <item>
1104 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
1105 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1106 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
1107 <pubDate>$pubdate</pubDate>
1108 <description>$SHORT_DESC</description>
1109 </item>
1110 EOT
1113 # Truncate stdout log file to $1 Mb
1114 loglimit()
1116 [ -n "$DEFAULT_LOG_LIMIT" ] || return
1117 tee /dev/stderr | dd bs=1024k count=${1:-$DEFAULT_LOG_LIMIT} 2> /dev/null
1121 # Commands
1124 case "$COMMAND" in
1125 usage|help|-u|-h)
1126 usage ;;
1127 list-wok)
1128 gettext -e "\nList of packages in:"; echo " $WOK"
1129 separator
1130 cd $WOK && ls -1
1131 separator
1132 echo -n "Packages: " && ls | wc -l
1133 newline ;;
1134 activity)
1135 cat $activity ;;
1136 search)
1137 # Just a simple search function, we dont need more actually.
1138 query="$2"
1139 newline
1140 gettext "Search results for:"; echo " $query"
1141 separator
1142 cd $WOK && ls -1 | grep "$query"
1143 separator && newline ;;
1144 setup)
1145 # Setup a build environment
1146 check_root
1147 echo "Cook: setup environment" | log
1148 newline
1149 gettext "Setting up your environment"; newline
1150 separator && cd $SLITAZ
1151 init_db_files
1152 gettext "Checking for packages to install..."; echo
1153 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1154 # ARCH-setup or 'cross check-env' should be used before: cook setup
1155 case "$ARCH" in
1156 arm|x86_64)
1157 if [ ! -x "/usr/bin/cross" ]; then
1158 gettext "ERROR: cross is not installed"; echo
1159 exit 1
1160 fi
1161 gettext "Using config file: /etc/slitaz/cross.conf"; echo
1162 . /etc/slitaz/cross.conf ;;
1163 esac
1164 for pkg in $INSTALL_PKGS; do
1165 if [ "$forced" ]; then
1166 tazpkg -gi $pkg --forced
1167 else
1168 [ -f "$INSTALLED/$pkg/receipt" ] || tazpkg get-install $pkg
1169 fi
1170 done
1171 # chroot list
1172 ls -1 "$INSTALLED" > $CACHE/chroot-pkgs
1173 # Handle --options
1174 case "$2" in
1175 --wok)
1176 hg clone $WOK_URL $WOKHG || exit 1 ;;
1177 --stable)
1178 hg clone $WOK_URL-stable $WOKHG || exit 1 ;;
1179 --undigest)
1180 hg clone $WOK_URL-undigest $WOKHG || exit 1 ;;
1181 --tiny)
1182 hg clone $WOK_URL-tiny $WOKHG || exit 1 ;;
1183 esac
1185 rsync_wok
1187 # SliTaz group and permissions
1188 if ! grep -q ^slitaz /etc/group; then
1189 gettext -e "Adding group: slitaz\n"
1190 addgroup slitaz
1191 fi
1192 gettext -e "Setting permissions for slitaz group...\n"
1193 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1194 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1195 separator
1196 gettext -e "All done, ready to cook packages :-)\n\n" ;;
1197 *-setup)
1198 # Setup for cross compiling.
1199 arch=${1%-setup}
1200 check_root
1201 echo "Cook: setup $arch cross environment" | log
1202 newline
1203 boldify $(gettext "Setting up your $arch cross environment")
1204 separator
1205 init_db_files
1206 sed -i \
1207 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1208 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1209 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1210 /etc/slitaz/cook.conf
1211 case "$arch" in
1212 arm)
1213 sed -i \
1214 -e s'/CFLAGS=.*/CFLAGS="-march=armv6 -O2"/' \
1215 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux-gnueabi/' \
1216 -e s'/xorg-dev/""/' \
1217 /etc/slitaz/cook.conf ;;
1218 x86_64)
1219 sed -i \
1220 -e s'/CFLAGS=.*/CFLAGS=""/' \
1221 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux/' \
1222 /etc/slitaz/cook.conf ;;
1223 esac
1224 . /etc/slitaz/cook.conf
1225 sysroot=$CROSS_TREE/sysroot
1226 tools=/cross/$arch/tools
1227 root=$sysroot
1228 CC=$tools/bin/${HOST_SYSTEM}-gcc
1229 echo "Target arch : $ARCH"
1230 echo "Configure args : $CONFIGURE_ARGS"
1231 echo "Arch sysroot : $sysroot"
1232 echo "Tools prefix : $tools/bin"
1233 # Tell the packages manager where to find packages.
1234 echo "Packages DB : ${root}$DB"
1235 mkdir -p ${root}$INSTALLED
1236 cd ${root}$DB && rm -f *.bak
1237 for list in packages.list packages.desc packages.equiv packages.md5
1238 do
1239 rm -f $list && ln -s $SLITAZ/packages/$list $list
1240 done
1241 # We must have the cross compiled glibc-base installed or default
1242 # i486 package will be used as dep by tazpkg and then break the
1243 # cross environment
1244 if [ ! -f "${root}$INSTALLED/glibc-base/receipt" ]; then
1245 colorize 36 "WARNING: (e)glibc-base is not installed in sysroot"
1246 fi
1247 # Show GCC version or warn if not yet compiled.
1248 if [ -x $CC ]; then
1249 echo "Cross compiler : ${HOST_SYSTEM}-gcc"
1250 else
1251 colorize 36 "C compiler is missing: ${HOST_SYSTEM}-gcc"
1252 echo "Run 'cross compile' to cook a toolchain"
1253 fi
1254 separator && newline ;;
1255 upwok)
1256 case "$2" in
1257 --local)
1258 gettext -e "Updating local chanages in wok-hg to wok...\n"
1259 rsync_wok || exit 1
1260 exit 1 ;;
1261 esac
1263 gettext -e "Updating wok-hg...\n"
1264 if [ -d $WOKHG/.hg ]; then
1265 cd $WOKHG
1266 hg pull -u || exit 1
1267 fi
1268 cd $SLITAZ
1269 rsync_wok || exit 1 ;;
1270 test)
1271 # Test a cook environment.
1272 echo "Cook test: testing the cook environment" | log
1273 [ ! -d "$WOK" ] && exit 1
1274 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1275 cook cooktest ;;
1276 new)
1277 # Create the package folder and an empty receipt.
1278 pkg="$2"
1279 [ "$pkg" ] || usage
1280 newline
1281 if [ -d "$WOKHG/$pkg" ]; then
1282 echo -n "$pkg " && gettext "package already exists."
1283 echo -e "\n" && exit 1
1284 fi
1285 gettext "Creating"; echo -n " $WOKHG/$pkg"
1286 mkdir $WOKHG/$pkg && cd $WOKHG/$pkg && status
1287 gettext "Preparing the package receipt..."
1288 cp $DATA/receipt .
1289 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1290 status && newline
1292 # Interactive mode, asking and seding.
1293 case "$3" in
1294 --interactive|-x)
1295 gettext -e "Entering interactive mode...\n"
1296 separator
1297 echo "Package : $pkg"
1298 # Version.
1299 echo -n "Version : " ; read anser
1300 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
1301 # Category.
1302 echo -n "Category : " ; read anser
1303 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
1304 # Short description.
1305 echo -n "Short desc : " ; read anser
1306 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
1307 # Maintainer.
1308 echo -n "Maintainer : " ; read anser
1309 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
1310 # License.
1311 echo -n "License : " ; read anser
1312 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$anser\""/ receipt
1313 # Web site.
1314 echo -n "Web site : " ; read anser
1315 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
1316 newline
1317 # Wget URL.
1318 echo "Wget URL to download source tarball."
1319 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
1320 echo -n "Wget url : " ; read anser
1321 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
1322 # Ask for a stuff dir.
1323 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
1324 if [ "$anser" = "y" ]; then
1325 echo -n "Creating the stuff directory..."
1326 mkdir -p $WOKHG/$pkg/stuff && status
1327 fi
1328 # Ask for a description file.
1329 echo -n "Are you going to write a description ? (y/N) : " ; read anser
1330 if [ "$anser" = "y" ]; then
1331 echo -n "Creating the description.txt file..."
1332 newline > $WOKHG/$pkg/description.txt && status
1333 fi
1334 separator
1335 gettext -e "Receipt is ready to use.\n"
1336 newline ;;
1337 esac ;;
1338 list)
1339 # Cook a list of packages (better use the Cooker since it will order
1340 # packages before executing cook).
1341 check_root
1342 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
1343 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
1344 echo -e " $2\n" && exit 1
1345 echo "Cook list starting: $2" | log
1346 for pkg in $(cat $2)
1347 do
1348 cook $pkg || broken
1349 done ;;
1350 clean-wok)
1351 check_root
1352 gettext -e "\nCleaning all packages files..."
1353 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1354 status && newline ;;
1355 clean-src)
1356 check_root
1357 gettext -e "\nCleaning all packages sources..."
1358 rm -rf $WOK/*/source
1359 status && newline ;;
1360 gen-cooklist)
1361 check_root
1362 [ -f "$2" ] && LIST="$2"
1363 get_options_list="pkg wok missing"
1364 get_options
1365 if ! [ "$pkg" ]; then
1366 if [ ! "$LIST" ] || [ "$LIST" = "toolchain" ]; then
1367 pkg="$TOOLCHAIN $TOOLCHAIN_EXTRA"
1368 else
1369 check_for_list
1370 fi
1371 fi
1372 gen_cook_list
1373 if [ "$missing" ]; then
1374 cooklist=${LIST:-$cooklist}
1375 for pkgname in $(cat $cooklist)
1376 do
1377 unset EXTRAVERSION
1378 [ -f $wok/$pkgname/receipt ] || continue
1379 . $wok/$pkgname/receipt
1380 if [ -f $INCOMING/$PACKAGE-${VERSION}*.tazpkg -o -f $PKGS/$PACKAGE-${VERSION}*.tazpkg ]; then
1381 if grep "^$pkgname" $cooklist; then
1382 sed -i "s|^$pkgname$||g" $cooklist
1383 sed -i /^$/d $cooklist
1384 fi
1385 fi
1386 done
1387 fi
1389 #rm -f $command
1390 ;;
1391 gen-wok-db)
1392 check_root
1393 #echo "cook:gen-wok-db" > $command
1394 [ -d "$WOKHG" ] && WOK="$WOKHG"
1395 [ "$2" ] && WOK="$2"
1396 gen_wok_db ;;
1397 check-incoming)
1398 check_root
1399 get_options_list="forced"
1400 get_options
1401 echo "cook:check-incoming" > $command
1402 check_for_incoming
1403 rm -f $command ;;
1404 gen-src)
1405 check_root
1406 [ "$2" ] && src_repository="$2"
1407 [ -d "$src_repository" ] || src_repository="$SRC"
1408 gettext -e "Rebulding sources.list file: $src_repository"
1409 gen_sources_list $src_repository
1410 status ;;
1411 maintainers)
1412 check_root
1413 newline
1414 echo "List of maintainers for: $WOK"
1415 separator
1416 tmp="/tmp/slitaz-maintainers"
1417 touch $tmp
1418 for pkg in $WOK/*
1419 do
1420 [ -f $pkg/receipt ] || continue
1421 . $pkg/receipt
1422 if ! fgrep -q "$MAINTAINER" $tmp; then
1423 echo "$MAINTAINER" >> $tmp
1424 echo "$MAINTAINER"
1425 fi
1426 done
1427 separator
1428 echo "Maintainers: `cat $tmp | wc -l`"
1429 newline
1430 # Remove tmp files
1431 [ -f $tmp ] && rm -f $tmp
1432 ;;
1433 tags)
1434 check_root
1435 echo -e "\n\033[1mTags list :\033[0m"
1436 separator
1437 tmp="/tmp/tags"
1438 touch $tmp
1439 for pkg in $WOK/*; do
1440 unset TAGS
1441 [ -f $pkg/receipt ] || continue
1442 source $pkg/receipt
1443 for t in $TAGS; do
1444 grep -q ^$t$ $tmp && continue
1445 echo $t | tee -a $tmp
1446 done
1447 done
1448 separator
1449 echo "$(wc -l $tmp | cut -f1 -d ' ') tags listed."
1450 [ -f $tmp ] && rm -rf $tmp
1451 ;;
1452 maintained-by)
1453 # Search for packages maintained by a contributor.
1454 check_root
1455 if [ ! -n "$2" ]; then
1456 echo "Specify a name or email of a maintainer." >&2
1457 exit 1
1458 fi
1459 echo "Maintainer packages"
1460 separator
1461 for pkg in $WOK/*
1462 do
1463 [ -f $pkg/receipt ] || continue
1464 . $pkg/receipt
1465 if echo "$MAINTAINER" | fgrep -q "$2"; then
1466 echo "$PACKAGE"
1467 packages=$(($packages+1))
1468 fi
1469 done
1470 separator
1471 echo "Packages maintained by $2: $packages"
1472 newline
1473 ;;
1474 check-src)
1475 # Verify if upstream package is still available.
1477 check_root
1478 PACKAGE="$2"
1479 receipt="$WOK/$PACKAGE/receipt"
1480 if [ ! -f $receipt ]; then
1481 gettext -e "\nUnable to find package in the wok:"
1482 echo -e " $PACKAGE\n" && exit 1
1483 fi
1484 unset_receipt
1485 source $receipt
1486 check_src()
1488 for url in $@; do
1489 busybox wget -s $url 2>/dev/null && break
1490 done
1492 if [ "$WGET_URL" ];then
1493 echo -n "$PACKAGE : "
1494 check_src $WGET_URL
1495 status
1496 else
1497 echo "No tarball to check for $PACKAGE"
1498 fi
1499 ;;
1500 unbuild)
1501 unbuild "$2" "$3" ;;
1502 pkgdb)
1503 # Create suitable packages list for TazPKG and only for built packages
1504 # as well as flavors files for TazLiTo. We dont need logs since we do it
1505 # manually to ensure everything is fine before syncing the mirror.
1506 pkgdb "$2"
1507 if [ "$3" == "--flavors" ]; then
1508 cook flavors
1509 fi
1510 exit 0 ;;
1511 flavors)
1512 [ -d "$flavors" ] || $(echo -e "Missing flavors: $flavors\n" && exit 1)
1513 [ -d "$live" ] || mkdir -p $live
1514 gettext "Creating flavors files in:"; echo " $live"
1515 echo "Cook pkgdb: Creating all flavors" | log
1516 separator
1517 gettext -e "Recharging lists to use latest packages...\n"
1518 tazpkg recharge >/dev/null 2>/dev/null
1520 if [ ! -f "$live/cookiso.conf" ]; then
1521 echo "Creating configuration file: tazlito.conf"
1522 cp /etc/slitaz/cookiso.conf $live
1523 sed -i "s|WORK_DIR=.*|WORK_DIR="$SLITAZ"|g" $live/cookiso.conf
1524 fi
1526 #[ -d "$flavors/.hg" ] && $flavors && hg pull -u
1528 cd $live
1529 echo "Starting to generate flavors..."
1530 rm -f flavors.list *.flavor
1531 for i in $flavors/*
1532 do
1533 fl=$(basename $i)
1534 echo "Packing flavor: $(basename $i)"
1535 pack_flavor $fl >/dev/null || exit 1
1536 show_flavor $fl --brief --noheader 2> \
1537 /dev/null >> flavors.list
1538 done
1539 cp -f $live/*.flavor $live/flavors.list $PKGS
1540 separator && gettext "Flavors size: "; du -sh $live | awk '{print $1}'
1541 exit 0 ;;
1542 clean-chroot)
1543 clean_chroot ;;
1544 *)
1545 # Just cook and generate a package.
1546 check_root
1547 time=$(date +%s)
1548 pkg="$1"
1549 [ -z "$pkg" ] && usage
1550 receipt="$WOK/$pkg/receipt"
1551 check_pkg_in_wok && newline
1553 unset inst
1554 unset_receipt
1555 . $receipt
1557 # Handle cross compilation.
1559 # CROSS_NOTE: Actually we are running an ARM cooker but running
1560 # the cooker and build each commit in wok is not possible since
1561 # we dont cook the full wok for this arch. For ARM we need a set
1562 # of packages to handle a touch screen desktop, servers but not
1563 # erland.
1565 # The temporary solution is to build only reviewed and tested
1566 # packages with HOST_ARCH set in receipt.
1567 case "$ARCH" in
1568 arm)
1569 if [ ! "$HOST_ARCH" ]; then
1570 echo "cook: HOST_ARCH is not set in $pkg receipt"
1571 echo "cook: This package is not included in: $ARCH"
1572 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1573 echo "Cook skip: $pkg is not included in: $ARCH" | log
1574 newline && exit 1
1575 fi ;;
1576 esac
1578 # Some packages are not included in some arch or fail to cross compile.
1579 : ${HOST_ARCH=i486}
1580 if ! $(echo "$HOST_ARCH" | fgrep -q $ARCH); then
1581 echo "cook: HOST_ARCH=$HOST_ARCH"
1582 echo "cook: $pkg doesn't cook or is not included in: $ARCH"
1583 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1584 echo "Cook skip: $pkg doesn't cook or is not included in: $ARCH" | log
1585 newline && exit 1
1586 fi
1588 # Skip blocked, 3 lines also for the Cooker.
1589 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1590 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
1591 fi
1593 if [ "$AUFS_MODE" ]; then
1594 try_aufs_chroot "$@"
1595 fi
1597 # Log and source receipt.
1598 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1599 echo "cook:$pkg" > $command
1601 # Display and log info if cook process stopped.
1602 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
1603 tee -a $LOGS/$pkg.log' INT
1605 set_paths
1607 # Handle --options
1608 case "$2" in
1609 --clean|-c)
1610 gettext -e "Cleaning:"; echo -n " $pkg"
1611 cd $WOK/$pkg && rm -rf install taz source
1612 status && newline && exit 0 ;;
1613 --install|-i)
1614 inst='yes' ;;
1615 --noupdate|-nu)
1616 UPCHROOT="" ;;
1617 --nocleanchroot|-ncc)
1618 CLEAN_CHROOT="" ;;
1619 --getsrc|-gs)
1620 getsrc "$3"
1621 exit 0 ;;
1622 --block|-b)
1623 gettext "Blocking:"; echo -n " $pkg"
1624 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1625 status && newline && exit 0 ;;
1626 --unblock|-ub)
1627 gettext "Unblocking:"; echo -n " $pkg"
1628 sed -i "/^${pkg}$/"d $blocked
1629 status && newline && exit 0 ;;
1630 --pack)
1631 if [ -d $WOK/$pkg/taz ]; then
1632 rm -rf $WOK/$pkg/taz
1633 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1634 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1635 clean_log
1636 else
1637 gettext "Need to build $pkg." && exit 0
1638 fi
1639 exit 0 ;;
1640 esac
1642 # Check if wanted is built now so we have separate log files.
1643 if [ "$WANTED" ]; then
1644 if grep -q "^$WANTED$" $blocked; then
1645 echo "WANTED package $PACKAGE is blocked: $WANTED" | tee $LOGS/$pkg.log
1646 newline && rm -f $command && exit 1
1647 fi
1648 if grep -q "^$WANTED$" $broken; then
1649 echo "WANTED package $PACKAGE is broken: $WANTED" | tee $LOGS/$pkg.log
1650 newline && rm -f $command && exit 1
1651 fi
1652 if [ ! "$COOK_WANTED" ]; then
1653 if [ ! -d "$WOK/$WANTED/install" ]; then
1654 cook "$WANTED" || exit 1
1655 fi
1656 fi
1657 fi
1659 if [ "$UPCOOKLIST" ]; then
1660 db_md5=$(md5sum $dep_db $wan_db)
1661 echo "update_wok_db"
1662 update_wan_db
1663 echo "check_for_commit"
1664 check_for_commit
1665 sort -o $dep_db $dep_db
1666 sort -o $wan_db $wan_db
1667 if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
1668 grep -q "^#" $fullco || sed 1i"#PlanSort" -i $fullco
1669 fi
1670 fi
1672 # Cook and pack or exit on error and log everything.
1673 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1674 remove_deps | tee -a $LOGS/$pkg.log
1675 if [ "$CLEAN_CHROOT" ]; then
1676 clean_chroot | tee -a $LOGS/$pkg.log
1677 fi
1678 cookit_quality
1679 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1680 clean_log
1682 # Exit if any error in packing.
1683 if grep -q ^ERROR $LOGS/$pkg.log; then
1684 debug_info | tee -a $LOGS/$pkg.log
1685 broken
1686 rm -f $command && exit 1
1687 fi
1689 # This is needed cause unset and source receipt again
1690 if [ -f "$SRC/$lzma_tarball" ]; then
1691 TARBALL="$lzma_tarball"
1692 fi
1694 # Create an XML feed
1695 gen_rss
1697 # Time and summary
1698 time=$(($(date +%s) - $time))
1699 summary | tee -a $LOGS/$pkg.log
1700 newline
1702 if [ "$AUTO_PURGE_SRC" ]; then
1703 if [ -f "$SRC/$TARBALL" ]; then
1704 previous_tarball=$(grep ^$PACKAGE:incoming $SRC/sources.list | cut -f2)
1705 if [ -f "$SRC/$previous_tarball" ]; then
1706 sed "/^$PACKAGE:incoming/ s/.*/$PACKAGE:incoming\t$TARBALL/" \
1707 -i $SRC/sources.list
1708 grep -q $'\t'$previous_tarball$ $SRC/sources.list || \
1709 rm -f $SRC/$previous_tarball
1710 else
1711 echo -e "$PACKAGE:incoming\t$TARBALL" >> $SRC/sources.list
1712 fi
1713 fi
1714 fi
1716 # remove source folder if its not used in
1717 # genpkg_rules in all wanted packages
1718 remove_src
1720 install_package
1722 # Regen the cooklist if it was planned and command is not cook.
1723 [ "$regen_cooklist" -a "$UPCOOKLIST" ] && unset regen_cooklist && sort_cooklist
1725 if [ $(grep -l "^$pkg$" $broken) ]; then
1726 sed -i "^$pkg$" $broken
1727 fi
1728 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1729 # You want automation: use the Cooker Build Bot.
1730 rm -f $command ;;
1731 esac
1733 exit 0