cookutils view cook @ rev 548

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