cookutils view cook @ rev 512

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