cookutils view cook @ rev 514

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