cookutils view cook @ rev 790

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