cookutils view cook @ rev 776

cookiso: clean rootfs before filling it with a packages
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Nov 17 01:23:50 2015 +0200 (2015-11-17)
parents e177315d46eb
children d8daf2802972
line source
1 #!/bin/sh
2 #
3 # Cook - A tool to cook and generate SliTaz packages. Read the README
4 # before adding or modifying any code in cook!
5 #
6 # Copyright (C) SliTaz GNU/Linux - GNU gpl v3
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
10 . /usr/lib/slitaz/libcook.sh
12 VERSION="3.2"
15 # Internationalization.
17 export TEXTDOMAIN='cook'
18 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
19 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
20 _p() {
21 local S="$1" P="$2" N="$3"; shift; shift; shift;
22 printf "$(ngettext "$S" "$P" "$N")" "$@"; }
25 #
26 # Functions
27 #
29 usage() {
30 cat <<EOT
32 $(boldify "$(_ 'Usage:')") $(_ 'cook [package|command] [list|--option]')
34 $(boldify "$(_ 'Commands:')")
35 usage|help $(_ 'Display this short usage.')
36 setup $(_ 'Setup your build environment.')
37 *-setup $(_ 'Setup a cross environment.')
38 * = {arm|armv6hf|armv7|x86_64}
39 test $(_ 'Test environment and cook a package.')
40 list-wok $(_ 'List packages in the wok.')
41 search $(_ 'Simple packages search function.')
42 new $(_ 'Create a new package with a receipt.')
43 list $(_ 'Cook a list of packages.')
44 clean-wok $(_ 'Clean-up all packages files.')
45 clean-src $(_ 'Clean-up all packages sources.')
46 uncook $(_ 'Check for uncooked packages')
47 pkgdb $(_ 'Create packages DB lists and flavors.')
49 $(boldify "$(_ 'Options:')")
50 cook <pkg>
51 --clean -c $(_ 'clean the package in the wok.')
52 --install -i $(_ 'cook and install the package.')
53 --getsrc -gs $(_ 'get the package source tarball.')
54 --block -b $(_ 'block a package so cook will skip it.')
55 --unblock -ub $(_ 'unblock a blocked package.')
56 --cdeps $(_ 'check dependencies of cooked package.')
57 --pack $(_ 'repack an already built package.')
58 --debug $(_ 'display debugging messages.')
59 --continue $(_ 'continue running compile_rules.')
60 cook new <pkg>
61 --interactive -x $(_ 'create a receipt interactively.')
62 cook setup
63 --wok $(_ 'clone the cooking wok from Hg repo.')
64 --stable $(_ 'clone the stable wok from Hg repo.')
65 --undigest $(_ 'clone the undigest wok from Hg repo.')
66 --tiny $(_ 'clone the tiny SliTaz wok from Hg repo.')
67 --forced $(_ 'force reinstall of chroot packages.')
68 cook pkgdb
69 --flavors $(_ 'create up-to-date flavors files.')
71 EOT
72 exit 0
73 }
76 # We don't want these escapes in web interface.
78 clean_log() {
79 sed -i -e s'|\[70G\[ \[1;32m| |' \
80 -e s'|\[0;39m \]||' $LOGS/$pkg.log
81 }
84 # Be sure package exists in wok.
86 check_pkg_in_wok() {
87 if [ ! -d "$WOK/$pkg" ]; then
88 newline; _ 'Unable to find package "%s" in the wok' "$pkg"; newline
89 exit 1
90 fi
91 }
94 if_empty_value() {
95 if [ -z "$value" ]; then
96 # L10n: QA is quality assurance
97 _ 'QA: empty variable: %s' "$var=\"\""; newline
98 exit 1
99 fi
100 }
103 # Initialize files used in $CACHE
105 init_db_files() {
106 _ 'Creating directories structure in "%s"' "$SLITAZ"
107 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
108 _ 'Creating DB files in "%s"' "$CACHE"
109 for f in $activity $command $broken $blocked; do
110 touch $f
111 done
112 }
115 # QA: check a receipt consistency before building.
117 receipt_quality() {
118 _ 'QA: checking package receipt...'
119 unset online
120 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
121 online='online'
122 fi
123 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE; do
124 unset value
125 value="$(. $receipt; eval echo \$$var)"
126 case "$var" in
127 PACKAGE|VERSION|SHORT_DESC)
128 if_empty_value ;;
129 CATEGORY)
130 value="${value:-empty}"
131 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
132 if ! echo " $valid " | grep -q " $value "; then
133 _ 'QA: unknown category "%s"' "$value"
134 longline "$(_ 'Please, use one of: %s' "$valid")"
135 newline
136 exit 1
137 fi ;;
138 WEB_SITE)
139 # We don't check WGET_URL since if dl is needed it will fail.
140 # Break also if we're not online. Here error is not fatal.
141 if_empty_value
142 [ -z "$online" ] && break
143 if ! busybox wget -T 12 -s $value 2>/dev/null; then
144 _ 'QA: unable to reach "%s"' "$value"
145 fi ;;
146 esac
147 done
148 }
151 # Paths used in receipt and by cook itself.
153 set_paths() {
154 pkgdir="$WOK/$PACKAGE"
155 basesrc="$pkgdir/source"
156 tmpsrc="$basesrc/tmp"
157 src="$basesrc/$PACKAGE-$VERSION"
158 taz="$pkgdir/taz"
159 pack="$taz/$PACKAGE-$VERSION$EXTRAVERSION"
160 fs="$pack/fs"
161 stuff="$pkgdir/stuff"
162 install="$pkgdir/install"
163 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
164 lzma_tarball="$pkgsrc.tar.lzma"
165 if [ -n "$PATCH" ]; then
166 [ -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
167 fi
168 if [ -n "$WANTED" ]; then
169 basesrc="$WOK/$WANTED/source"
170 src="$basesrc/$WANTED-$VERSION"
171 install="$WOK/$WANTED/install"
172 wanted_stuff="$WOK/$WANTED/stuff"
173 fi
174 if [ -n "$SOURCE" ]; then
175 source_stuff="$WOK/$SOURCE/stuff"
176 fi
177 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
178 if [ -f "$WOK/linux/receipt" ]; then
179 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d\" -f2)
180 kbasevers=${kvers:0:3}
181 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
182 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d\" -f2)
183 kbasevers=${kvers:0:3}
184 fi
185 # Python version
186 if [ -f "$WOK/python/receipt" ]; then
187 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d\" -f2)
188 fi
189 # Perl version for some packages needed it
190 if [ -f "$WOK/perl/receipt" ]; then
191 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d\" -f2)
192 fi
193 # Old way compatibility.
194 _pkg="$install"
195 }
198 # Create source tarball when URL is a SCM.
200 create_tarball() {
201 local tarball
202 tarball="$pkgsrc.tar.bz2"
203 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
204 _ 'Creating tarball "%s"' "$tarball"
205 if [ -n "$LZMA_SRC" ]; then
206 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
207 LZMA_SRC=''
208 else
209 tar -cjf $tarball $pkgsrc || exit 1
210 mv $tarball $SRC; rm -rf $pkgsrc
211 fi
212 TARBALL="$tarball"
213 }
216 # Get package source. For SCM we are in cache so clone here and create a
217 # tarball here.
219 get_source() {
220 local url
221 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
222 set_paths
223 pwd=$(pwd)
224 case "$WGET_URL" in
225 http://*|ftp://*)
226 # Busybox Wget is better!
227 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
228 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
229 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
231 https://*)
232 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
233 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
234 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
236 hg*|mercurial*)
237 if $(echo "$WGET_URL" | fgrep -q 'hg|'); then
238 url=${WGET_URL#hg|}
239 else
240 url=${WGET_URL#mercurial|}
241 fi
242 _ 'Getting source from %s...' 'Hg'
243 _ 'URL: %s' "$url"
244 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
245 if [ -n "$BRANCH" ]; then
246 _ 'Hg branch: %s' "$BRANCH"
247 hg clone $url --rev $BRANCH $pkgsrc || \
248 (_ 'ERROR: %s' "hg clone $url --rev $BRANCH" && exit 1)
249 else
250 hg clone $url $pkgsrc || (_ 'ERROR: %s' "hg clone $url" && exit 1)
251 fi
252 rm -rf $pkgsrc/.hg
253 create_tarball ;;
255 git*)
256 url=${WGET_URL#git|}
257 _ 'Getting source from %s...' 'Git'
258 _ 'URL: %s' "$url"
259 cd $SRC
260 git clone $url $pkgsrc || (_ 'ERROR: %s' "git clone $url" && exit 1)
261 if [ -n "$BRANCH" ]; then
262 _ 'Git branch: %s' "$BRANCH"
263 cd $pkgsrc; git checkout $BRANCH; cd ..
264 fi
265 cd $SRC
266 create_tarball ;;
268 cvs*)
269 url=${WGET_URL#cvs|}
270 mod=$PACKAGE
271 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
272 _ 'Getting source from %s...' 'CVS'
273 _ 'URL: %s' "$url"
274 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
275 _ 'Cloning to "%s"' "$pwd/$mod"
276 cvs -d:$url co $mod && mv $mod $pkgsrc
277 create_tarball ;;
279 svn*|subversion*)
280 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
281 url=${WGET_URL#svn|}
282 else
283 url=${WGET_URL#subversion|}
284 fi
285 _ 'Getting source from %s...' 'SVN'
286 _ 'URL: %s' "$url"
287 if [ -n "$BRANCH" ]; then
288 echo t | svn co $url -r $BRANCH $pkgsrc
289 else
290 echo t | svn co $url $pkgsrc
291 fi
292 create_tarball ;;
294 bzr*)
295 url=${WGET_URL#bzr|}
296 _ 'Getting source from %s...' 'bazaar'
297 cd $SRC
298 pkgsrc=${url#*:}
299 if [ -n "$BRANCH" ]; then
300 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
301 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
302 else
303 echo "bzr -Ossl.cert_reqs=none branch $url"
304 bzr -Ossl.cert_reqs=none branch $url
305 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
306 _ "Don't forget to add to receipt:"
307 echo -e "BRANCH=\"$BRANCH\"\n"
308 fi
309 mv $pkgsrc $pkgsrc-$BRANCH
310 pkgsrc="$pkgsrc-$BRANCH"
311 create_tarball ;;
313 *)
314 (newline; _ 'ERROR: Unable to handle "%s"' "$WGET_URL"; newline) | \
315 tee -a $LOGS/$PACKAGE.log
316 exit 1 ;;
317 esac
318 }
321 # Extract source package.
323 extract_source() {
324 if [ ! -s "$SRC/$TARBALL" ]; then
325 local url
326 url="$MIRROR_URL/sources/packages"
327 url="$url/${TARBALL:0:1}/$TARBALL"
328 _ 'Getting source from %s...' 'mirror'
329 _ 'URL: %s' "$url"
330 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
331 fi
332 _ 'Extracting source archive "%s"' "$TARBALL"
333 case "$TARBALL" in
334 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
335 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
336 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
337 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
338 *.tar) tar -xf $SRC/$TARBALL ;;
339 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
340 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
341 tar -xf $SRC/$TARBALL 2>/dev/null;;
342 *.7z) 7zr x $SRC/$TARBALL ;;
343 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
344 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
345 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
346 *) cp $SRC/$TARBALL $(pwd) ;;
347 esac
348 }
351 # Display cooked package summary.
353 summary() {
354 cd $WOK/$pkg
355 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
356 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
357 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
358 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
359 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
360 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
362 sec="$time"
363 div=$(( ($time + 30) / 60))
364 case $div in
365 0) min='';;
366 # L10n: 'm' is for minutes (approximate cooking time)
367 *) min=$(_n '~ %dm' "$div");;
368 esac
370 _ 'Summary for: %s' "$PACKAGE $VERSION"
371 separator
373 # L10n: keep the same width of translations to get a consistent view
374 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
375 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
376 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
377 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
378 _ 'Packed : %s' "$fs"
379 _ 'Compressed : %s' "$size"
380 _ 'Files : %s' "$files"
381 # L10n: 's' is for seconds (cooking time)
382 _ 'Cook time : %ds %s' "$sec" "$min"
383 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
384 _ 'Host arch : %s' "$ARCH"
385 separator
386 }
389 # Display debugging error info.
391 debug_info() {
392 newline; _ 'Debug information'; separator
393 # L10n: specify your format of date and time (to help: man date)
394 # L10n: not bad one is '+%x %R'
395 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
396 [ "$time" ] && _ 'Cook time: %ds' "$(($(date +%s) - $time))"
397 # L10n: Please, translate all messages beginning with ERROR in a same way
398 lerror=$(_n 'ERROR')
399 for error in \
400 ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
401 'error:' 'fatal error:' 'undefined reference to' \
402 'Unable to connect to' 'link: cannot find the library' \
403 'CMake Error' ': No such file or directory'
404 do
405 fgrep "$error" $LOGS/$pkg.log
406 done > $LOGS/$pkg.log.debug_info 2>&1
407 cat $LOGS/$pkg.log.debug_info
408 rm -f $LOGS/$pkg.log.debug_info
409 separator; newline
410 }
413 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
414 # so some packages need to copy these files with the receipt and genpkg_rules.
416 copy_generic_files() {
417 # $LOCALE is set in cook.conf
418 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
419 if [ -d "$install/usr/share/locale" ]; then
420 mkdir -p $fs/usr/share/locale
421 for i in $LOCALE; do
422 if [ -d "$install/usr/share/locale/$i" ]; then
423 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
424 fi
425 done
426 fi
427 fi
429 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
430 if [ "$GENERIC_PIXMAPS" != 'no' ]; then
431 if [ -d "$install/usr/share/pixmaps" ]; then
432 mkdir -p $fs/usr/share/pixmaps
433 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
434 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
435 $fs/usr/share/pixmaps
436 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
437 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
438 $fs/usr/share/pixmaps
439 fi
440 fi
442 # Custom or homemade PNG pixmap can be in stuff.
443 if [ -f "$stuff/$PACKAGE.png" ]; then
444 mkdir -p $fs/usr/share/pixmaps
445 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
446 fi
447 fi
449 # Desktop entry (.desktop).
450 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
451 if [ "$GENERIC_MENUS" != 'no' ]; then
452 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
453 mkdir -p $fs/usr/share
454 cp -a $install/usr/share/applications $fs/usr/share
455 fi
456 fi
458 # Homemade desktop file(s) can be in stuff.
459 if [ -d "$stuff/applications" ]; then
460 mkdir -p $fs/usr/share
461 cp -a $stuff/applications $fs/usr/share
462 fi
463 if [ -f "$stuff/$PACKAGE.desktop" ]; then
464 mkdir -p $fs/usr/share/applications
465 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
466 fi
468 # Add custom licenses
469 if [ -d "$stuff/licenses" ]; then
470 mkdir -p $fs/usr/share/licenses
471 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
472 fi
473 }
476 # Fix common errors and warnings in the .desktop files
478 fix_desktop_files() {
479 [ -d "$install/usr/share/applications" ] || return
481 if [ -n "$QA" -a -z "$(which desktop-file-validate)" ]; then
482 _n 'Installing dep (web/cache): %s' 'desktop-file-utils-extra'
483 tazpkg -gi desktop-file-utils-extra >/dev/null
484 status
485 fi
487 for desktop in $(find $install/usr/share/applications -name '*.desktop'); do
488 cp "$desktop" "$desktop.orig"
490 # Sort out .desktop file (is prerequisite to correct working of `fix-desktop-file`)
491 sdft "$desktop" -i
493 # Fix common errors in .desktop file
494 fix-desktop-file "$desktop"
496 if [ -n "$QA" ]; then
497 # Check the rest of errors, warnings and tips
498 _ 'QA: Checking %s...' "$(basename $desktop)"
499 diff "$desktop.orig" "$desktop"
500 desktop-file-validate "$desktop"
501 echo
502 fi
504 rm "$desktop.orig"
505 done
506 }
509 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
510 # as removing unneeded files like in Python packages. Cross compiled binaries
511 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
513 strip_package() {
514 case "$ARCH" in
515 arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
516 *) export STRIP='strip' ;;
517 esac
518 _n 'Executing strip on all files...'
519 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
520 if [ -d "$dir" ]; then
521 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
522 fi
523 done
524 find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
525 find $fs -name '*.a' -exec $STRIP --strip-debug '{}' 2>/dev/null \;
526 status
528 # Remove Python .pyc and .pyo from packages.
529 #_n 'Removing Python compiled files...'
530 find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
531 #status
533 # Remove Perl perllocal.pod and .packlist from packages.
534 #_n 'Removing Perl compiled files...'
535 find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \) -delete 2>/dev/null
536 #status
537 }
540 # Update installed.cook.diff
542 update_installed_cook_diff() {
543 # If a cook failed deps are removed.
544 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
545 cd $CACHE
546 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
547 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
548 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
549 }
552 # Remove installed deps.
554 remove_deps() {
555 # Now remove installed build deps.
556 diff='/tmp/installed.cook.diff'
557 if [ -s $diff ]; then
558 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
559 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
560 _n 'Build dependencies to remove:'; echo " $nb"
561 [ -n "$root" ] && echo "root=\"$root\""
562 _n 'Removing:'
563 for dep in $deps; do
564 echo -n " $dep"
565 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
566 done
567 newline; newline
568 # Keep the last diff for debug and info.
569 mv -f $diff $CACHE/installed.diff
570 fi
571 }
574 # The main cook function.
576 cookit() {
577 _ 'Cook: %s' "$PACKAGE $VERSION"; separator
578 set_paths
580 # Handle cross-tools.
581 case "$ARCH" in
582 arm*|x86_64)
583 # CROSS_COMPILE is used by at least Busybox and the kernel to set
584 # the cross-tools prefix. Sysroot is the root of our target arch
585 sysroot="$CROSS_TREE/sysroot"
586 tools="$CROSS_TREE/tools"
587 # Set root path when cross compiling. ARM tested but not x86_64
588 # When cross compiling we must install build deps in $sysroot.
589 arch="-$ARCH"
590 root="$sysroot"
591 _ '%s sysroot: %s' "$ARCH" "$sysroot"
592 _ 'Adding "%s" to PATH' "$tools/bin"
593 export PATH="$PATH:$tools/bin"
594 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
595 export CROSS_COMPILE="$HOST_SYSTEM-"
596 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
597 if [ "$ARCH" == 'x86_64' ]; then
598 export CC="$HOST_SYSTEM-gcc -m64"
599 export CXX="$HOST_SYSTEM-g++ -m64"
600 else
601 export CC="$HOST_SYSTEM-gcc"
602 export CXX="$HOST_SYSTEM-g++"
603 fi
604 export AR="$HOST_SYSTEM-ar"
605 export AS="$HOST_SYSTEM-as"
606 export RANLIB="$HOST_SYSTEM-ranlib"
607 export LD="$HOST_SYSTEM-ld"
608 export STRIP="$HOST_SYSTEM-strip"
609 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
610 esac
612 [ -n "$QA" ] && receipt_quality
613 cd $pkgdir
614 [ -z "$continue" ] && rm -rf source 2>/dev/null
615 rm -rf install taz 2>/dev/null
617 # Disable -pipe if less than 512Mb free RAM.
618 free=$(free | awk '/buffers:/{print $4}')
619 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
620 _ 'Disabling -pipe compile flag: %d RAM free' "$free"
621 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
622 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
623 fi
624 unset free
626 # Export flags and path to be used by make and receipt.
627 DESTDIR="$pkgdir/install"
628 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
629 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
630 #LDFLAGS
632 # Check for build deps and handle implicit depends of *-dev packages
633 # (ex: libusb-dev :: libusb).
634 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
635 touch $CACHE/installed.local $CACHE/installed.web
636 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
637 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
638 for dep in $BUILD_DEPENDS; do
639 implicit="${dep%-dev}"
640 for i in $dep $implicit; do
641 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
642 # Try local package first. In some cases implicit doesn't exist, ex:
643 # libboost-dev exists but not libboost, so check if we got vers.
644 unset vers
645 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
646 # We may have a local package.
647 if [ -z "$vers" ]; then
648 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info)
649 fi
650 debug "bdep: $i version: $vers"
651 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
652 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
653 else
654 # Priority to package version in wok (maybe more up-to-date)
655 # than the mirrored one.
656 if [ -n "$vers" ]; then
657 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
658 echo $i >> $CACHE/installed.web
659 else
660 # So package exists in wok but not available.
661 _ 'Missing dep (wok/pkg): %s' "$i $vers"
662 echo $i >> $CACHE/missing.dep
663 fi
664 else
665 # Package is not in wok but may be in online repo.
666 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
667 echo $i >> $CACHE/installed.web
668 else
669 _ 'ERROR: unknown dep "%s"' "$i"
670 exit 1
671 fi
672 fi
673 fi
674 fi
675 done
676 done
678 # Get the list of installed packages
679 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
681 # Have we a missing build dep to cook?
682 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
683 _ 'Auto cook config is set: %s' "$AUTO_COOK"
684 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
685 for i in $(uniq $CACHE/missing.dep); do
686 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
687 tee -a $LOGS/$PACKAGE.log.$$
688 # programmers: next two messages are exact copy from remove_deps()
689 togrep1=$(_n 'Build dependencies to remove:')
690 togrep2=$(_n 'Removing:')
691 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
692 fgrep $togrep1 $LOGS/$i.log && \
693 fgrep $togrep2 $LOGS/$i.log && newline) | \
694 tee -a $LOGS/$PACKAGE.log.$$ && break
695 done
696 rm -f $CACHE/missing.dep
697 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
698 fi
700 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
701 # is enabled and cook fails we have ERROR in log, if no auto cook we have
702 # missing dep in cached file.
703 lerror=$(_n 'ERROR')
704 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
705 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
706 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
707 exit 1
708 fi
710 # Install local packages: package-version$arch
711 cd $PKGS
712 for i in $(uniq $CACHE/installed.local); do
713 _ 'Installing dep (pkg/local): %s' "$i"
714 tazpkg install $i --root=$root >/dev/null 2>/dev/null
715 done
717 # Install web or cached packages (if mirror is set to $PKGS we only
718 # use local packages).
719 for i in $(uniq $CACHE/installed.web); do
720 _ 'Installing dep (web/cache): %s' "$i"
721 tazpkg get-install $i --root=$root >/dev/null 2>/dev/null
722 done
724 update_installed_cook_diff
726 # Get source tarball and make sure we have source dir named:
727 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
728 # tarball if it exists.
729 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
730 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
731 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
732 LZMA_SRC=''
733 else
734 get_source || exit 1
735 fi
736 fi
737 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
738 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
739 if ! extract_source ; then
740 get_source
741 extract_source || exit 1
742 fi
743 if [ -n "$LZMA_SRC" ]; then
744 cd $pkgdir/source
745 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
746 mv tmp tmp-1; mkdir tmp
747 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
748 fi
749 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
750 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
751 fi
752 fi
753 cd $pkgdir/source/tmp
754 # Some archives are not well done and don't extract to one dir (ex lzma).
755 files=$(ls | wc -l)
756 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
757 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
758 mv * ../$PACKAGE-$VERSION/$TARBALL
759 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
760 mv * ../$PACKAGE-$VERSION
761 cd ..; rm -rf tmp
762 fi
764 # Libtool shared libs path hack.
765 case "$ARCH" in
766 arm*) cross libhack ;;
767 esac
769 # Execute receipt rules.
770 if grep -q ^compile_rules $receipt; then
771 _ 'Executing: %s' 'compile_rules'
772 echo "CFLAGS : $CFLAGS"
773 #echo "LDFLAGS : $LDFLAGS"
774 [ -d "$src" ] && cd $src
775 compile_rules $@ || exit 1
776 # Stay compatible with _pkg
777 [ -d "$src/_pkg" ] && mv $src/_pkg $install
778 # QA: compile_rules success so valid.
779 mkdir -p $install
780 else
781 # QA: no compile_rules so no error, valid.
782 mkdir -p $install
783 fi
784 separator; newline
786 # Execute testsuite.
787 if grep -q ^testsuite $receipt; then
788 _ 'Running testsuite'; separator
789 testsuite $@ || exit 1
790 separator; newline
791 fi
793 fix_desktop_files
794 update_installed_cook_diff force
795 }
798 # Cook quality assurance.
800 cookit_quality() {
801 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
802 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
803 fi
804 # ERROR can be echoed any time in cookit()
805 lerror=$(_n 'ERROR')
806 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
807 grep -Eq "(^$lerror|undefined reference to)" ; then
808 debug_info | tee -a $LOGS/$pkg.log
809 rm -f $command
810 exit 1
811 fi
812 }
815 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
816 # but it doesn't handle EXTRAVERSION.
818 packit() {
819 set_paths
821 # Handle cross compilation
822 case "$ARCH" in
823 arm*|x86_64) arch="-$ARCH" ;;
824 esac
826 _ 'Pack: %s' "$PACKAGE $VERSION$arch"; separator
828 if grep -q ^genpkg_rules $receipt; then
829 _ 'Executing: %s' 'genpkg_rules'
830 set -e; cd $pkgdir; mkdir -p $fs
831 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
832 $LOGS/$pkg.log
833 else
834 _ 'No packages rules: meta package'
835 mkdir -p $fs
836 fi
838 # First QA check to stop now if genpkg_rules failed.
839 lerror=$(_n 'ERROR')
840 if fgrep -q ^$lerror $LOGS/$pkg.log; then
841 exit 1
842 fi
844 cd $taz
845 for file in receipt description.txt; do
846 [ ! -f "../$file" ] && continue
847 _n 'Copying "%s"...' "$file"
848 cp -f ../$file $pack; chown 0.0 $pack/$file; status
849 done
850 copy_generic_files
852 # Strip and stuff files.
853 strip_package
855 # Create files.list with redirecting find output.
856 _n 'Creating the list of files...'
857 cd $fs
858 find . -type f -print > ../files.list
859 find . -type l -print >> ../files.list
860 cd ..; sed -i s/'^.'/''/ files.list
861 status
863 # Md5sum of files.
864 _n 'Creating md5sum 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 md5sum "fs$file" | sed 's/ fs/ /'
872 done < files.list > md5sum
873 status
875 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
876 2>/dev/null | awk 'END{ print $1 }')
878 # Build cpio archives.
879 _n 'Compressing the FS...'
880 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
881 rm -rf fs
882 status
884 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
885 2>/dev/null | awk 'END{ print $1 }')
887 _n 'Updating receipt sizes...'
888 sed -i s/^PACKED_SIZE.*$// receipt
889 sed -i s/^UNPACKED_SIZE.*$// receipt
890 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
891 status
893 # Set extra version.
894 if [ -n "$EXTRAVERSION" ]; then
895 _n 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
896 sed -i s/^EXTRAVERSION.*$// receipt
897 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
898 status
899 fi
901 # Compress.
902 _n 'Creating full cpio archive...'
903 find . -print | cpio -o -H newc --quiet > \
904 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
905 status
907 _n 'Restoring original package tree...'
908 unlzma -c fs.cpio.lzma | cpio -idm --quiet
909 status
911 rm fs.cpio.lzma; cd ..
913 # QA and give info.
914 tazpkg=$(ls *.tazpkg)
915 packit_quality
916 separator; _ 'Package "%s" created' "$tazpkg"; newline
917 }
920 # Verify package quality and consistency.
922 packit_quality() {
923 #gettext "QA: checking for broken link..."
924 #link=$(find $fs/usr -type l -follow)
925 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
926 #status
928 # Exit if any error found in log file.
929 lerror=$(_n 'ERROR')
930 if fgrep -q ^$lerror $LOGS/$pkg.log; then
931 rm -f $command
932 exit 1
933 fi
935 _n 'QA: checking for empty package...'
936 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
937 if [ "$files" == 0 ] && [ "$CATEGORY" != 'meta' ]; then
938 newline; _ 'ERROR: empty package'
939 rm -f $command
940 exit 1
941 else
942 # Ls sort by name so the first file is the one we want.
943 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n1)
944 status
945 if [ -f "$old" ]; then
946 _n 'Removing old package "%s"' "$(basename $old)"
947 rm -f $old; status
948 fi
949 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
950 sed -i /^${pkg}$/d $broken
951 #gettext "Removing source tree..."
952 #rm -f $WOK/$pkg/source && status
953 fi
954 }
957 # Reverse "cat" command: prints input lines in the reverse order
959 tac() {
960 sed '1!G;h;$!d' $1
961 }
964 # Install package on --install or update the chroot.
966 install_package() {
967 case "$ARCH" in
968 arm*|x86_64)
969 arch="-$ARCH"
970 root="$CROSS_TREE/sysroot" ;;
971 esac
972 # Install package if requested but skip install if target host doesn't
973 # match build system or it will break the build chroot.
974 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
975 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
976 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
977 cd $PKGS
978 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
979 else
980 _ 'Unable to install package, build has failed.'; newline
981 exit 1
982 fi
983 fi
985 # Install package if part of the chroot to keep env up-to-date.
986 if [ -d "$root$INSTALLED/$pkg" ]; then
987 . /etc/slitaz/cook.conf
988 . $WOK/$pkg/taz/$pkg-*/receipt
989 _ 'Updating %s chroot environment...' "$ARCH"
990 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
991 cd $PKGS
992 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
993 fi
994 }
997 # remove chroot jail
999 umount_aufs() {
1000 tac ${1}rw/aufs-umount.sh | sh
1001 rm -rf ${1}rw
1002 umount ${1}root
1003 rmdir ${1}r*
1007 # Launch the cook command into a chroot jail protected by aufs.
1008 # The current filesystems are used read-only and updates are
1009 # stored in a separate branch.
1011 try_aufs_chroot() {
1013 base="/dev/shm/aufsmnt$$"
1015 # Can we setup the chroot? Is it already done?
1016 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1017 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1018 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1019 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1020 mkdir ${base}root ${base}rw || return
1022 _ 'Setup aufs chroot...'
1024 # Sanity check
1025 for i in / /proc /sys /dev/shm /home ; do
1026 case " $AUFS_MOUNTS " in
1027 *\ $i\ *) ;;
1028 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1029 esac
1030 done
1031 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1032 mount --bind $mnt ${base}root$mnt
1033 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1034 _ 'Aufs mount failure'
1035 umount ${base}root
1036 rm -rf ${base}r*
1037 return
1038 fi
1039 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1040 done
1041 trap "umount_aufs ${base}" INT
1043 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1044 status=$?
1046 _ 'Leaving aufs chroot...'
1047 umount_aufs $base
1048 # Install package outside the aufs jail
1049 install_package
1050 exit $status
1054 # Encode predefined XML entities
1056 xml_ent() {
1057 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1061 # Create a XML feed for freshly built packages.
1063 gen_rss() {
1064 pubdate=$(date '+%a, %d %b %Y %X')
1065 cat > $FEEDS/$pkg.xml <<EOT
1066 <item>
1067 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1068 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1069 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1070 <pubDate>$pubdate</pubDate>
1071 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1072 </item>
1073 EOT
1077 # Truncate stdout log file to $1 Mb.
1079 loglimit() {
1080 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1081 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1082 else
1083 tee /dev/stderr
1084 fi
1088 # Search file in mirrored packages
1090 search_file_mirror() {
1091 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1095 # Search file in local wok packages
1097 search_file_local() {
1098 # existing packages have precedence over the package/taz folder
1099 srch=$1
1100 { for package in $(find $PKGS -name '*.tazpkg'); do
1101 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1102 grep /$srch\$)" ]; then
1103 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1104 fi
1105 done } | sort -u
1109 # Ask in multiple choice
1111 ask_multiple() {
1112 local multiples first my_choice
1113 multiples="$1"
1114 first=$(echo "$multiples" | head -n1)
1115 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1116 _ 'Select one [%s]: ' "$first"; read my_choice
1117 found="${my_choice:-$first}"
1121 # Search file in local cache (fast), local wok packages, mirrored packages
1123 search_file() {
1124 local srch cache missing
1125 srch="$1"
1126 cache='/var/cache/ldsearch.cache'
1127 missing='/var/cache/missing.file'
1128 touch $cache $missing
1129 found=$(grep $srch $cache | cut -d$'\t' -f2)
1130 if [ -z "$found" ]; then
1131 found=$(search_file_local $srch)
1132 if [ -n "$found" ]; then
1133 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1134 ask_multiple "$found"
1135 fi
1136 echo -e "$srch\t$found" >> $cache
1137 else
1138 found=$(search_file_mirror $srch)
1139 if [ -n "$found" ]; then
1140 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1141 ask_multiple "$found"
1142 fi
1143 echo -e "$srch\t$found" >> $cache
1144 else
1145 echo "$srch" >> $missing
1146 fi
1147 fi
1148 fi
1152 # Return size of file in human readible format
1153 # Note, "du" in opposite returns size occupied by file on disk (4KB multiple in most cases)
1154 filesize() {
1155 busybox ls -lh "$1" | awk '{print $5 "B"}'
1160 # Receipt functions to ease packaging
1163 get_dev_files() {
1164 _n 'Getting standard devel files...'
1165 mkdir -p $fs/usr/lib
1166 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1167 cp -a $install/usr/lib/*a $fs/usr/lib
1168 cp -a $install/usr/include $fs/usr
1169 status
1172 dblog() { tee -a $LOGS/pkgdb.log; }
1178 # Commands
1181 case "$1" in
1182 usage|help|-u|-h)
1183 usage ;;
1185 list-wok)
1186 newline; _ 'List of %s packages in "%s"' "$ARCH" "$WOK"; separator
1187 cd $WOK
1188 if [ "$ARCH" != 'i486' ]; then
1189 count=0
1190 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1191 do
1192 unset HOST_ARCH
1193 . $pkg
1194 count=$(($count + 1))
1195 colorize 34 "$PACKAGE"
1196 done
1197 else
1198 count=$(ls | wc -l)
1199 ls -1
1200 fi
1201 separator
1202 _p '%s package' '%s packages' "$count" "$(colorize 32 "$count")"
1203 newline ;;
1205 activity)
1206 cat $activity ;;
1208 search)
1209 # Just a simple search function, we dont need more actually.
1210 query="$2"
1211 newline; _ 'Search results for "%s"' "$query"; separator
1212 cd $WOK; ls -1 | grep "$query"
1213 separator; newline ;;
1215 setup)
1216 # Setup a build environment
1217 check_root
1218 _ 'Cook: setup environment' | log
1219 newline; _ 'Setting up your environment'; separator
1220 cd $SLITAZ
1221 init_db_files
1222 _ 'Checking for packages to install...'
1223 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1224 # ARCH-setup or 'cross check' should be used before: cook setup
1225 case "$ARCH" in
1226 arm*|x86_64)
1227 if [ ! -x '/usr/bin/cross' ]; then
1228 _ 'ERROR: %s is not installed' 'cross'
1229 exit 1
1230 fi
1231 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1232 . /etc/slitaz/cross.conf ;;
1233 esac
1234 for pkg in $SETUP_PKGS; do
1235 if [ -n "$forced" ]; then
1236 tazpkg -gi $pkg --forced
1237 else
1238 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1239 fi
1240 done
1242 # Handle --options
1243 case "$2" in
1244 --wok) hg clone $WOK_URL wok || exit 1 ;;
1245 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1246 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1247 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1248 esac
1250 # SliTaz group and permissions
1251 if ! grep -q ^slitaz /etc/group; then
1252 _ 'Adding group "%s"' 'slitaz'
1253 addgroup slitaz
1254 fi
1255 _ 'Setting permissions for group "%s"...' 'slitaz'
1256 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1257 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1258 separator; _ 'All done, ready to cook packages :-)'; newline ;;
1260 *-setup)
1261 # Setup for cross compiling.
1262 arch="${1%-setup}"
1263 check_root
1264 . /etc/slitaz/cook.conf
1265 for pkg in $CROSS_SETUP; do
1266 if [ -n "$forced" ]; then
1267 tazpkg -gi $pkg --forced
1268 else
1269 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1270 fi
1271 done
1273 _ 'Cook: setup %s cross environment' "$arch" | log
1274 newline; boldify $(_n 'Setting up your %s cross environment' "$arch"); separator
1275 init_db_files
1276 sed -i \
1277 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1278 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1279 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1280 /etc/slitaz/cook.conf
1281 case "$arch" in
1282 arm)
1283 flags='-O2 -march=armv6'
1284 host="$ARCH-slitaz-linux-gnueabi" ;;
1285 armv6hf)
1286 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1287 host="$ARCH-slitaz-linux-gnueabi" ;;
1288 armv7)
1289 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1290 host="$ARCH-slitaz-linux-gnueabi" ;;
1291 x86_64)
1292 flags='-O2 -mtune=generic -pipe'
1293 host="$ARCH-slitaz-linux" ;;
1294 esac
1295 sed -i \
1296 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1297 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1298 . /etc/slitaz/cook.conf
1299 sysroot="$CROSS_TREE/sysroot"
1300 tools="/cross/$arch/tools"
1301 root="$sysroot"
1302 # L10n: keep the same width of translations to get a consistent view
1303 _ 'Target arch : %s' "$ARCH"
1304 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1305 _ 'Build flags : %s' "$flags"
1306 _ 'Arch sysroot : %s' "$sysroot"
1307 _ 'Tools prefix : %s' "$tools/bin"
1308 # Tell the packages manager where to find packages.
1309 _ 'Packages DB : %s' "$root$DB"
1310 mkdir -p $root$INSTALLED
1311 cd $root$DB; rm -f *.bak
1312 for list in packages.list packages.desc packages.equiv packages.md5; do
1313 rm -f $list
1314 ln -s $SLITAZ/packages/$list $list
1315 done
1316 # We must have the cross compiled glibc-base installed or default
1317 # i486 package will be used as dep by tazpkg and then break the
1318 # cross environment
1319 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1320 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1321 fi
1322 # Show GCC version or warn if not yet compiled.
1323 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1324 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1325 else
1326 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1327 _ 'Run "%s" to cook a toolchain' 'cross compile'
1328 fi
1329 separator; newline ;;
1331 test)
1332 # Test a cook environment.
1333 _ 'Cook test: testing the cook environment' | log
1334 [ ! -d "$WOK" ] && exit 1
1335 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1336 cook cooktest ;;
1338 new)
1339 # Create the package folder and an empty receipt.
1340 pkg="$2"
1341 [ -z "$pkg" ] && usage
1342 newline
1343 if [ -d "$WOK/$pkg" ]; then
1344 _ 'Package "%s" already exists.' "$pkg"
1345 exit 1
1346 fi
1348 _n 'Creating folder "%s"' "$WOK/$pkg"
1349 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1351 _n 'Preparing the package receipt...'
1352 cp $DATA/receipt .
1353 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1354 status; newline
1356 # Interactive mode, asking and seding.
1357 case "$3" in
1358 --interactive|-x)
1359 _ 'Entering interactive mode...'
1360 separator
1361 _ 'Package : %s' "$pkg"
1363 _n 'Version : ' ; read answer
1364 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1366 _n 'Category : ' ; read answer
1367 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1369 # L10n: Short description
1370 _n 'Short desc : ' ; read answer
1371 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1373 _n 'Maintainer : ' ; read answer
1374 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1376 _n 'License : ' ; read answer
1377 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1379 _n 'Web site : ' ; read answer
1380 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1381 newline
1383 # Wget URL.
1384 _ 'Wget URL to download source tarball.'
1385 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1386 _n 'Wget url : ' ; read answer
1387 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1389 # Ask for a stuff dir.
1390 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1391 if [ "$?" == 0 ]; then
1392 _n 'Creating the stuff directory...'
1393 mkdir $WOK/$pkg/stuff; status
1394 fi
1396 # Ask for a description file.
1397 confirm "$(_n 'Are you going to write a description? (y/N)')"
1398 if [ "$?" == 0 ]; then
1399 _n 'Creating the "%s" file...' 'description.txt'
1400 touch $WOK/$pkg/description.txt; status
1401 fi
1403 separator; _ 'Receipt is ready to use.'; newline ;;
1404 esac ;;
1406 list)
1407 # Cook a list of packages (better use the Cooker since it will order
1408 # packages before executing cook).
1409 check_root
1410 if [ -z "$2" ]; then
1411 newline; _ 'No list in argument.'; newline
1412 exit 1
1413 fi
1414 if [ ! -f "$2" ]; then
1415 newline; _ 'List "%s" not found.' "$2"; newline
1416 exit 1
1417 fi
1419 _ 'Starting cooking the list "%s"' "$2" | log
1421 for pkg in $(cat $2); do
1422 cook $pkg || broken
1423 done ;;
1425 clean-wok)
1426 check_root
1427 newline; _n 'Cleaning all packages files...'
1428 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1429 status; newline ;;
1431 clean-src)
1432 check_root
1433 newline; _n 'Cleaning all packages sources...'
1434 rm -rf $WOK/*/source
1435 status; newline ;;
1437 uncook)
1438 cd $WOK
1439 count=0
1440 newline; _ 'Checking for uncooked packages'; separator
1442 for pkg in *; do
1443 unset HOST_ARCH EXTRAVERSION
1444 [ ! -e $pkg/receipt ] && continue
1445 . $pkg/receipt
1446 # Source cooked pkg receipt to get EXTRAVERSION
1447 if [ -d "$WOK/$pkg/taz" ]; then
1448 cd $WOK/$pkg/taz/$pkg-*
1449 . receipt; cd $WOK
1450 fi
1451 case "$ARCH" in
1452 i486)
1453 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1454 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1455 count=$(($count + 1))
1456 colorize 34 "$pkg"
1457 fi ;;
1458 arm*)
1459 # Check only packages included in arch
1460 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1461 # *.tazpkg
1462 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1463 count=$(($count + 1))
1464 colorize 34 "$pkg"
1465 fi
1466 fi ;;
1467 esac
1468 done
1470 if [ "$count" -gt "0" ]; then
1471 separator
1472 _p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")"
1473 else
1474 _ 'All packages are cooked :-)'
1475 fi
1476 newline ;;
1478 pkgdb)
1479 # Create suitable packages list for TazPKG and only for built packages
1480 # as well as flavors files for TazLiTo. We dont need logs since we do it
1481 # manually to ensure everything is fine before syncing the mirror.
1483 rm $LOGS/pkgdb.log 2>/dev/null
1485 case "$2" in
1486 --flavors|--rmpkg) ;;
1487 *)
1488 [ -n "$2" ] && PKGS="$2"
1489 if [ ! -d "$PKGS" ]; then
1490 { newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline; } | dblog
1491 exit 1
1492 fi ;;
1493 esac
1495 time=$(date +%s)
1496 flavors="$SLITAZ/flavors"
1497 live="$SLITAZ/live"
1499 echo 'cook:pkgdb' > $command
1500 _ 'Cook pkgdb: Creating all packages lists' | log
1501 newline; { _ 'Creating lists for "%s"' "$PKGS"; separator; } | dblog
1503 { _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"; newline; } | dblog
1505 cd $PKGS
1506 rm -f packages.* extra.list
1507 touch packages.equiv
1509 _n 'Creating file "%s"' 'packages.list' | dblog
1510 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1511 echo " ($(filesize $PKGS/packages.list))" | dblog
1513 _n 'Creating file "%s"' 'packages.md5' | dblog
1514 md5sum *.tazpkg > $PKGS/packages.md5
1515 echo " ($(filesize $PKGS/packages.md5))" | dblog
1516 cp $PKGS/packages.md5 $PKGS/packages.toremove # list of duplicates
1518 md5sum packages.md5 | cut -d' ' -f1 > ID
1519 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
1521 _n 'Creating file "%s"' 'descriptions.txt' | dblog
1522 rm $PKGS/descriptions.txt 2>/dev/null
1523 for i in $(ls $WOK | sort); do
1524 if [ -e "$WOK/$i/description.txt" ]; then
1525 echo "$i" >> descriptions.txt
1526 cat "$WOK/$i/description.txt" | sed 's|^$| |' >> descriptions.txt
1527 echo >> descriptions.txt
1528 fi
1529 done
1530 echo " ($(filesize $PKGS/descriptions.txt))" | dblog
1533 _ 'Creating lists from "%s"' "$WOK" | dblog
1534 cd $WOK
1535 for pkg in *; do
1536 unset_receipt
1537 . $pkg/receipt
1538 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1539 [ -s $pkg/taz/*/receipt ] && . $pkg/taz/*/receipt
1541 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ] || \
1542 [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1544 # packages.desc lets us search easily in DB
1545 cat >> $PKGS/packages.desc <<EOT
1546 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1547 EOT
1549 # packages.txt used by tazpkg and tazpkg-web also to provide
1550 # a human readable package list with version and description.
1551 cat >> $PKGS/packages.txt <<EOT
1552 $PACKAGE
1553 $VERSION$EXTRAVERSION
1554 $SHORT_DESC
1555 $PACKED_SIZE ($UNPACKED_SIZE installed)
1557 EOT
1559 # packages.info combines TazPkg separate files
1560 # and will substitute them all
1561 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1562 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1563 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
1564 cat >> $PKGS/packages.info <<EOT
1565 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
1566 EOT
1568 # packages.equiv is used by tazpkg install to check depends.
1569 for i in $PROVIDE; do
1570 DEST=''
1571 echo $i | fgrep -q : && DEST="${i#*:}:"
1572 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1573 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1574 $PKGS/packages.equiv
1575 else
1576 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1577 fi
1578 done
1580 # files.list provides a list of all packages files.
1581 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1582 $PKGS/files.list
1584 # list of duplicates
1585 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
1586 else
1587 # if receipt variable HOST_ARCH absent/empty or contains ARCH
1588 if [ -z "$HOST_ARCH" -o "${HOST_ARCH/$ARCH/}" != "$HOST_ARCH" ]; then
1589 _ ' - absent: %s (%s)' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ARCH" | dblog
1590 fi
1591 fi
1592 done
1594 # Display list size.
1595 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)" | dblog
1596 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)" | dblog
1597 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)" | dblog
1598 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)" | dblog
1600 cd $PKGS
1603 # Check package duplicates
1604 if [ -s "$PKGS/packages.toremove" ]; then
1605 newline | dblog
1606 _ 'Removing duplicates:' | dblog
1607 while read pkgsum pkgfile; do
1608 echo " - $pkgfile" | dblog
1609 sed -i "/${pkgfile%.tazpkg}/d" $PKGS/packages.list
1610 sed -i "/ $pkgfile/d" $PKGS/packages.md5
1611 [ -n "$rmpkg" ] && rm $PKGS/$pkgfile # remove packages only with --rmpkg
1612 done < $PKGS/packages.toremove
1613 newline | dblog
1614 fi
1615 rm $PKGS/packages.toremove
1618 # files.list.lzma
1619 _n 'Creating file "%s"' 'files.list.lzma' | dblog
1620 touch files.list
1621 # pkgs.slitaz.org strongly depends on list sorted by packages names
1622 lzma e files.list files.list.lzma
1623 echo " ($(filesize $PKGS/files.list.lzma))" | dblog
1625 # Pre-sorting filenames causes 10% smaller resulting lzma file
1626 _n 'Creating file "%s"' 'files-list.lzma' | dblog
1627 cat files.list | sort -k2 -o files.list.sorted
1628 lzma e files.list.sorted files-list.lzma
1629 rm -f files.list files.list.sorted
1630 echo " ($(filesize $PKGS/files-list.lzma))" | dblog
1632 [ -e files.list.md5 ] && rm files.list.md5
1633 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
1635 # packages.info.lzma
1636 PI=packages.info
1637 _n 'Creating file "%s"' 'packages.info.lzma' | dblog
1638 touch $PI
1639 lzma e $PI $PI.lzma
1640 echo " ($(filesize $PKGS/packages.info.lzma))" | dblog
1642 # Make bundle to fast recharge
1643 _n 'Creating file "%s"' 'bundle.tar.lzma' | dblog
1644 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
1645 # Make sure to get "mirrors" file
1646 until [ -e 'mirrors' ]; do
1647 wget -q http://mirror1.slitaz.org/mirrors
1648 echo -n '.' | dblog; sleep 5
1649 done
1650 # Make sure to get "extra.list" file
1651 until [ -e 'extra.list' ]; do
1652 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
1653 echo -n '.' | dblog; sleep 5
1654 done
1655 busybox tar -chaf bundle.tar.lzma \
1656 mirrors extra.list files-list.md5 packages.info descriptions.txt \
1657 packages.desc packages.md5 packages.txt packages.list packages.equiv
1658 rm ./mirrors
1659 echo " ($(filesize $PKGS/bundle.tar.lzma))" | dblog
1661 # Display some info.
1662 separator | dblog
1663 nb=$(ls $PKGS/*.tazpkg | wc -l)
1664 time=$(($(date +%s) - $time))
1665 # L10n: 's' is for seconds (cooking time)
1666 { _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline; } | dblog
1669 # Create all flavors files at once. Do we really need code to monitor
1670 # flavors changes? Lets just build them with packages lists before
1671 # syncing the mirror.
1672 [ "$2" != '--flavors' ] && exit 1
1674 if [ ! -d "$flavors" ]; then
1675 { _ 'Missing flavors folder "%s"' "$flavors"; newline; } | dblog
1676 exit 1
1677 fi
1679 [ ! -d "$live" ] && mkdir -p $live
1680 _ 'Creating flavors files in "%s"' "$live" | dblog
1681 _ 'Cook pkgdb: Creating all flavors' | log
1682 separator | dblog
1684 _ 'Recharging lists to use latest packages...' | dblog
1685 tazpkg recharge >/dev/null 2>/dev/null
1687 # We need a custom tazlito config to set working dir to /home/slitaz.
1688 if [ ! -f "$live/tazlito.conf" ]; then
1689 _ 'Creating configuration file "%s"' 'tazlito.conf' | dblog
1690 cp /etc/tazlito/tazlito.conf $live
1691 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1692 $live/tazlito.conf
1693 fi
1695 # Update Hg flavors repo and pack.
1696 if [ -d "$flavors/.hg" ]; then
1697 cd $flavors; hg pull -u
1698 fi
1700 cd $live
1701 _ 'Starting to generate flavors...' | dblog
1702 rm -f flavors.list *.flavor
1703 for i in $flavors/*; do
1704 fl=$(basename $i)
1705 _ 'Packing flavor "%s"' "$fl" | dblog
1706 tazlito pack-flavor $fl >/dev/null || exit 1
1707 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
1708 done
1709 cp -f $live/*.flavor $live/flavors.list $PKGS
1710 separator | dblog
1711 { _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline; } | dblog
1712 rm -f $command
1713 separator | dblog
1714 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" | dblog
1715 ;;
1717 *)
1718 # Just cook and generate a package.
1719 check_root
1720 time=$(date +%s)
1721 pkg="$1"
1722 [ -z "$pkg" ] && usage
1723 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1724 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
1725 receipt="$WOK/$pkg/receipt"
1726 check_pkg_in_wok
1727 newline
1729 unset inst
1730 unset_receipt
1731 . $receipt
1733 # Handle cross compilation.
1734 case "$ARCH" in
1735 arm*)
1736 if [ -z "$HOST_ARCH" ]; then
1737 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1738 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1739 _ 'cook: %s' "$error"
1740 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1741 _ 'Cook skip: %s' "$error" | log
1742 newline
1743 exit 1
1744 fi ;;
1745 esac
1747 # Some packages are not included in some arch or fail to cross compile.
1748 : ${HOST_ARCH=i486}
1749 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1750 # Handle arm{v6hf,v7,..}
1751 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1752 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1753 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1754 _ 'cook: %s' "error"
1755 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1756 _ 'Cook skip: %s' "$error" | log
1757 sed -i /^${pkg}$/d $broken
1758 newline
1759 exit 0
1760 fi
1762 # Skip blocked, 3 lines also for the Cooker.
1763 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
1764 _ 'Package "%s" is blocked' "$pkg"; newline
1765 exit 0
1766 fi
1768 try_aufs_chroot "$@"
1770 # Log and source receipt.
1771 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1772 echo "cook:$pkg" > $command
1773 [ "$lastcooktime" ] &&
1774 echo "cook:$pkg $lastcooktime $(date +%s)" > $cooktime
1776 # Display and log info if cook process stopped.
1777 # FIXME: gettext not working (in single quotes) here!
1778 trap '_ "\n\nCook stopped: control-C\n\n" | \
1779 tee -a $LOGS/$pkg.log' INT
1781 # Handle --options
1782 case "$2" in
1783 --clean|-c)
1784 _n 'Cleaning "%s"' "$pkg"
1785 cd $WOK/$pkg; rm -rf install taz source
1786 status; newline
1787 exit 0 ;;
1789 --install|-i)
1790 inst='yes' ;;
1792 --getsrc|-gs)
1793 _ 'Getting source for "%s"' "$pkg"; separator
1794 get_source
1795 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1796 exit 0 ;;
1798 --block|-b)
1799 _n 'Blocking package "%s"' "$pkg"
1800 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1801 status; newline
1802 exit 0 ;;
1804 --unblock|-ub)
1805 _n 'Unblocking package "%s"' "$pkg"
1806 sed -i "/^${pkg}$/"d $blocked
1807 status; newline
1808 exit 0 ;;
1810 --pack)
1811 if [ -d $WOK/$pkg/taz ]; then
1812 rm -rf $WOK/$pkg/taz
1813 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1814 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1815 clean_log
1816 else
1817 _ 'Need to build "%s"' "$pkg"
1818 exit 0
1819 fi
1820 exit 0 ;;
1822 --cdeps)
1823 if [ ! -d $WOK/$pkg/taz ]; then
1824 _ 'Need to build "%s"' "$pkg"
1825 exit 0
1826 fi
1828 _ 'Checking depends'; separator
1829 lddlist='/tmp/lddlist'; touch $lddlist
1830 missing='/var/cache/missing.file'
1832 # find all deps using ldd
1833 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1834 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1835 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1836 done #"
1838 # remove exe/so duplicates
1839 sort -u $lddlist > $lddlist.sorted
1841 # search packages
1842 for exefile in $(cat $lddlist.sorted); do
1843 search_file $exefile
1844 echo "$found" >> $lddlist.pkgs
1845 echo -n '.'
1846 done
1847 echo
1849 # remove packages duplicates
1850 sort -u $lddlist.pkgs > $lddlist.final
1851 sort -u $missing > $missing.final
1852 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1853 exit 0 ;;
1854 esac
1856 # Check if wanted is built now so we have separate log files.
1857 for wanted in $WANTED ; do
1858 if grep -q "^$wanted$" $blocked; then
1859 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
1860 newline
1861 rm -f $command
1862 exit 1
1863 fi
1864 if grep -q "^$wanted$" $broken; then
1865 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
1866 newline
1867 rm -f $command
1868 exit 1
1869 fi
1870 if [ ! -d "$WOK/$wanted/install" ]; then
1871 cook "$wanted" || exit 1
1872 fi
1873 done
1875 # Cook and pack or exit on error and log everything.
1876 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1877 remove_deps | tee -a $LOGS/$pkg.log
1878 cookit_quality
1879 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1880 clean_log
1882 # Exit if any error in packing.
1883 lerror=$(_n 'ERROR')
1884 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1885 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1886 debug_info | tee -a $LOGS/$pkg.log
1887 rm -f $command
1888 exit 1
1889 fi
1891 # Create an XML feed
1892 gen_rss
1894 # Time and summary
1895 time=$(($(date +%s) - $time))
1896 summary | tee -a $LOGS/$pkg.log
1897 newline
1899 # We may want to install/update (outside aufs jail !).
1900 [ -s /aufs-umount.sh ] ||
1901 install_package
1903 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1904 # You want automation: use the Cooker Build Bot.
1905 rm -f $command ;;
1906 esac
1908 exit 0