cookutils view cook @ rev 502

Merge default.
author Christopher Rogers <slaxemulator@gmail.com>
date Wed Jun 20 23:17:27 2012 +0000 (2012-06-20)
parents ff51df709a1c e09f02df6e1e
children 755379070a00
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
12 COMMAND="$1"
14 #
15 # Functions
16 #
18 usage() {
19 cat << EOT
21 $(echo -e "\033[1m$(gettext "Usage:")\033[0m") cook [package|command] [list|--option]
23 $(echo -e "\033[1m$(gettext "Commands:")\033[0m")
24 usage|help $(gettext "Display this short usage.")
25 setup $(gettext "Setup your build environment.")
26 *-setup $(gettext "Setup a cross environment.")
27 test $(gettext "Test environment and cook a package.")
28 list-wok $(gettext "List packages in the wok.")
29 search $(gettext "Simple packages search function.")
30 new $(gettext "Create a new package with a receipt".)
31 list $(gettext "Cook a list of packages.")
32 clean-wok $(gettext "Clean-up all packages files.")
33 clean-src $(gettext "Clean-up all packages sources.")
34 upwok $(gettext "Update wok.")
35 gen-wok-db $(gettext "Build cook order files.")
36 gen-src $(gettext "Build source list.")
37 check-incoming $(gettext "Move incoming packages to packages folder.")
38 gen-cooklist $(gettext "Make cook order list.")
39 check-src $(gettext "Check upstream tarball for package in the wok.")
40 maintainers $(gettext "List all maintainers in the wok.")
41 maintained-by $(gettext "List packages maintained by a contributor.")
42 tags $(gettext "List all tags used in wok receipts.")
43 pkgdb $(gettext "Create packages DB lists and flavors.")
44 unbuild $(gettext "List all unbuild packages.")
46 $(echo -e "\033[1m$(gettext "Options:")\033[0m")
47 --clean|-c Cook : $(gettext "clean the package in the wok.")
48 --install|-i Cook : $(gettext "cook and install the package.")
49 --getsrc|-gs Cook : $(gettext "get the package source tarball.")
50 --block|-b Cook : $(gettext "Block a package so cook will skip it.")
51 --unblock|-ub Cook : $(gettext "Unblock a blocked package.")
52 --interactive|-x New : $(gettext "create a receipt interactively.")
53 --local Upwok : $(gettext "update wok local changes in wok-hg.")
54 --wok|-w Setup : $(gettext "clone the cooking wok from Hg repo.")
55 --stable Setup : $(gettext "clone the stable wok from Hg repo.")
56 --undigest Setup : $(gettext "clone the undigest wok from Hg repo.")
57 --tiny Setup: $(gettext "clone the tiny SliTaz wok from Hg repo.")
58 --forced Setup: $(gettext "force reinstall of chroot packages.")
59 --flavors Pkgdb : $(gettext "create up-to-date flavors files.")
60 --full Unbuild : $(gettext "create a full unbuild list.")
61 --list Unbuild : $(gettext "Copy unbuild list into your cooklist.")
63 EOT
64 exit 0
65 }
67 # We don't want these escapes in web interface.
68 clean_log() {
69 sed -i -e s'|\[70G\[ \[1;32m| |' \
70 -e s'|\[0;39m \]||' $LOGS/$pkg.log
71 }
73 if_empty_value() {
74 if [ -z "$value" ]; then
75 gettext "QA: empty variable:"; echo -e " ${var}=\"\"\n"
76 exit 1
77 fi
78 }
80 # Initialize files used in $CACHE
81 init_db_files() {
82 gettext "Creating directories structure in:"; echo " $SLITAZ"
83 mkdir -p $INCOMING $PKGS $SRC $FEEDS $CACHE $LOGS
84 gettext "Creating DB files in:"; echo " $CACHE"
85 for f in $activity $command $broken $blocked $commits $cookorder $cooklist $command $wan_db $dep_db $fullco $lib_db $unbuild
86 do
87 touch $f
88 done
89 if [ -f $PKGS/libraries.txt ]; then
90 cp -a $PKGS/libraries.txt $lib_db
91 fi
92 }
94 # QA: check a receipt consistency before building.
95 receipt_quality() {
96 gettext -e "QA: checking package receipt...\n"
97 unset online
98 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
99 online="online"
100 fi
101 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
102 do
103 unset value
104 value="$(. $receipt ; eval echo \$$var)"
105 case "$var" in
106 PACKAGE|VERSION|SHORT_DESC)
107 if_empty_value ;;
108 CATEGORY)
109 [ -z "$value" ] && value="empty"
110 valid="$PKGS_CATEGORIES"
111 if ! echo "$valid" | grep -q -w "$value"; then
112 gettext "QA: unknown category:"; echo -e " $value\n"
113 exit 1
114 fi ;;
115 WEB_SITE)
116 # We don't check WGET_URL since if dl is needed it will fail.
117 # Break also if we're not online. Here error is not fatal.
118 if_empty_value
119 [ -z "$online" ] || break
120 case $value in
121 https://*)
122 if ! wget -T $TIMEOUT --spider --no-check-certificate $value 2>/dev/null; then
123 gettext "QA: Unable to reach:"; echo -e " $value"
124 fi ;;
125 http://*|ftp://*)
126 if ! busybox wget -T $TIMEOUT -s $value 2>/dev/null; then
127 gettext "QA: Unable to reach:"; echo -e " $value"
128 fi ;;
129 esac
130 esac
131 done
132 }
134 # Paths used in receipt and by cook itself.
135 set_paths() {
136 pkgdir=$WOK/$PACKAGE
137 basesrc=$pkgdir/source
138 tmpsrc=$basesrc/tmp
139 src=$basesrc/$PACKAGE-$VERSION
140 taz=$pkgdir/taz
141 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
142 fs=$pack/fs
143 stuff=$pkgdir/stuff
144 install=$pkgdir/install
145 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
146 lzma_tarball="$pkgsrc.tar.lzma"
147 if [ "$PATCH" ]; then
148 [ "${PTARBALL}" ] || PTARBALL="$(basename $PATCH)"
149 fi
150 if [ "$WANTED" ]; then
151 basesrc=$WOK/$WANTED/source
152 src=$basesrc/$WANTED-$VERSION
153 install=$WOK/$WANTED/install
154 wanted_stuff=$WOK/$WANTED/stuff
155 fi
156 if [ "$SOURCE" ]; then
157 source_stuff=$WOK/$SOURCE/stuff
158 fi
159 # Kernel version is set from linux
160 if [ -f "$WOK/linux/receipt" ]; then
161 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d '"' -f 2)
162 kbasevers=${kvers:0:3}
163 fi
164 # Python version
165 if [ -f "$WOK/python/receipt" ]; then
166 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d '"' -f 2)
167 fi
168 # perl version for some packages needed it
169 if [ -f "$WOK/perl/receipt" ]; then
170 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d '"' -f 2)
171 fi
172 # Old way compatibility.
173 _pkg=$install
174 }
176 # Create source tarball when URL is a SCM.
177 create_tarball() {
178 local tarball
179 tarball=$pkgsrc.tar.bz2
180 [ "$LZMA_SRC" ] && tarball=$lzma_tarball
181 gettext "Creating tarball: "; echo "$tarball"
182 if [ "$LZMA_SRC" ]; then
183 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
184 LZMA_SRC=""
185 else
186 tar cjf $tarball $pkgsrc || exit 1
187 mv $tarball $SRC && rm -rf $pkgsrc
188 fi
189 TARBALL=$tarball
190 }
192 # Get package source. For SCM we are in cache so clone here and create a
193 # tarball here.
194 get_source() {
195 pwd=$(pwd)
196 for file in $@; do
197 gettext "Getting source from url:"; echo " ${file#*|}"
198 if [ "$file" = "$PATCH" -o "$file" = "$orig_url_patch" ]; then
199 SAVE_FILE="$SRC/$PTARBALL"
200 else
201 SAVE_FILE="$SRC/$TARBALL"
202 fi
203 case "$file" in
204 http://*|ftp://*)
205 # Busybox Wget is better!
206 busybox wget $WGET_OPTIONS -T $TIMEOUT -c -O $SAVE_FILE $file || \
207 (echo -e "ERROR: wget $file" && exit 1) ;;
208 https://*)
209 wget $WGET_OPTIONS -T $TIMEOUT -c --no-check-certificate -O $SAVE_FILE $file || \
210 (echo -e "ERROR: wget $file" && exit 1) ;;
211 hg*|mercurial*)
212 if $(echo "$file" | fgrep -q "hg|"); then
213 url=${file#hg|}
214 else
215 url=${file#mercurial|}
216 fi
217 gettext -e "Getting source from Hg...\n"
218 echo "URL: $url"
219 gettext "Cloning to: "; echo "$pwd/$pkgsrc"
220 if [ "$BRANCH" ]; then
221 echo "Hg branch: $BRANCH"
222 hg clone $url --rev $BRANCH $pkgsrc || \
223 (echo "ERROR: hg clone $url --rev $BRANCH" && exit 1)
224 else
225 hg clone $url $pkgsrc || (echo "ERROR: hg clone $url" && exit 1)
226 fi
227 create_tarball ;;
228 git*)
229 url=${file#git|}
230 gettext -e "Getting source from Git...\n"
231 echo "URL: $url"
232 git clone $url $pkgsrc || (echo "ERROR: git clone $url" && exit 1)
233 if [ "$BRANCH" ]; then
234 echo "Git branch: $BRANCH"
235 cd $pkgsrc && git checkout $BRANCH && cd ..
236 fi
237 create_tarball ;;
238 cvs*)
239 url=${file#cvs|}
240 mod=$PACKAGE
241 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
242 gettext -e "Getting source from CVS...\n"
243 echo "URL: $url"
244 [ "$CVS_MODULE" ] && echo "CVS module: $mod"
245 gettext "Cloning to: "; echo "$pwd/$mod"
246 cvs -d:$url co $mod && mv $mod $pkgsrc
247 create_tarball ;;
248 svn*|subversion*)
249 if $(echo "$file" | fgrep -q "svn|"); then
250 url=${file#svn|}
251 else
252 url=${file#subversion|}
253 fi
254 gettext -e "Getting source from SVN...\n"
255 echo "URL: $url"
256 if [ "$BRANCH" ]; then
257 echo t | svn co $url -r $BRANCH $pkgsrc
258 else
259 echo t | svn co $url $pkgsrc
260 fi
261 create_tarball ;;
262 *)
263 gettext -e "\nERROR: Unable to handle:"; echo -e " $file \n" | \
264 tee -a $LOGS/$PACKAGE.log
265 exit 1 ;;
266 esac
267 done
268 }
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 if [ ! "$WANTED" ] && [ "$TARBALL" ]; then
280 [ -d $tmpsrc ] && rm -rf $tmpsrc
281 mkdir -p $tmpsrc && cd $tmpsrc
282 fi
284 if [ "$WGET_URL" ] && [ -f "$SRC/$TARBALL" ]; then
285 if [ "$1" = "--extract" ]; then
286 [ -d $basesrc ] && rm -rf $basesrc
287 mkdir -p $tmpsrc && cd $tmpsrc
288 extract_source
289 extract_path
290 fi
291 [ "$TARBALL" = "$lzma_tarball" ] && LZMA_SRC=""
292 else
293 separator && download
294 fi
296 # This is to make sure if PATCH equals something it will be downloaded
297 # checks are done in download functions
298 if [ "$PATCH" ]; then
299 if [ ! -f "$SRC/$PTARBALL" ]; then
300 separator && download
301 fi
302 fi
304 look_for_cookopt !repack_src && LZMA_SRC=""
305 if [ "$LZMA_SRC" ]; then
306 echo -e "Repacking source."
307 set_paths
308 mkdir -p $tmpsrc && cd $tmpsrc
309 extract_source || exit 1
310 repack_source || exit 1
311 if [ "$1" = "--extract" ]; then
312 extract_path
313 fi
314 if [ -f $SRC/$TARBALL ]; then
315 [ -d $tmpsrc ] && rm -rf $tmpsrc
316 fi
317 fi
319 echo -e "Tarball: $SRC/$TARBALL"
320 [ "$PATCH" ] && echo -e "Patch: $SRC/$PTARBALL"
321 }
323 download_base() {
324 local URLS url alt_url orig_url orig_url_patch
325 url="$ONLINE_SRC_REPOSITORY"
326 if [ "$SOURCE" ]; then
327 alt_url="${url}${SOURCE:0:1}/$SOURCE-${KBASEVER:-$VERSION}.tar.lzma"
328 else
329 alt_url="${url}${PACKAGE:0:1}/$PACKAGE-${KBASEVER:-$VERSION}.tar.lzma"
330 fi
331 orig_url="${url}${TARBALL:0:1}/$TARBALL"
332 [ "$PATCH" ] && orig_url_patch="${url}${PTARBALL:0:1}/$PTARBALL"
333 URLS="$@ $alt_url $orig_url $orig_url_patch"
334 [ "$LAN_MIRROR" ] && URLS="$alt_url $orig_url $orig_url_patch $@"
335 if [ "$WGET_URL" = "$orig_url" ]; then
336 [ "$TARBALL" = "$lzma_tarball" ] && LZMA_SRC=""
337 get_source $@
338 elif [ "$WGET_URL" = "$alt_url" ]; then
339 LZMA_SRC=""
340 get_source $@
341 else
342 for i in $URLS; do
343 if [ "$1" = "$PATCH" ]; then
344 [ ! -f "$SRC/$PTARBALL" ] || continue
345 else
346 [ ! -f "$SRC/$TARBALL" ] || continue
347 fi
348 case $i in
349 ${url}*)
350 [ "$i" = "$alt_url" ] && TARBALL="$(basename $alt_url)"
351 [ "$i" = "$alt_url" ] && LZMA_SRC=""
352 get_source $i
353 ;;
354 *)
355 get_source $i ;;
356 esac
357 done
358 fi
359 }
361 # Get source from multible urls
362 download() {
363 if [ ! -s "$SRC/$TARBALL" ]; then
364 download_base $WGET_URL
365 [ -f "$SRC/$TARBALL" ] || broken
366 fi
368 if [ "$PATCH" ]; then
369 if [ ! -s "$SRC/$PTARBALL" ]; then
370 download_base $PATCH
371 [ -f "$SRC/$PTARBALL" ] || broken
372 fi
373 fi
374 }
376 # Extract source package.
377 extract_source() {
378 gettext "Extracting:"; echo " $TARBALL"
379 case "$TARBALL" in
380 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
381 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
382 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
383 *.tar) tar xf $SRC/$TARBALL ;;
384 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
385 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
386 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
387 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
388 *.deb) ar vx $SRC/$TARBALL
389 [ ! -d $tmpsrc/$PACKAGE-$VERSION ] && mkdir -p $tmpsrc/$PACKAGE-$VERSION
390 cd $tmpsrc/$PACKAGE-$VERSION
391 tar -xvzf $tmpsrc/data.tar.gz
392 [ -f $tmpsrc/data.tar.gz ] && rm -f $tmpsrc/data.tar.gz
393 [ -f $tmpsrc/control.tar.gz ] && rm -f $tmpsrc/control.tar.gz
394 [ -f $tmpsrc/debian-binary ] && rm -f $tmpsrc/debian-binary ;;
395 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
396 *.7z) 7zr x $SRC/$TARBALL ;;
397 *) cp $SRC/$TARBALL $(pwd) ;;
398 esac
399 chown -R 0.0 $(pwd)
400 }
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 ORIG_TARBALL=$TARBALL
415 if [ -d "$tmpsrc/$pkgsrc" ]; then
416 gettext "Repacking source is enabled:"; echo " LZMA_SRC"
417 TARBALL=$lzma_tarball
418 cd $tmpsrc
419 if [ -x /usr/bin/optipng ]; then
420 [ "$SHRINKPNG" ] && find -name "*.png" -type f | xargs -i optipng "{}"
421 fi
422 tar -c * | lzma e $SRC/$TARBALL -si $LZMA_SET_DIR
423 if [ $REMOVE_ORIG_TARBALL ]; then
424 if [ -f $SRC/$TARBALL ]; then
425 [ -f $SRC/$ORIG_TARBALL ] && rm -f $SRC/$ORIG_TARBALL
426 fi
427 fi
428 fi
429 }
431 # Display cooked package summary.
432 summary() {
433 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
434 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
435 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
436 size=$(du -sh $INCOMING/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
437 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
438 [ "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
439 cookdate=$(date "+%Y-%m-%d %H:%M")
440 sec=$time
441 div=$(( ($time + 30) / 60))
442 [ "$div" != 0 ] && min="~ ${div}m"
443 gettext "Summary for:"; echo " $PACKAGE $VERSION"
444 separator
445 [ "$srcdir" ] && echo "Source dir : $srcdir"
446 [ "$TARBALL" ] && echo "Src file : $TARBALL"
447 [ "$srcsize" ] && echo "Src size : $srcsize"
448 [ "$prod" ] && echo "Produced : $prod"
449 cat << EOT
450 Packed : $fs
451 Compressed : $size
452 Files : $files
453 Cook time : ${sec}s $min
454 Cook date : $cookdate
455 Host arch : $ARCH
456 $(separator)
457 EOT
458 }
460 # Display debugging error info.
461 debug_info() {
462 echo -e "\nDebug information"
463 separator
464 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
465 for error in \
466 ERROR "No package" "cp: can't" "can't open" "can't cd" \
467 "error:" "fatal error:" "rm: can't remove" "cp: can't stat"
468 "undefined reference to" "Unable to connect to" \
469 "link: cannot find the library"
470 do
471 fgrep "$error" $LOGS/$pkg.log
472 done
473 separator && newline
474 }
476 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
477 # so some packages need to copy these files with the receipt and genpkg_rules.
478 copy_generic_files()
479 {
480 # $LOCALE is set in cook.conf
481 if [ "$LOCALE" -a "$WANTED" = "" ]; then
482 if [ -d "$install/usr/share/locale" ]; then
483 mkdir -p $fs/usr/share/locale
484 for i in $LOCALE
485 do
486 if [ -d "$install/usr/share/locale/$i" ]; then
487 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
488 fi
489 done
490 fi
491 fi
493 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
494 if [ "$GENERIC_PIXMAPS" != "no" ]; then
495 if [ -d "$install/usr/share/pixmaps" ]; then
496 mkdir -p $fs/usr/share/pixmaps
497 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
498 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
499 $fs/usr/share/pixmaps
500 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
501 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
502 $fs/usr/share/pixmaps
503 fi
504 fi
506 # Custom or homemade PNG pixmap can be in stuff.
507 if [ -f "$stuff/$PACKAGE.png" ]; then
508 mkdir -p $fs/usr/share/pixmaps
509 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
510 fi
511 fi
513 # Desktop entry (.desktop).
514 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
515 if [ "$GENERIC_MENUS" != "no" ]; then
516 if [ -d "$install/usr/share/applications" ] && [ "$WANTED" == "" ]; then
517 mkdir -p $fs/usr/share
518 cp -a $install/usr/share/applications $fs/usr/share
519 fi
520 fi
522 # Homemade desktop file(s) can be in stuff.
523 if [ -d "$stuff/applications" ]; then
524 mkdir -p $fs/usr/share
525 cp -a $stuff/applications $fs/usr/share
526 fi
527 if [ -f "$stuff/$PACKAGE.desktop" ]; then
528 mkdir -p $fs/usr/share/applications
529 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
530 fi
532 # Add custom licenses
533 if [ -d "$stuff/licenses" ]; then
534 mkdir -p $fs/usr/share/licenses
535 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
536 fi
537 }
539 # Find and strip : --strip-all (-s) or --strip-debug on static libs as well
540 # as removing uneeded files like in Python packages. Cross compiled binaries
541 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
542 strip_package()
543 {
544 case "$ARCH" in
545 arm|x86_64) export STRIP=${HOST_SYSTEM}-strip ;;
546 *) export STRIP=strip ;;
547 esac
548 gettext "Executing strip on all files..."
549 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
550 do
551 if [ -d "$dir" ]; then
552 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
553 fi
554 done
555 find $fs -name "*.so*" -exec $STRIP -s '{}' 2>/dev/null \;
556 find $fs -name "*.a" -exec $STRIP --strip-debug '{}' 2>/dev/null \;
557 status
559 # Remove Python .pyc and .pyo from packages.
560 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
561 gettext "Removing Python compiled files..."
562 find $fs -type f -name "*.pyc" -delete 2>/dev/null
563 find $fs -type f -name "*.pyo" -delete 2>/dev/null
564 status
565 fi
567 # Remove Perl perllocal.pod and .packlist from packages.
568 if echo "$DEPENDS" | fgrep -q "perl"; then
569 gettext "Removing Perl compiled files..."
570 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
571 find $fs -type f -name ".packlist" -delete 2>/dev/null
572 status
573 fi
574 }
576 # Remove installed deps.
577 remove_deps() {
578 # Now remove installed build deps.
579 diff="$CACHE/installed.cook.diff"
580 if [ -s "$CACHE/installed.cook.diff" ]; then
581 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
582 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
583 gettext "Build dependencies to remove:"; echo " $nb"
584 gettext "Removing:"
585 for dep in $deps
586 do
587 echo -n " $dep"
588 tazpkg remove $dep --auto --root=/ >/dev/null
589 done
590 echo -e "\n"
591 # Keep the last diff for debug and info.
592 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
593 fi
594 clean_chroot
595 }
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 -l ${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 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
787 look_for_cookopt !unpack && unpack="no"
788 if [ ! "$unpack" ] && [ "$cook_code" = "" ]; then
789 extract_source || exit 1
790 look_for_cookopt !repack_src && LZMA_SRC=""
791 [ "$LZMA_SRC" ] && repack_source
792 extract_path
793 fi
794 fi
796 # Execute receipt rules.
797 if [ $(grep ^compile_rules $receipt) ] && [ "$cook_code" = "" ]; then
798 echo "Executing: compile_rules"
799 echo "CFLAGS : $CFLAGS"
800 #echo "LDFLAGS : $LDFLAGS"
801 [ -d "$src" ] && cd $src
802 compile_rules $@ || broken
803 [ "$cook_code" ] && exit 1
804 # Stay compatible with _pkg
805 [ -d "$src/_pkg" ] && mv $src/_pkg $install
806 # QA: compile_rules success so valid.
807 mkdir -p $install
808 else
809 # QA: No compile_rules so no error, valid.
810 mkdir -p $install
811 fi
812 separator && newline
814 # Execute testsuite.
815 if grep -q ^testsuite $receipt; then
816 echo "Running testsuite"
817 separator
818 testsuite $@ || exit 1
819 separator && newline
820 fi
821 }
823 # Cook quality assurance.
824 cookit_quality() {
825 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
826 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
827 fi
828 # ERROR can be echoed any time in cookit()
829 if fgrep -q ERROR: $LOGS/$pkg.log; then
830 debug_info | tee -a $LOGS/$pkg.log
831 rm -f $command && exit 1
832 fi
833 }
835 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
836 # but it doesn't handle EXTRAVERSION.
837 packit() {
838 set_paths
840 # Handle cross compilation
841 case "$ARCH" in
842 arm|x86_64) arch="-$ARCH" ;;
843 esac
845 echo "Pack: $PACKAGE ${VERSION}${arch}"
846 separator
848 if grep -q ^genpkg_rules $receipt; then
849 gettext -e "Executing: genpkg_rules\n"
850 set -e && cd $pkgdir && mkdir -p $fs
851 genpkg_rules || (broken && echo -e "\nERROR: genpkg_rules failed\n" >> \
852 $LOGS/$pkg.log)
853 else
854 gettext "No packages rules: meta package"; echo
855 mkdir -p $fs
856 fi
858 # First QA check to stop now if genpkg_rules failed.
859 if fgrep -q ERROR: $LOGS/$pkg.log; then
860 broken && exit 1
861 fi
863 cd $taz
864 for file in receipt description.txt
865 do
866 [ ! -f "../$file" ] && continue
867 gettext "Copying"; echo -n " $file..."
868 cp -f ../$file $pack && chown 0.0 $pack/$file && status
869 done
870 copy_generic_files
872 # Create files.list with redirecting find output.
873 gettext "Creating the list of files..." && cd $fs
874 find . -type f -print > ../files.list
875 find . -type l -print >> ../files.list
876 cd .. && sed -i s/'^.'/''/ files.list
877 status
879 # Strip and stuff files.
880 look_for_cookopt !strip && STRIP="n"
881 [ "$STRIP" ] || strip_package
883 # Md5sum of files.
884 gettext "Creating $CHECKSUM of files..."
885 while read file; do
886 [ -L "fs$file" ] && continue
887 [ -f "fs$file" ] || continue
888 case "$file" in
889 /lib/modules/*/modules.*|*.pyc) continue ;;
890 esac
891 $CHECKSUM "fs$file" | sed 's/ fs/ /'
892 done < files.list > "$CHECKSUM"
893 status
894 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
895 description.txt 2> /dev/null | awk \
896 '{ sz=$1 } END { print sz }')
898 if [ "$UPCOOKLIST" ]; then
899 check_so_files
900 fi
902 # Generate md5 of cooking stuff to look for commit later.
903 gen_cookmd5
904 echo -e "\n# md5sum of cooking stuff :" >> receipt
905 cat $WOK/$PACKAGE/md5 | sed 's/^/# /' >> receipt
907 # Build cpio archives.
908 gettext "Compressing the fs... "
909 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si $LZMA_SET_DIR
910 rm -rf fs
911 status
912 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
913 $CHECKSUM description.txt 2> /dev/null | awk \
914 '{ sz=$1 } END { print sz }')
915 gettext "Updating receipt sizes..."
916 sed -i s/^PACKED_SIZE.*$// receipt
917 sed -i s/^UNPACKED_SIZE.*$// receipt
918 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
919 status
921 # Set extra version.
922 if [ "$EXTRAVERSION" ]; then
923 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
924 sed -i s/^EXTRAVERSION.*$// receipt
925 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
926 status
927 fi
929 # Compress.
930 gettext "Creating full cpio archive... "
931 find . -print | cpio -o -H newc --quiet > \
932 ../$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg
933 status
934 gettext "Restoring original package tree... "
935 unlzma -c fs.cpio.lzma | cpio -idm --quiet
936 status
937 rm fs.cpio.lzma && cd ..
939 if [ "$UPCOOKLIST" ]; then
940 check_recook_rdeps
941 fi
943 # QA and give info.
944 tazpkg=$(ls *.tazpkg)
945 packit_quality
946 separator && gettext "Package:"; echo -e " $tazpkg\n"
947 }
949 # Verify package quality and consistency.
950 packit_quality() {
951 #gettext "QA: Checking for broken link..."
952 #link=$(find $fs/usr -type l -follow)
953 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
954 #status
956 # Exit if any error found in log file.
957 if fgrep -q ERROR: $LOGS/$pkg.log; then
958 rm -f $command && exit 1
959 fi
961 gettext "QA: Checking for empty package..."
962 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
963 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
964 echo -e "\nERROR: empty package"
965 rm -f $command && exit 1
966 else
967 # Ls sort by name so the first file is the one we want.
968 old=$(ls $INCOMING/$pkg-[0-9]*.tazpkg 2>/dev/null | head -n 1)
969 status
970 if [ -f "$old" ]; then
971 gettext "Removing old: $(basename $old)"
972 rm -f $old && status
973 fi
974 mv -f $pkgdir/taz/$pkg-*.tazpkg $INCOMING
975 sed -i /^${pkg}$/d $broken
976 fi
977 }
979 # Install package on --install or update the chroot.
980 install_package()
981 {
982 local pkg build
983 case "$ARCH" in
984 arm|x86_64)
985 arch="-${ARCH}"
986 root=$CROSS_TREE/sysroot ;;
987 *)
988 root="/" ;;
989 esac
990 # Install package if requested but skip install if target host doesn't
991 # match build system or it will break the build chroot.
992 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
993 for pkg in $PACKAGE; do
994 if [ -f "$inst" ] && [ "$build" == "$ARCH" ]; then
995 if [ -f "$INCOMING/$pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg" ]; then
996 echo "Updating $ARCH chroot environment..."
997 echo "Updating chroot: $pkg (${VERSION}${EXTRAVERSION}${arch})" | log
998 tazpkg install \
999 $INCOMING/$pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg --root=$root --forced
1000 else
1001 gettext -e "Unable to install package, build has failed.\n\n"
1002 exit 1
1003 fi
1004 fi
1005 done
1007 # Install package if part of the chroot to keep env up-to-date.
1008 if [ -f "${root}$INSTALLED/$pkg/receipt" ]; then
1009 . /etc/slitaz/cook.conf
1010 . $WOK/$pkg/taz/$pkg-*/receipt
1011 echo "Updating $ARCH chroot environment..."
1012 echo "Updating chroot: $pkg (${VERSION}${EXTRAVERSION}${arch})" | log
1013 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg" ]; then
1014 tazpkg install \
1015 $PKGS/$pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg \
1016 --forced --root=$root
1017 elif [ -f "$INCOMING/$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg" ]; then
1018 tazpkg install \
1019 $INCOMING/$pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg \
1020 --forced --root=$root
1021 fi
1022 fi
1025 tac()
1027 sed '1!G;h;$!d' $1
1030 unbuild()
1032 check_root
1033 get_options_list="full list"
1034 get_options
1035 [ -f $unbuild ] && rm -rf $unbuild
1036 LIST="$fullco"
1037 [ -f "$1" ] && LIST="$1"
1038 #[ "$full" ] && LIST=$(ls $WOK)
1039 if [ -f "$1" -a "$full" ]; then
1040 COMMAND=gen-cooklist
1041 gen_cook_list
1042 LIST="$tmp/cooklist"
1043 fi
1044 for pkg in $(cat $LIST | grep -v ^#); do
1045 unset VERSION PACKAGE
1046 [ -f $WOK/$pkg/receipt ] || continue
1047 . $WOK/$pkg/receipt
1048 if [ ! -f $INCOMING/$PACKAGE-${VERSION}*.tazpkg -a ! -f $PKGS/$PACKAGE-${VERSION}*.tazpkg ]; then
1049 echo "$PACKAGE" && echo "$PACKAGE" >> $unbuild
1050 fi
1051 done
1052 unset pkg
1053 [ "$list" ] && cp -a $unbuild $cooklist
1056 # Launch the cook command into a chroot jail protected by aufs.
1057 # The current filesystems are used read-only and updates are
1058 # stored in a separate branch.
1059 try_aufs_chroot() {
1061 base=/dev/shm/aufsmnt$$
1063 # Can we setup the chroot ? Is it already done ?
1064 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1065 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1066 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1067 mkdir ${base}root ${base}rw || return
1069 echo "Setup aufs chroot..."
1071 # Sanity check
1072 for i in / /proc /sys /dev/shm /dev/pts /home ; do
1073 case " $AUFS_MOUNTS " in
1074 *\ $i\ *) ;;
1075 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1076 esac
1077 done
1078 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
1079 mount --bind $mnt ${base}root$mnt
1080 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1081 echo "Aufs mountage failure"
1082 umount ${base}root
1083 rmdir ${base}*
1084 return
1085 fi
1086 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1087 done
1089 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1090 status=$?
1092 echo "Leaving aufs chroot..."
1093 tac ${base}rw/aufs-umount.sh | sh
1094 rm -rf ${base}rw
1095 umount ${base}root
1096 rmdir $base*
1098 # Install package if requested
1099 install_package
1100 exit $status
1103 # Create a XML feed for freshly built package.
1104 gen_rss() {
1105 pubdate=$(date "+%a, %d %b %Y %X")
1106 cat > $FEEDS/$pkg.xml << EOT
1107 <item>
1108 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
1109 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1110 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
1111 <pubDate>$pubdate</pubDate>
1112 <description>$SHORT_DESC</description>
1113 </item>
1114 EOT
1120 # Commands
1123 case "$COMMAND" in
1124 usage|help|-u|-h)
1125 usage ;;
1126 list-wok)
1127 gettext -e "\nList of packages in:"; echo " $WOK"
1128 separator
1129 cd $WOK && ls -1
1130 separator
1131 echo -n "Packages: " && ls | wc -l
1132 newline ;;
1133 activity)
1134 cat $activity ;;
1135 search)
1136 # Just a simple search function, we dont need more actually.
1137 query="$2"
1138 newline
1139 gettext "Search results for:"; echo " $query"
1140 separator
1141 cd $WOK && ls -1 | grep "$query"
1142 separator && newline ;;
1143 setup)
1144 # Setup a build environment
1145 check_root
1146 echo "Cook: setup environment" | log
1147 newline
1148 gettext "Setting up your environment"; newline
1149 separator && cd $SLITAZ
1150 init_db_files
1151 gettext "Checking for packages to install..."; echo
1152 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1153 # ARCH-setup or 'cross check-env' should be used before: cook setup
1154 case "$ARCH" in
1155 arm|x86_64)
1156 if [ ! -x "/usr/bin/cross" ]; then
1157 gettext "ERROR: cross is not installed"; echo
1158 exit 1
1159 fi
1160 gettext "Using config file: /etc/slitaz/cross.conf"; echo
1161 . /etc/slitaz/cross.conf ;;
1162 esac
1163 for pkg in $INSTALL_PKGS; do
1164 if [ "$forced" ]; then
1165 tazpkg -gi $pkg --forced
1166 else
1167 [ -f "$INSTALLED/$pkg/receipt" ] || tazpkg get-install $pkg
1168 fi
1169 done
1170 # chroot list
1171 ls -1 "$INSTALLED" > $CACHE/chroot-pkgs
1172 # Handle --options
1173 case "$2" in
1174 --wok)
1175 hg clone $WOK_URL $WOKHG || exit 1 ;;
1176 --stable)
1177 hg clone $WOK_URL-stable $WOKHG || exit 1 ;;
1178 --undigest)
1179 hg clone $WOK_URL-undigest $WOKHG || exit 1 ;;
1180 --tiny)
1181 hg clone $WOK_URL-tiny $WOKHG || exit 1 ;;
1182 esac
1184 rsync_wok
1186 # SliTaz group and permissions
1187 if ! grep -q ^slitaz /etc/group; then
1188 gettext -e "Adding group: slitaz\n"
1189 addgroup slitaz
1190 fi
1191 gettext -e "Setting permissions for slitaz group...\n"
1192 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1193 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1194 separator
1195 gettext -e "All done, ready to cook packages :-)\n\n" ;;
1196 *-setup)
1197 # Setup for cross compiling.
1198 arch=${1%-setup}
1199 check_root
1200 echo "Cook: setup $arch cross environment" | log
1201 newline
1202 boldify $(gettext "Setting up your $arch cross environment")
1203 separator
1204 init_db_files
1205 sed -i \
1206 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1207 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1208 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1209 /etc/slitaz/cook.conf
1210 case "$arch" in
1211 arm)
1212 sed -i \
1213 -e s'/CFLAGS=.*/CFLAGS="-march=armv6 -O2"/' \
1214 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux-gnueabi/' \
1215 -e s'/xorg-dev/""/' \
1216 /etc/slitaz/cook.conf ;;
1217 x86_64)
1218 sed -i \
1219 -e s'/CFLAGS=.*/CFLAGS=""/' \
1220 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux/' \
1221 /etc/slitaz/cook.conf ;;
1222 esac
1223 . /etc/slitaz/cook.conf
1224 sysroot=$CROSS_TREE/sysroot
1225 tools=/cross/$arch/tools
1226 root=$sysroot
1227 CC=$tools/bin/${HOST_SYSTEM}-gcc
1228 echo "Target arch : $ARCH"
1229 echo "Configure args : $CONFIGURE_ARGS"
1230 echo "Arch sysroot : $sysroot"
1231 echo "Tools prefix : $tools/bin"
1232 # Tell the packages manager where to find packages.
1233 echo "Packages DB : ${root}$DB"
1234 mkdir -p ${root}$INSTALLED
1235 cd ${root}$DB && rm -f *.bak
1236 for list in packages.list packages.desc packages.equiv packages.md5
1237 do
1238 rm -f $list && ln -s $SLITAZ/packages/$list $list
1239 done
1240 # We must have the cross compiled glibc-base installed or default
1241 # i486 package will be used as dep by tazpkg and then break the
1242 # cross environment
1243 if [ ! -f "${root}$INSTALLED/glibc-base/receipt" ]; then
1244 colorize 36 "WARNING: (e)glibc-base is not installed in sysroot"
1245 fi
1246 # Show GCC version or warn if not yet compiled.
1247 if [ -x $CC ]; then
1248 echo "Cross compiler : ${HOST_SYSTEM}-gcc"
1249 else
1250 colorize 36 "C compiler is missing: ${HOST_SYSTEM}-gcc"
1251 echo "Run 'cross compile' to cook a toolchain"
1252 fi
1253 separator && newline ;;
1254 upwok)
1255 case "$2" in
1256 --local)
1257 gettext -e "Updating local chanages in wok-hg to wok...\n"
1258 rsync_wok || exit 1
1259 exit 1 ;;
1260 esac
1262 gettext -e "Updating wok-hg...\n"
1263 if [ -d $WOKHG/.hg ]; then
1264 cd $WOKHG
1265 hg pull -u || exit 1
1266 fi
1267 cd $SLITAZ
1268 rsync_wok || exit 1 ;;
1269 test)
1270 # Test a cook environment.
1271 echo "Cook test: testing the cook environment" | log
1272 [ ! -d "$WOK" ] && exit 1
1273 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1274 cook cooktest ;;
1275 new)
1276 # Create the package folder and an empty receipt.
1277 pkg="$2"
1278 [ "$pkg" ] || usage
1279 newline
1280 if [ -d "$WOKHG/$pkg" ]; then
1281 echo -n "$pkg " && gettext "package already exists."
1282 echo -e "\n" && exit 1
1283 fi
1284 gettext "Creating"; echo -n " $WOKHG/$pkg"
1285 mkdir $WOKHG/$pkg && cd $WOKHG/$pkg && status
1286 gettext "Preparing the package receipt..."
1287 cp $DATA/receipt .
1288 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1289 status && newline
1291 # Interactive mode, asking and seding.
1292 case "$3" in
1293 --interactive|-x)
1294 gettext -e "Entering interactive mode...\n"
1295 separator
1296 echo "Package : $pkg"
1297 # Version.
1298 echo -n "Version : " ; read anser
1299 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
1300 # Category.
1301 echo -n "Category : " ; read anser
1302 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
1303 # Short description.
1304 echo -n "Short desc : " ; read anser
1305 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
1306 # Maintainer.
1307 echo -n "Maintainer : " ; read anser
1308 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
1309 # License.
1310 echo -n "License : " ; read anser
1311 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$anser\""/ receipt
1312 # Web site.
1313 echo -n "Web site : " ; read anser
1314 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
1315 newline
1316 # Wget URL.
1317 echo "Wget URL to download source tarball."
1318 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
1319 echo -n "Wget url : " ; read anser
1320 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
1321 # Ask for a stuff dir.
1322 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
1323 if [ "$anser" = "y" ]; then
1324 echo -n "Creating the stuff directory..."
1325 mkdir -p $WOKHG/$pkg/stuff && status
1326 fi
1327 # Ask for a description file.
1328 echo -n "Are you going to write a description ? (y/N) : " ; read anser
1329 if [ "$anser" = "y" ]; then
1330 echo -n "Creating the description.txt file..."
1331 newline > $WOKHG/$pkg/description.txt && status
1332 fi
1333 separator
1334 gettext -e "Receipt is ready to use.\n"
1335 newline ;;
1336 esac ;;
1337 list)
1338 # Cook a list of packages (better use the Cooker since it will order
1339 # packages before executing cook).
1340 check_root
1341 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
1342 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
1343 echo -e " $2\n" && exit 1
1344 echo "Cook list starting: $2" | log
1345 for pkg in $(cat $2)
1346 do
1347 cook $pkg || broken
1348 done ;;
1349 clean-wok)
1350 check_root
1351 gettext -e "\nCleaning all packages files..."
1352 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1353 status && newline ;;
1354 clean-src)
1355 check_root
1356 gettext -e "\nCleaning all packages sources..."
1357 rm -rf $WOK/*/source
1358 status && newline ;;
1359 gen-cooklist)
1360 check_root
1361 [ -f "$2" ] && LIST="$2"
1362 get_options_list="pkg wok missing"
1363 get_options
1364 if ! [ "$pkg" ]; then
1365 if [ ! "$LIST" ] || [ "$LIST" = "toolchain" ]; then
1366 pkg="$TOOLCHAIN $TOOLCHAIN_EXTRA"
1367 else
1368 check_for_list
1369 fi
1370 fi
1371 gen_cook_list
1372 if [ "$missing" ]; then
1373 cooklist=${LIST:-$cooklist}
1374 for pkgname in $(cat $cooklist)
1375 do
1376 unset EXTRAVERSION
1377 [ -f $wok/$pkgname/receipt ] || continue
1378 . $wok/$pkgname/receipt
1379 if [ -f $INCOMING/$PACKAGE-${VERSION}*.tazpkg -o -f $PKGS/$PACKAGE-${VERSION}*.tazpkg ]; then
1380 if grep "^$pkgname" $cooklist; then
1381 sed -i "s|^$pkgname$||g" $cooklist
1382 sed -i /^$/d $cooklist
1383 fi
1384 fi
1385 done
1386 fi
1388 #rm -f $command
1389 ;;
1390 gen-wok-db)
1391 check_root
1392 #echo "cook:gen-wok-db" > $command
1393 [ -d "$WOKHG" ] && WOK="$WOKHG"
1394 [ "$2" ] && WOK="$2"
1395 gen_wok_db ;;
1396 check-incoming)
1397 check_root
1398 get_options_list="forced"
1399 get_options
1400 echo "cook:check-incoming" > $command
1401 check_for_incoming
1402 rm -f $command ;;
1403 gen-src)
1404 check_root
1405 [ "$2" ] && src_repository="$2"
1406 [ -d "$src_repository" ] || src_repository="$SRC"
1407 gettext -e "Rebulding sources.list file: $src_repository"
1408 gen_sources_list $src_repository
1409 status ;;
1410 maintainers)
1411 check_root
1412 newline
1413 echo "List of maintainers for: $WOK"
1414 separator
1415 tmp="/tmp/slitaz-maintainers"
1416 touch $tmp
1417 for pkg in $WOK/*
1418 do
1419 [ -f $pkg/receipt ] || continue
1420 . $pkg/receipt
1421 if ! fgrep -q "$MAINTAINER" $tmp; then
1422 echo "$MAINTAINER" >> $tmp
1423 echo "$MAINTAINER"
1424 fi
1425 done
1426 separator
1427 echo "Maintainers: `cat $tmp | wc -l`"
1428 newline
1429 # Remove tmp files
1430 [ -f $tmp ] && rm -f $tmp
1431 ;;
1432 tags)
1433 check_root
1434 echo -e "\n\033[1mTags list :\033[0m"
1435 separator
1436 tmp="/tmp/tags"
1437 touch $tmp
1438 for pkg in $WOK/*; do
1439 unset TAGS
1440 [ -f $pkg/receipt ] || continue
1441 source $pkg/receipt
1442 for t in $TAGS; do
1443 grep -q ^$t$ $tmp && continue
1444 echo $t | tee -a $tmp
1445 done
1446 done
1447 separator
1448 echo "$(wc -l $tmp | cut -f1 -d ' ') tags listed."
1449 [ -f $tmp ] && rm -rf $tmp
1450 ;;
1451 maintained-by)
1452 # Search for packages maintained by a contributor.
1453 check_root
1454 if [ ! -n "$2" ]; then
1455 echo "Specify a name or email of a maintainer." >&2
1456 exit 1
1457 fi
1458 echo "Maintainer packages"
1459 separator
1460 for pkg in $WOK/*
1461 do
1462 [ -f $pkg/receipt ] || continue
1463 . $pkg/receipt
1464 if echo "$MAINTAINER" | fgrep -q "$2"; then
1465 echo "$PACKAGE"
1466 packages=$(($packages+1))
1467 fi
1468 done
1469 separator
1470 echo "Packages maintained by $2: $packages"
1471 newline
1472 ;;
1473 check-src)
1474 # Verify if upstream package is still available.
1476 check_root
1477 PACKAGE="$2"
1478 receipt="$WOK/$PACKAGE/receipt"
1479 if [ ! -f $receipt ]; then
1480 gettext -e "\nUnable to find package in the wok:"
1481 echo -e " $PACKAGE\n" && exit 1
1482 fi
1483 unset_receipt
1484 source $receipt
1485 check_src()
1487 for url in $@; do
1488 busybox wget -s $url 2>/dev/null && break
1489 done
1491 if [ "$WGET_URL" ];then
1492 echo -n "$PACKAGE : "
1493 check_src $WGET_URL
1494 status
1495 else
1496 echo "No tarball to check for $PACKAGE"
1497 fi
1498 ;;
1499 unbuild)
1500 unbuild "$2" "$3" ;;
1501 pkgdb)
1502 # Create suitable packages list for TazPKG and only for built packages
1503 # as well as flavors files for TazLiTo. We dont need logs since we do it
1504 # manually to ensure everything is fine before syncing the mirror.
1505 pkgdb "$2"
1506 exit 0 ;;
1507 clean-chroot)
1508 clean_chroot ;;
1509 *)
1510 # Just cook and generate a package.
1511 check_root
1512 time=$(date +%s)
1513 pkg="$1"
1514 [ -z "$pkg" ] && usage
1515 receipt="$WOK/$pkg/receipt"
1516 check_pkg_in_wok && newline
1518 unset inst
1519 unset_receipt
1520 . $receipt
1522 # Handle cross compilation.
1524 # CROSS_NOTE: Actually we are running an ARM cooker but running
1525 # the cooker and build each commit in wok is not possible since
1526 # we dont cook the full wok for this arch. For ARM we need a set
1527 # of packages to handle a touch screen desktop, servers but not
1528 # erland.
1530 # The temporary solution is to build only reviewed and tested
1531 # packages with HOST_ARCH set in receipt.
1532 case "$ARCH" in
1533 arm)
1534 if [ ! "$HOST_ARCH" ]; then
1535 echo "cook: HOST_ARCH is not set in $pkg receipt"
1536 echo "cook: This package is not included in: $ARCH"
1537 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1538 echo "Cook skip: $pkg is not included in: $ARCH" | log
1539 newline && exit 1
1540 fi ;;
1541 esac
1543 # Some packages are not included in some arch or fail to cross compile.
1544 : ${HOST_ARCH=i486}
1545 if ! $(echo "$HOST_ARCH" | fgrep -q $ARCH); then
1546 echo "cook: HOST_ARCH=$HOST_ARCH"
1547 echo "cook: $pkg doesn't cook or is not included in: $ARCH"
1548 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1549 echo "Cook skip: $pkg doesn't cook or is not included in: $ARCH" | log
1550 newline && exit 1
1551 fi
1553 # Skip blocked, 3 lines also for the Cooker.
1554 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1555 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
1556 fi
1558 if [ "$AUFS_MODE" ]; then
1559 try_aufs_chroot "$@"
1560 fi
1562 # Log and source receipt.
1563 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1564 echo "cook:$pkg" > $command
1566 # Display and log info if cook process stopped.
1567 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
1568 tee -a $LOGS/$pkg.log' INT
1570 set_paths
1572 # Handle --options
1573 case "$2" in
1574 --clean|-c)
1575 gettext -e "Cleaning:"; echo -n " $pkg"
1576 cd $WOK/$pkg && rm -rf install taz source
1577 status && newline && exit 0 ;;
1578 --install|-i)
1579 inst='yes' ;;
1580 --noupdate|-nu)
1581 UPCHROOT="" ;;
1582 --nocleanchroot|-ncc)
1583 CLEAN_CHROOT="" ;;
1584 --getsrc|-gs)
1585 getsrc "$3"
1586 exit 0 ;;
1587 --block|-b)
1588 gettext "Blocking:"; echo -n " $pkg"
1589 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1590 status && newline && exit 0 ;;
1591 --unblock|-ub)
1592 gettext "Unblocking:"; echo -n " $pkg"
1593 sed -i "/^${pkg}$/"d $blocked
1594 status && newline && exit 0 ;;
1595 --pack)
1596 if [ -d $WOK/$pkg/taz ]; then
1597 rm -rf $WOK/$pkg/taz
1598 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1599 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1600 clean_log
1601 else
1602 gettext "Need to build $pkg." && exit 0
1603 fi
1604 exit 0 ;;
1605 esac
1607 # Check if wanted is built now so we have separate log files.
1608 if [ "$WANTED" ]; then
1609 if grep -q "^$WANTED$" $blocked; then
1610 echo "WANTED package $PACKAGE is blocked: $WANTED" | tee $LOGS/$pkg.log
1611 newline && rm -f $command && exit 1
1612 fi
1613 if grep -q "^$WANTED$" $broken; then
1614 echo "WANTED package $PACKAGE is broken: $WANTED" | tee $LOGS/$pkg.log
1615 newline && rm -f $command && exit 1
1616 fi
1617 if [ ! "$COOK_WANTED" ]; then
1618 if [ ! -d "$WOK/$WANTED/install" ]; then
1619 cook "$WANTED" || exit 1
1620 fi
1621 fi
1622 fi
1624 if [ "$UPCOOKLIST" ]; then
1625 db_md5=$(md5sum $dep_db $wan_db)
1626 echo "update_wok_db"
1627 update_wan_db
1628 echo "check_for_commit"
1629 check_for_commit
1630 sort -o $dep_db $dep_db
1631 sort -o $wan_db $wan_db
1632 if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
1633 grep -q "^#" $fullco || sed 1i"#PlanSort" -i $fullco
1634 fi
1635 fi
1637 # Cook and pack or exit on error and log everything.
1638 cookit $@ 2>&1 | tee $LOGS/$pkg.log
1639 remove_deps | tee -a $LOGS/$pkg.log
1640 if [ "$CLEAN_CHROOT" ]; then
1641 clean_chroot | tee -a $LOGS/$pkg.log
1642 fi
1643 cookit_quality
1644 packit 2>&1 | tee -a $LOGS/$pkg.log
1645 clean_log
1647 # Exit if any error in packing.
1648 if grep -q ^ERROR $LOGS/$pkg.log; then
1649 debug_info | tee -a $LOGS/$pkg.log
1650 broken
1651 rm -f $command && exit 1
1652 fi
1654 # This is needed cause unset and source receipt again
1655 if [ -f "$SRC/$lzma_tarball" ]; then
1656 TARBALL="$lzma_tarball"
1657 fi
1659 # Create an XML feed
1660 gen_rss
1662 # Time and summary
1663 time=$(($(date +%s) - $time))
1664 summary | tee -a $LOGS/$pkg.log
1665 newline
1667 if [ "$AUTO_PURGE_SRC" ]; then
1668 if [ -f "$SRC/$TARBALL" ]; then
1669 previous_tarball=$(grep ^$PACKAGE:incoming $SRC/sources.list | cut -f2)
1670 if [ -f "$SRC/$previous_tarball" ]; then
1671 sed "/^$PACKAGE:incoming/ s/.*/$PACKAGE:incoming\t$TARBALL/" \
1672 -i $SRC/sources.list
1673 grep -q $'\t'$previous_tarball$ $SRC/sources.list || \
1674 rm -f $SRC/$previous_tarball
1675 else
1676 echo -e "$PACKAGE:incoming\t$TARBALL" >> $SRC/sources.list
1677 fi
1678 fi
1679 fi
1681 # remove source folder if its not used in
1682 # genpkg_rules in all wanted packages
1683 remove_src
1685 install_package
1687 # Regen the cooklist if it was planned and command is not cook.
1688 [ "$regen_cooklist" -a "$UPCOOKLIST" ] && unset regen_cooklist && sort_cooklist
1690 if [ $(grep -l "^$pkg$" $broken) ]; then
1691 sed -i "^$pkg$" $broken
1692 fi
1693 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1694 # You want automation: use the Cooker Build Bot.
1695 rm -f $command ;;
1696 esac
1698 exit 0