cookutils view cook @ rev 479

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