cookutils view cook @ rev 538

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