cookutils view cook @ rev 517

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