cookutils view cook @ rev 837

cook: few tweaks
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Nov 15 03:40:41 2016 +0200 (2016-11-15)
parents 11a3c021e563
children d8bac8bb4eab
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 2>/dev/null >&2 ;;
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 time.
354 disp_time() {
355 local sec div min
356 sec="$1"
357 div=$(( ($1 + 30) / 60))
358 case $div in
359 0) min='';;
360 # L10n: 'm' is for minutes (approximate cooking time)
361 *) min=$(_n ' ~ %dm' "$div");;
362 esac
364 # L10n: 's' is for seconds (cooking time)
365 _ '%ds%s' "$sec" "$min"
366 }
369 # Display cooked package summary.
371 summary() {
372 cd $WOK/$pkg
373 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
374 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
375 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
376 size=$(ls -lh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $5}')
377 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
378 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
380 _ 'Summary for: %s' "$PACKAGE $VERSION"
381 separator
383 # L10n: keep the same width of translations to get a consistent view
384 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
385 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
386 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
387 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
388 _ 'Packed : %s' "$fs"
389 _ 'Compressed : %s' "$size"
390 _ 'Files : %s' "$files"
391 _ 'Cook time : %s' "$(disp_time "$time")"
392 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
393 _ 'Host arch : %s' "$ARCH"
394 separator
395 }
398 # Display debugging error info.
400 debug_info() {
401 title 'Debug information'
402 # L10n: specify your format of date and time (to help: man date)
403 # L10n: not bad one is '+%x %R'
404 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
405 [ "$time" ] && _ 'Cook time: %ds' "$(($(date +%s) - $time))"
406 # L10n: Please, translate all messages beginning with ERROR in a same way
407 lerror=$(_n 'ERROR')
408 for error in \
409 ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
410 'error:' 'fatal error:' 'undefined reference to' \
411 'Unable to connect to' 'link: cannot find the library' \
412 'CMake Error' ': No such file or directory' \
413 'Could not read symbols: File in wrong format'
414 do
415 fgrep "$error" $LOGS/$pkg.log
416 done > $LOGS/$pkg.log.debug_info 2>&1
417 cat $LOGS/$pkg.log.debug_info
418 rm -f $LOGS/$pkg.log.debug_info
419 footer
420 }
423 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
424 # so some packages need to copy these files with the receipt and genpkg_rules.
426 copy_generic_files() {
427 # $LOCALE is set in cook.conf
428 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
429 if [ -d "$install/usr/share/locale" ]; then
430 mkdir -p $fs/usr/share/locale
431 for i in $LOCALE; do
432 if [ -d "$install/usr/share/locale/$i" ]; then
433 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
434 fi
435 done
436 fi
437 fi
439 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
440 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
441 if [ -d "$install/usr/share/pixmaps" ]; then
442 mkdir -p $fs/usr/share/pixmaps
443 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
444 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
445 $fs/usr/share/pixmaps
446 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
447 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
448 $fs/usr/share/pixmaps
449 fi
450 fi
452 # Custom or homemade PNG pixmap can be in stuff.
453 if [ -f "$stuff/$PACKAGE.png" ]; then
454 mkdir -p $fs/usr/share/pixmaps
455 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
456 fi
457 fi
459 # Desktop entry (.desktop).
460 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
461 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
462 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
463 mkdir -p $fs/usr/share
464 cp -a $install/usr/share/applications $fs/usr/share
465 fi
466 fi
468 # Homemade desktop file(s) can be in stuff.
469 if [ -d "$stuff/applications" ]; then
470 mkdir -p $fs/usr/share
471 cp -a $stuff/applications $fs/usr/share
472 fi
473 if [ -f "$stuff/$PACKAGE.desktop" ]; then
474 mkdir -p $fs/usr/share/applications
475 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
476 fi
478 # Add custom licenses
479 if [ -d "$stuff/licenses" ]; then
480 mkdir -p $fs/usr/share/licenses
481 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
482 fi
483 }
486 # Fix common errors and warnings in the .desktop files
487 # Fixing can be disabled with COOKOPTS="!fixdesktops"
489 fix_desktop_files() {
490 [ "${COOKOPTS/!fixdesktops/}" != "$COOKOPTS" ] && return
491 [ -z "$(find $install -type f -name '*.desktop')" ] && return
493 if [ -n "$QA" -a -z "$(which desktop-file-validate)" ]; then
494 tazpkg -gi desktop-file-utils-extra --quiet
495 fi
497 for desktop in $(find $install -type f -name '*.desktop'); do
498 cp "$desktop" "$desktop.orig"
500 # Sort out .desktop file (is prerequisite to correct working of `fix-desktop-file`)
501 sdft "$desktop" -i
503 # Fix common errors in .desktop file
504 fix-desktop-file "$desktop"
506 if [ -n "$QA" ]; then
507 # Check the rest of errors, warnings and tips
508 _ 'QA: Checking %s...' "$(basename $desktop)"
509 diff "$desktop.orig" "$desktop"
510 desktop-file-validate "$desktop" | busybox fold -s
511 echo
512 fi
514 rm "$desktop.orig"
515 done
516 }
519 # Compressor mini summary
521 comp_summary() {
522 [ "$3" -eq 0 ] && return
523 local time=$(($2 - $1))
524 local saving=$(( ($3 - $4) / 1024 ))
525 _ ' Time: %s. Size: %s B -> %s B. Save: %s KB' "$(disp_time $time)" "$3" "$4" "$saving"
526 }
529 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
530 # as removing unneeded files like in Python packages. Cross compiled binaries
531 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
532 # Stripping can be disabled with COOKOPTS="!strip"
534 strip_package() {
535 [ "${COOKOPTS/!strip/}" != "$COOKOPTS" ] && return
537 case "$ARCH" in
538 arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
539 *) export STRIP='strip' ;;
540 esac
541 action 'Executing strip on all files...'
542 local size0=0 size1=0 oldsize newsize
543 local time0=$(date +%s)
545 # Strip executable files
546 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
547 if [ -d "$dir" ]; then
548 oldsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
549 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
550 newsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
551 size0=$((size0 + oldsize)); size1=$((size1 + newsize))
552 fi
553 done
555 # Strip shared and static libraries
556 # Remove Python *.pyc and *.pyo, Perl perllocal.pod and .packlist
557 oldsize=$(find $fs -type f \( \
558 -name '*.so*' -o -name '*.a' -o \
559 -name '*.pyc' -o -name '*.pyo' -o \
560 -name 'perllocal.pod' -o -name '.packlist' \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
562 find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
563 find $fs -name '*.a' -exec $STRIP --strip-debug '{}' 2>/dev/null \;
564 find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
565 find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \) -delete 2>/dev/null
567 newsize=$(find $fs -type f \( \
568 -name '*.so*' -o -name '*.a' -o \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
570 size0=$((size0 + oldsize)); size1=$((size1 + newsize))
572 local time1=$(date +%s)
573 status
574 comp_summary "$time0" "$time1" "$size0" "$size1"
575 }
578 # Update installed.cook.diff
580 update_installed_cook_diff() {
581 # If a cook failed deps are removed.
582 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
583 cd $CACHE
584 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
585 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
586 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
587 }
590 # Remove installed deps.
592 remove_deps() {
593 # Now remove installed build deps.
594 diff='/tmp/installed.cook.diff'
595 if [ -s $diff ]; then
596 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
597 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
598 _n 'Build dependencies to remove:'; echo " $nb"
599 [ -n "$root" ] && echo "root=\"$root\""
600 _n 'Removing:'
601 for dep in $deps; do
602 echo -n " $dep"
603 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
604 done
605 newline; newline
606 # Keep the last diff for debug and info.
607 mv -f $diff $CACHE/installed.diff
608 fi
609 }
612 # Function to compress all man pages
613 # Compressing can be disabled with COOKOPTS="!manz"
615 compress_manpages() {
616 [ "${COOKOPTS/!manz/}" != "$COOKOPTS" ] && return
618 case "$ARCH" in
619 arm*) return;; # While SliTaz-arm miss `advancecomp`
620 esac
621 local manpath="$install/usr/share/man" dest link
622 [ -d "$manpath" ] || return
624 action 'Compressing man pages...'
626 local size0=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
627 local time0=$(date +%s)
628 # We'll use only Gzip compression, so decompress other formats first
629 find $manpath -type f -name '*.bz2' -exec bunzip2 \{\} \;
630 find $manpath -type f -name '*.xz' -exec unxz \{\} \;
632 # Fast compress with gzip
633 find $manpath -type f -name '*.[1-9]' -exec gzip \{\} \;
635 # Fix symlinks
636 for i in $(find $install/usr/share/man -type l); do
637 dest=$(readlink $i | sed 's|\.[gbx]z2*$||')
638 link=$(echo $i | sed 's|\.[gbx]z2*$||')
639 rm $i; ln -s $dest.gz $link.gz
640 done
642 # Recompress with advdef (it can't compress, only recompress)
643 tazpkg -gi advancecomp --quiet
644 for i in $(find $install/usr/share/man -type f); do
645 advdef -z4q $i
646 done
648 local size1=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
649 local time1=$(date +%s)
650 status
651 comp_summary "$time0" "$time1" "$size0" "$size1"
652 }
655 # Function used after compile_rules() to compress all png images
656 # Compressing can be disabled with COOKOPTS="!pngz"
658 cook_compress_png() {
659 [ "${COOKOPTS/!pngz/}" != "$COOKOPTS" ] && return
660 case "$ARCH" in
661 arm*) return;; # While SliTaz-arm miss `pngquant` and `optipng`
662 esac
663 [ -z "$(find $install -type f -name '*.png')" ] && return
665 action 'Compressing png images...'
666 local size0=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
667 local time0=$(date +%s)
669 local use_pq=true use_op=true
670 [ "${COOKOPTS/!pngquant/}" != "$COOKOPTS" ] && use_pq=false
671 [ "${COOKOPTS/!optipng/}" != "$COOKOPTS" ] && use_op=false
673 $use_pq && tazpkg -gi pngquant --quiet
674 $use_op && tazpkg -gi optipng --quiet
676 local oplevel=$(echo $COOKOPTS | grep 'op[0-8]' | sed 's|.*op\([0-8]\).*|\1|')
677 [ -z "$oplevel" ] && oplevel='2'
678 [ "$oplevel" == '8' ] && oplevel='7 -zm1-9'
680 for i in $(find $install -type f -name '*.png'); do
681 $use_pq && pngquant -f --skip-if-larger --ext .png --speed 1 "$i"
682 $use_op && optipng -quiet -strip all -o$oplevel "$i"
683 done
685 local size1=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
686 local time1=$(date +%s)
687 status
688 comp_summary "$time0" "$time1" "$size0" "$size1"
689 }
692 # Function used after compile_rules() to compress all svg images
693 # Compressing can be disabled with COOKOPTS="!svgz"
695 cook_compress_svg() {
696 [ "${COOKOPTS/!svgz/}" != "$COOKOPTS" ] && return
697 case "$ARCH" in
698 arm*) return;; # While SliTaz-arm miss `svgcleaner`
699 esac
700 [ -z "$(find $install -type f -name '*.svg')" ] && return
702 action 'Compressing svg images...'
703 local size0=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
704 local time0=$(date +%s)
705 tazpkg -gi svgcleaner --quiet
706 cleaner_log="$(mktemp)"
707 for i in $(find $install -type f -name '*.svg'); do
708 echo -n "$i: " >> "$cleaner_log"
709 svgcleaner "$i" "$i" --remove-unresolved-classes false --quiet true >> "$cleaner_log"
710 done
711 local size1=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
712 local time1=$(date +%s)
713 status
714 comp_summary "$time0" "$time1" "$size0" "$size1"
715 sed -i '/: $/d' "$cleaner_log"
716 if [ -s "$cleaner_log" ]; then
717 echo 'Cleaner warnings and errors:'
718 awk '{printf " %s\n", $0;}' "$cleaner_log"
719 echo
720 fi
721 rm "$cleaner_log"
722 }
725 # Function used after compile_rules() to shrink all *.ui and *.glade files:
726 # remove insignificant spaces and comments
727 # Compressing can be disabled with COOKOPTS="!uiz"
729 compress_ui() {
730 [ "${COOKOPTS/!uiz/}" != "$COOKOPTS" ] && return
731 case "$ARCH" in
732 arm*) return;; # While SliTaz-arm miss `xmlstarlet`
733 esac
734 [ -z "$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) )" ] && return
736 action 'Compressing ui files...'
737 local size0=$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
738 local time0=$(date +%s)
739 tazpkg -gi xmlstarlet --quiet
740 temp_ui="$(mktemp)"
741 for ui in $(find $install -type f \( -name '*.ui' -o -name '*.glade' \) ); do
742 xmlstarlet c14n --without-comments "$ui" | xmlstarlet sel -B -t -c '*' > "$temp_ui"
743 cat "$temp_ui" > "$ui"
744 done
745 local size1=$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
746 local time1=$(date +%s)
747 status
748 comp_summary "$time0" "$time1" "$size0" "$size1"
749 rm "$temp_ui"
750 }
753 # The main cook function.
755 cookit() {
756 title 'Cook: %s' "$PACKAGE $VERSION"
757 set_paths
759 # Handle cross-tools.
760 case "$ARCH" in
761 arm*|x86_64)
762 # CROSS_COMPILE is used by at least Busybox and the kernel to set
763 # the cross-tools prefix. Sysroot is the root of our target arch
764 sysroot="$CROSS_TREE/sysroot"
765 tools="$CROSS_TREE/tools"
766 # Set root path when cross compiling. ARM tested but not x86_64
767 # When cross compiling we must install build deps in $sysroot.
768 arch="-$ARCH"
769 root="$sysroot"
770 _ '%s sysroot: %s' "$ARCH" "$sysroot"
771 _ 'Adding "%s" to PATH' "$tools/bin"
772 export PATH="$PATH:$tools/bin"
773 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
774 export CROSS_COMPILE="$HOST_SYSTEM-"
775 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
776 if [ "$ARCH" == 'x86_64' ]; then
777 export CC="$HOST_SYSTEM-gcc -m64"
778 export CXX="$HOST_SYSTEM-g++ -m64"
779 else
780 export CC="$HOST_SYSTEM-gcc"
781 export CXX="$HOST_SYSTEM-g++"
782 fi
783 export AR="$HOST_SYSTEM-ar"
784 export AS="$HOST_SYSTEM-as"
785 export RANLIB="$HOST_SYSTEM-ranlib"
786 export LD="$HOST_SYSTEM-ld"
787 export STRIP="$HOST_SYSTEM-strip"
788 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
789 esac
791 [ -n "$QA" ] && receipt_quality
792 cd $pkgdir
793 [ -z "$continue" ] && rm -rf source 2>/dev/null
794 rm -rf install taz 2>/dev/null
796 # Disable -pipe if less than 512Mb free RAM.
797 free=$(free | awk '/buffers:/{print $4}')
798 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
799 _ 'Disabling -pipe compile flag: %d RAM free' "$free"
800 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
801 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
802 fi
803 unset free
805 # Export flags and path to be used by make and receipt.
806 DESTDIR="$pkgdir/install"
807 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
808 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
809 #LDFLAGS
811 # Check for build deps and handle implicit depends of *-dev packages
812 # (ex: libusb-dev :: libusb).
813 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
814 touch $CACHE/installed.local $CACHE/installed.web
815 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
816 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
817 for dep in $BUILD_DEPENDS; do
818 implicit="${dep%-dev}"
819 # Don't add implicit dependency if it defined in DEPENDS
820 # echo '' $DEPENDS '' | fgrep -q " $implicit " && implicit=''
821 for i in $dep $implicit; do
822 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
823 # Try local package first. In some cases implicit doesn't exist, ex:
824 # libboost-dev exists but not libboost, so check if we got vers.
825 unset vers
826 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
827 # We may have a local package.
828 if [ -z "$vers" ]; then
829 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info 2> /dev/null)
830 fi
831 debug "bdep: $i version: $vers"
832 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
833 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
834 else
835 # Priority to package version in wok (maybe more up-to-date)
836 # than the mirrored one.
837 if [ -n "$vers" ]; then
838 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
839 echo $i >> $CACHE/installed.web
840 else
841 # So package exists in wok but not available.
842 _ 'Missing dep (wok/pkg): %s' "$i $vers"
843 echo $i >> $CACHE/missing.dep
844 fi
845 else
846 # Package is not in wok but may be in online repo.
847 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
848 echo $i >> $CACHE/installed.web
849 else
850 _ 'ERROR: unknown dep "%s"' "$i"
851 exit 1
852 fi
853 fi
854 fi
855 fi
856 done
857 done
859 # Get the list of installed packages
860 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
862 # Have we a missing build dep to cook?
863 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
864 _ 'Auto cook config is set: %s' "$AUTO_COOK"
865 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
866 for i in $(uniq $CACHE/missing.dep); do
867 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
868 tee -a $LOGS/$PACKAGE.log.$$
869 # programmers: next two messages are exact copy from remove_deps()
870 togrep1=$(_n 'Build dependencies to remove:')
871 togrep2=$(_n 'Removing:')
872 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
873 fgrep $togrep1 $LOGS/$i.log && \
874 fgrep $togrep2 $LOGS/$i.log && newline) | \
875 tee -a $LOGS/$PACKAGE.log.$$ && break
876 done
877 rm -f $CACHE/missing.dep
878 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
879 fi
881 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
882 # is enabled and cook fails we have ERROR in log, if no auto cook we have
883 # missing dep in cached file.
884 lerror=$(_n 'ERROR')
885 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
886 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
887 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
888 exit 1
889 fi
891 # Install local packages: package-version$arch
892 cd $PKGS
893 for i in $(uniq $CACHE/installed.local); do
894 _ 'Installing dep (pkg/local): %s' "$i"
895 tazpkg install $i --root=$root --local --quiet
896 done
898 # Install web or cached packages (if mirror is set to $PKGS we only
899 # use local packages).
900 for i in $(uniq $CACHE/installed.web); do
901 _ 'Installing dep (web/cache): %s' "$i"
902 tazpkg get-install $i --root=$root --quiet
903 done
905 update_installed_cook_diff
907 # Get source tarball and make sure we have source dir named:
908 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
909 # tarball if it exists.
910 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
911 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
912 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
913 LZMA_SRC=''
914 else
915 get_source || exit 1
916 fi
917 fi
918 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
919 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
920 if ! extract_source ; then
921 get_source
922 extract_source || exit 1
923 fi
924 if [ -n "$LZMA_SRC" ]; then
925 cd $pkgdir/source
926 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
927 mv tmp tmp-1; mkdir tmp
928 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
929 fi
930 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
931 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
932 fi
933 fi
934 cd $pkgdir/source/tmp
935 # Some archives are not well done and don't extract to one dir (ex lzma).
936 files=$(ls | wc -l)
937 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
938 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
939 mv * ../$PACKAGE-$VERSION/$TARBALL
940 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
941 mv * ../$PACKAGE-$VERSION
942 cd ..; rm -rf tmp
943 fi
945 # Libtool shared libs path hack.
946 case "$ARCH" in
947 arm*) cross libhack ;;
948 esac
950 # Execute receipt rules.
951 if grep -q ^compile_rules $receipt; then
952 _ 'Executing: %s' 'compile_rules'
953 echo "CFLAGS : $CFLAGS"
954 #echo "LDFLAGS : $LDFLAGS"
955 [ -d "$src" ] && cd $src
956 compile_rules $@ || exit 1
957 # Stay compatible with _pkg
958 [ -d "$src/_pkg" ] && mv $src/_pkg $install
959 # QA: compile_rules success so valid.
960 mkdir -p $install
961 else
962 # QA: no compile_rules so no error, valid.
963 mkdir -p $install
964 fi
966 # Actions to do after compiling the package
967 # Skip all for splitted packages (already done in main package)
968 if [ -z "$WANTED" ]; then
969 footer
970 compress_manpages
971 cook_compress_png
972 cook_compress_svg
973 compress_ui
974 fix_desktop_files
975 fi
976 footer
978 # Execute testsuite.
979 if grep -q ^testsuite $receipt; then
980 title 'Running testsuite'
981 testsuite $@ || exit 1
982 footer
983 fi
985 update_installed_cook_diff force
986 }
989 # Cook quality assurance.
991 cookit_quality() {
992 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
993 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
994 fi
995 # ERROR can be echoed any time in cookit()
996 lerror=$(_n 'ERROR')
997 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
998 grep -Eq "(^$lerror|undefined reference to)" ; then
999 debug_info | tee -a $LOGS/$pkg.log
1000 rm -f $command
1001 exit 1
1002 fi
1006 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
1007 # but it doesn't handle EXTRAVERSION.
1009 packit() {
1010 set_paths
1012 # Handle cross compilation
1013 case "$ARCH" in
1014 arm*|x86_64) arch="-$ARCH" ;;
1015 esac
1017 title 'Pack: %s' "$PACKAGE $VERSION$arch"
1019 if grep -q ^genpkg_rules $receipt; then
1020 _ 'Executing: %s' 'genpkg_rules'
1021 set -e; cd $pkgdir; mkdir -p $fs
1022 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
1023 $LOGS/$pkg.log
1024 else
1025 _ 'No packages rules: meta package'
1026 mkdir -p $fs
1027 fi
1029 # First QA check to stop now if genpkg_rules failed.
1030 lerror=$(_n 'ERROR')
1031 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1032 exit 1
1033 fi
1035 cd $taz
1036 for file in receipt description.txt; do
1037 [ ! -f "../$file" ] && continue
1038 action 'Copying "%s"...' "$file"
1039 cp -f ../$file $pack; chown 0.0 $pack/$file; status
1040 done
1041 copy_generic_files
1043 # Strip and stuff files.
1044 strip_package
1046 # Create files.list with redirecting find output.
1047 action 'Creating the list of files...'
1048 cd $fs
1049 find . -type f -print > ../files.list
1050 find . -type l -print >> ../files.list
1051 cd ..; sed -i s/'^.'/''/ files.list
1052 status
1054 # Md5sum of files.
1055 action 'Creating md5sum of files...'
1056 while read file; do
1057 [ -L "fs$file" ] && continue
1058 [ -f "fs$file" ] || continue
1059 case "$file" in
1060 /lib/modules/*/modules.*|*.pyc) continue ;;
1061 esac
1062 md5sum "fs$file" | sed 's/ fs/ /'
1063 done < files.list > md5sum
1064 status
1066 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1067 2>/dev/null | awk 'END{ print $1 }')
1069 # Build cpio archives.
1070 action 'Compressing the FS...'
1071 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1072 rm -rf fs
1073 status
1075 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
1076 2>/dev/null | awk 'END{ print $1 }')
1078 action 'Updating receipt sizes...'
1079 sed -i s/^PACKED_SIZE.*$// receipt
1080 sed -i s/^UNPACKED_SIZE.*$// receipt
1081 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1082 status
1084 # Set extra version.
1085 if [ -n "$EXTRAVERSION" ]; then
1086 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
1087 sed -i s/^EXTRAVERSION.*$// receipt
1088 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1089 status
1090 fi
1092 # Compress.
1093 action 'Creating full cpio archive...'
1094 find . -print | cpio -o -H newc --quiet > \
1095 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1096 status
1098 action 'Restoring original package tree...'
1099 unlzma -c fs.cpio.lzma | cpio -idm --quiet
1100 status
1102 rm fs.cpio.lzma; cd ..
1104 # QA and give info.
1105 tazpkg=$(ls *.tazpkg)
1106 packit_quality
1107 footer "$(_ 'Package "%s" created' "$tazpkg")"
1111 # Verify package quality and consistency.
1113 packit_quality() {
1114 #action 'QA: checking for broken link...'
1115 #link=$(find $fs/usr -type l -follow)
1116 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
1117 #status
1119 # Exit if any error found in log file.
1120 lerror=$(_n 'ERROR')
1121 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1122 rm -f $command
1123 exit 1
1124 fi
1126 action 'QA: checking for empty package...'
1127 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
1128 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
1129 newline; _ 'ERROR: empty package'
1130 rm -f $command
1131 exit 1
1132 else
1133 :; status
1134 # Find and remove old package(s)
1135 tempd="$(mktemp -d)"; cd "$tempd"
1136 for testpkg in $(ls $PKGS/$pkg-*.tazpkg 2> /dev/null); do
1137 # Extract receipt from each matched package
1138 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
1139 name=$(. receipt; echo $PACKAGE)
1140 rm receipt
1141 if [ "$name" == "$pkg" ]; then
1142 action 'Removing old package "%s"' "$(basename "$testpkg")"
1143 rm -f "$testpkg"
1144 status
1145 fi
1146 done
1147 rm -r "$tempd"
1148 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
1149 sed -i /^${pkg}$/d $broken
1150 #action 'Removing source tree...'
1151 #rm -f $WOK/$pkg/source; status
1152 fi
1156 # Reverse "cat" command: prints input lines in the reverse order
1158 tac() {
1159 sed '1!G;h;$!d' $1
1163 # Install package on --install or update the chroot.
1165 install_package() {
1166 case "$ARCH" in
1167 arm*|x86_64)
1168 arch="-$ARCH"
1169 root="$CROSS_TREE/sysroot" ;;
1170 esac
1171 # Install package if requested but skip install if target host doesn't
1172 # match build system or it will break the build chroot.
1173 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1174 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
1175 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1176 cd $PKGS
1177 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1178 else
1179 _ 'Unable to install package, build has failed.'; newline
1180 exit 1
1181 fi
1182 fi
1184 # Install package if part of the chroot to keep env up-to-date.
1185 if [ -d "$root$INSTALLED/$pkg" ]; then
1186 . /etc/slitaz/cook.conf
1187 . $WOK/$pkg/taz/$pkg-*/receipt
1188 _ 'Updating %s chroot environment...' "$ARCH"
1189 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
1190 cd $PKGS
1191 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1192 fi
1196 # remove chroot jail
1198 umount_aufs() {
1199 tac ${1}rw/aufs-umount.sh | sh
1200 rm -rf ${1}rw
1201 umount ${1}root
1202 rmdir ${1}r*
1206 # Launch the cook command into a chroot jail protected by aufs.
1207 # The current filesystems are used read-only and updates are
1208 # stored in a separate branch.
1210 try_aufs_chroot() {
1212 base="/dev/shm/aufsmnt$$"
1214 # Can we setup the chroot? Is it already done?
1215 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1216 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1217 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1218 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1219 mkdir ${base}root ${base}rw || return
1221 _ 'Setup aufs chroot...'
1223 # Sanity check
1224 for i in / /proc /sys /dev/shm /home ; do
1225 case " $AUFS_MOUNTS " in
1226 *\ $i\ *) ;;
1227 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1228 esac
1229 done
1230 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1231 mount --bind $mnt ${base}root$mnt
1232 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1233 _ 'Aufs mount failure'
1234 umount ${base}root
1235 rm -rf ${base}r*
1236 return
1237 fi
1238 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1239 done
1240 trap "umount_aufs ${base}" INT
1242 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1243 status=$?
1245 _ 'Leaving aufs chroot...'
1246 umount_aufs $base
1247 # Install package outside the aufs jail
1248 install_package
1249 exit $status
1253 # Encode predefined XML entities
1255 xml_ent() {
1256 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1260 # Create a XML feed for freshly built packages.
1262 gen_rss() {
1263 pubdate=$(date '+%a, %d %b %Y %X')
1264 cat > $FEEDS/$pkg.xml <<EOT
1265 <item>
1266 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1267 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1268 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1269 <pubDate>$pubdate</pubDate>
1270 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1271 </item>
1272 EOT
1276 # Truncate stdout log file to $1 Mb.
1278 loglimit() {
1279 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1280 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1281 else
1282 tee /dev/stderr
1283 fi
1287 # Search file in mirrored packages
1289 search_file_mirror() {
1290 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1294 # Search file in local wok packages
1296 search_file_local() {
1297 # existing packages have precedence over the package/taz folder
1298 srch=$1
1299 { for package in $(find $PKGS -name '*.tazpkg'); do
1300 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1301 grep /$srch\$)" ]; then
1302 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1303 fi
1304 done } | sort -u
1308 # Ask in multiple choice
1310 ask_multiple() {
1311 local multiples first my_choice
1312 multiples="$1"
1313 first=$(echo "$multiples" | head -n1)
1314 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1315 _ 'Select one [%s]: ' "$first"; read my_choice
1316 found="${my_choice:-$first}"
1320 # Search file in local cache (fast), local wok packages, mirrored packages
1322 search_file() {
1323 local srch cache missing
1324 srch="$1"
1325 cache='/var/cache/ldsearch.cache'
1326 missing='/var/cache/missing.file'
1327 touch $cache $missing
1328 found=$(grep $srch $cache | cut -d$'\t' -f2)
1329 if [ -z "$found" ]; then
1330 found=$(search_file_local $srch)
1331 if [ -n "$found" ]; then
1332 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1333 ask_multiple "$found"
1334 fi
1335 echo -e "$srch\t$found" >> $cache
1336 else
1337 found=$(search_file_mirror $srch)
1338 if [ -n "$found" ]; then
1339 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1340 ask_multiple "$found"
1341 fi
1342 echo -e "$srch\t$found" >> $cache
1343 else
1344 echo "$srch" >> $missing
1345 fi
1346 fi
1347 fi
1351 # Return size of file in human readible format
1352 # Note, "du" in opposite returns size occupied by file on disk (4KB multiple in most cases)
1353 filesize() {
1354 busybox ls -lh "$1" | awk '{print $5 "B"}'
1359 # Receipt functions to ease packaging
1362 get_dev_files() {
1363 action 'Getting standard devel files...'
1364 mkdir -p $fs/usr/lib
1365 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1366 cp -a $install/usr/lib/*a $fs/usr/lib
1367 cp -a $install/usr/include $fs/usr
1368 status
1372 # Function to use in compile_rules() to copy man page from $src to $install
1374 cook_pick_manpages() {
1375 local name section
1376 action 'Copying man pages...'
1378 for i in $@; do
1379 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1380 section=${name##*/}; section=${section##*.}
1381 mkdir -p $install/usr/share/man/man$section
1382 cp -a $i $install/usr/share/man/man$section
1383 done
1384 status
1388 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1390 cook_copy_files() {
1391 action 'Copying files...'
1392 cd $install
1393 local i j
1394 for i in $@; do
1395 for j in $(find . -name $i ! -type d); do
1396 mkdir -p $fs$(dirname ${j#.})
1397 cp -a $j $fs/${j#.}
1398 done
1399 done
1400 cd - >/dev/null
1401 status
1405 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1407 cook_copy_folders() {
1408 action 'Copying folders...'
1409 cd $install
1410 local i j
1411 for i in $@; do
1412 for j in $(find . -name $i -type d); do
1413 mkdir -p $fs$(dirname ${j#.})
1414 cp -a $j $fs/${j#.}
1415 done
1416 done
1417 cd - >/dev/null
1418 status
1422 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1423 # (default: 16 and 48) from $install to $fs
1425 cook_copy_icons() {
1426 local sizes=$@
1427 action 'Copying hicolor icons...'
1428 mkdir -p $fs/usr/share/icons/hicolor
1429 for i in ${sizes:-16 48}; do
1430 [ -e "$install/usr/share/icons/hicolor/${i}x$i" ] &&
1431 cp -a $install/usr/share/icons/hicolor/${i}x$i \
1432 $fs/usr/share/icons/hicolor
1433 done
1434 status
1437 dblog() { tee -a $LOGS/pkgdb.log; }
1443 # Commands
1446 case "$1" in
1447 usage|help|-u|-h)
1448 usage ;;
1450 list-wok)
1451 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1452 cd $WOK
1453 if [ "$ARCH" != 'i486' ]; then
1454 count=0
1455 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1456 do
1457 unset HOST_ARCH
1458 . $pkg
1459 count=$(($count + 1))
1460 colorize 34 "$PACKAGE"
1461 done
1462 else
1463 count=$(ls | wc -l)
1464 ls -1
1465 fi
1466 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1467 ;;
1469 activity)
1470 cat $activity ;;
1472 search)
1473 # Just a simple search function, we dont need more actually.
1474 query="$2"
1475 title 'Search results for "%s"' "$query"
1476 cd $WOK; ls -1 | grep "$query"
1477 footer ;;
1479 setup)
1480 # Setup a build environment
1481 check_root
1482 _ 'Cook: setup environment' | log
1483 title 'Setting up your environment'
1484 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1485 cd $SLITAZ
1486 init_db_files
1487 _ 'Checking for packages to install...'
1488 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1489 # ARCH-setup or 'cross check' should be used before: cook setup
1490 case "$ARCH" in
1491 arm*|x86_64)
1492 if [ ! -x '/usr/bin/cross' ]; then
1493 _ 'ERROR: %s is not installed' 'cross'
1494 exit 1
1495 fi
1496 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1497 . /etc/slitaz/cross.conf ;;
1498 esac
1499 for pkg in $SETUP_PKGS; do
1500 if [ -n "$forced" ]; then
1501 tazpkg -gi $pkg --forced
1502 else
1503 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1504 fi
1505 done
1507 # Handle --options
1508 case "$2" in
1509 --wok) hg clone $WOK_URL wok || exit 1 ;;
1510 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1511 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1512 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1513 esac
1515 # SliTaz group and permissions
1516 if ! grep -q ^slitaz /etc/group; then
1517 _ 'Adding group "%s"' 'slitaz'
1518 addgroup slitaz
1519 fi
1520 _ 'Setting permissions for group "%s"...' 'slitaz'
1521 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1522 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1523 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1525 *-setup)
1526 # Setup for cross compiling.
1527 arch="${1%-setup}"
1528 check_root
1529 . /etc/slitaz/cook.conf
1530 for pkg in $CROSS_SETUP; do
1531 if [ -n "$forced" ]; then
1532 tazpkg -gi $pkg --forced
1533 else
1534 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1535 fi
1536 done
1538 _ 'Cook: setup %s cross environment' "$arch" | log
1539 title 'Setting up your %s cross environment' "$arch"
1540 init_db_files
1541 sed -i \
1542 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1543 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1544 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1545 /etc/slitaz/cook.conf
1546 case "$arch" in
1547 arm)
1548 flags='-O2 -march=armv6'
1549 host="$ARCH-slitaz-linux-gnueabi" ;;
1550 armv6hf)
1551 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1552 host="$ARCH-slitaz-linux-gnueabi" ;;
1553 armv7)
1554 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1555 host="$ARCH-slitaz-linux-gnueabi" ;;
1556 x86_64)
1557 flags='-O2 -mtune=generic -pipe'
1558 host="$ARCH-slitaz-linux" ;;
1559 esac
1560 sed -i \
1561 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1562 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1563 . /etc/slitaz/cook.conf
1564 sysroot="$CROSS_TREE/sysroot"
1565 tools="/cross/$arch/tools"
1566 root="$sysroot"
1567 # L10n: keep the same width of translations to get a consistent view
1568 _ 'Target arch : %s' "$ARCH"
1569 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1570 _ 'Build flags : %s' "$flags"
1571 _ 'Arch sysroot : %s' "$sysroot"
1572 _ 'Tools prefix : %s' "$tools/bin"
1573 # Tell the packages manager where to find packages.
1574 _ 'Packages DB : %s' "$root$DB"
1575 mkdir -p $root$INSTALLED
1576 cd $root$DB; rm -f *.bak
1577 for list in packages.list packages.desc packages.equiv packages.md5; do
1578 rm -f $list
1579 ln -s $SLITAZ/packages/$list $list
1580 done
1581 # We must have the cross compiled glibc-base installed or default
1582 # i486 package will be used as dep by tazpkg and then break the
1583 # cross environment
1584 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1585 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1586 fi
1587 # Show GCC version or warn if not yet compiled.
1588 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1589 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1590 else
1591 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1592 _ 'Run "%s" to cook a toolchain' 'cross compile'
1593 fi
1594 footer ;;
1596 test)
1597 # Test a cook environment.
1598 _ 'Cook test: testing the cook environment' | log
1599 [ ! -d "$WOK" ] && exit 1
1600 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1601 cook cooktest ;;
1603 new)
1604 # Create the package folder and an empty receipt.
1605 pkg="$2"
1606 [ -z "$pkg" ] && usage
1607 newline
1608 if [ -d "$WOK/$pkg" ]; then
1609 _ 'Package "%s" already exists.' "$pkg"
1610 exit 1
1611 fi
1613 action 'Creating folder "%s"' "$WOK/$pkg"
1614 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1616 action 'Preparing the package receipt...'
1617 cp $DATA/receipt .
1618 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1619 status; newline
1621 # Interactive mode, asking and seding.
1622 case "$3" in
1623 --interactive|-x)
1624 _ 'Entering interactive mode...'
1625 separator
1626 _ 'Package : %s' "$pkg"
1628 _n 'Version : ' ; read answer
1629 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1631 _n 'Category : ' ; read answer
1632 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1634 # L10n: Short description
1635 _n 'Short desc : ' ; read answer
1636 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1638 _n 'Maintainer : ' ; read answer
1639 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1641 _n 'License : ' ; read answer
1642 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1644 _n 'Web site : ' ; read answer
1645 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1646 newline
1648 # Wget URL.
1649 _ 'Wget URL to download source tarball.'
1650 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1651 _n 'Wget url : ' ; read answer
1652 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1654 # Ask for a stuff dir.
1655 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1656 if [ "$?" -eq 0 ]; then
1657 action 'Creating the stuff directory...'
1658 mkdir $WOK/$pkg/stuff; status
1659 fi
1661 # Ask for a description file.
1662 confirm "$(_n 'Are you going to write a description? (y/N)')"
1663 if [ "$?" -eq 0 ]; then
1664 action 'Creating the "%s" file...' 'description.txt'
1665 touch $WOK/$pkg/description.txt; status
1666 fi
1668 footer "$(_ 'Receipt is ready to use.')" ;;
1669 esac ;;
1671 list)
1672 # Cook a list of packages (better use the Cooker since it will order
1673 # packages before executing cook).
1674 check_root
1675 if [ -z "$2" ]; then
1676 newline; _ 'No list in argument.'; newline
1677 exit 1
1678 fi
1679 if [ ! -f "$2" ]; then
1680 newline; _ 'List "%s" not found.' "$2"; newline
1681 exit 1
1682 fi
1684 _ 'Starting cooking the list "%s"' "$2" | log
1686 for pkg in $(cat $2); do
1687 cook $pkg || broken
1688 done ;;
1690 clean-wok)
1691 check_root
1692 newline; action 'Cleaning all packages files...'
1693 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1694 status; newline ;;
1696 clean-src)
1697 check_root
1698 newline; action 'Cleaning all packages sources...'
1699 rm -rf $WOK/*/source
1700 status; newline ;;
1702 uncook)
1703 cd $WOK
1704 count=0
1705 title 'Checking for uncooked packages'
1707 for pkg in *; do
1708 unset HOST_ARCH EXTRAVERSION
1709 [ ! -e $pkg/receipt ] && continue
1710 . $pkg/receipt
1711 # Source cooked pkg receipt to get EXTRAVERSION
1712 if [ -d "$WOK/$pkg/taz" ]; then
1713 cd $WOK/$pkg/taz/$pkg-*
1714 . receipt; cd $WOK
1715 fi
1716 case "$ARCH" in
1717 i486)
1718 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1719 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1720 count=$(($count + 1))
1721 colorize 34 "$pkg"
1722 fi ;;
1723 arm*)
1724 # Check only packages included in arch
1725 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1726 # *.tazpkg
1727 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1728 count=$(($count + 1))
1729 colorize 34 "$pkg"
1730 fi
1731 fi ;;
1732 esac
1733 done
1735 if [ "$count" -gt "0" ]; then
1736 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1737 else
1738 _ 'All packages are cooked :-)'
1739 newline
1740 fi
1741 ;;
1743 pkgdb)
1744 # Create suitable packages list for TazPKG and only for built packages
1745 # as well as flavors files for TazLiTo. We dont need logs since we do it
1746 # manually to ensure everything is fine before syncing the mirror.
1748 rm $LOGS/pkgdb.log 2>/dev/null
1750 case "$2" in
1751 --flavors|--rmpkg) ;;
1752 *)
1753 [ -n "$2" ] && PKGS="$2"
1754 if [ ! -d "$PKGS" ]; then
1755 { newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline; } | dblog
1756 exit 1
1757 fi ;;
1758 esac
1760 time=$(date +%s)
1761 flavors="$SLITAZ/flavors"
1762 live="$SLITAZ/live"
1764 echo 'cook:pkgdb' > $command
1765 _ 'Cook pkgdb: Creating all packages lists' | log
1766 newline; { _ 'Creating lists for "%s"' "$PKGS"; separator; } | dblog
1768 { _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"; newline; } | dblog
1770 cd $PKGS
1771 rm -f packages.* extra.list
1772 touch packages.equiv
1774 _n 'Creating file "%s"' 'packages.list' | dblog
1775 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1776 echo " ($(filesize $PKGS/packages.list))" | dblog
1778 _n 'Creating file "%s"' 'packages.md5' | dblog
1779 md5sum *.tazpkg > $PKGS/packages.md5
1780 echo " ($(filesize $PKGS/packages.md5))" | dblog
1781 cp $PKGS/packages.md5 $PKGS/packages.toremove # list of duplicates
1783 md5sum packages.md5 | cut -d' ' -f1 > ID
1784 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
1786 _n 'Creating file "%s"' 'descriptions.txt' | dblog
1787 rm $PKGS/descriptions.txt 2>/dev/null
1788 for i in $(ls $WOK | sort); do
1789 if [ -e "$WOK/$i/description.txt" ]; then
1790 echo "$i" >> descriptions.txt
1791 cat "$WOK/$i/description.txt" | sed 's|^$| |' >> descriptions.txt
1792 echo >> descriptions.txt
1793 fi
1794 done
1795 echo " ($(filesize $PKGS/descriptions.txt))" | dblog
1798 _ 'Creating lists from "%s"' "$WOK" | dblog
1799 cd $WOK
1800 for pkg in *; do
1801 unset_receipt
1802 . $pkg/receipt
1803 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1804 [ -s $pkg/taz/*/receipt ] && . $pkg/taz/*/receipt
1806 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ] || \
1807 [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1809 # packages.desc lets us search easily in DB
1810 cat >> $PKGS/packages.desc <<EOT
1811 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1812 EOT
1814 # packages.txt used by tazpkg and tazpkg-web also to provide
1815 # a human readable package list with version and description.
1816 cat >> $PKGS/packages.txt <<EOT
1817 $PACKAGE
1818 $VERSION$EXTRAVERSION
1819 $SHORT_DESC
1820 $PACKED_SIZE ($UNPACKED_SIZE installed)
1822 EOT
1824 # packages.info combines TazPkg separate files
1825 # and will substitute them all
1826 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1827 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1828 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
1829 cat >> $PKGS/packages.info <<EOT
1830 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
1831 EOT
1833 # packages.equiv is used by tazpkg install to check depends.
1834 for i in $PROVIDE; do
1835 DEST=''
1836 echo $i | fgrep -q : && DEST="${i#*:}:"
1837 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1838 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1839 $PKGS/packages.equiv
1840 else
1841 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1842 fi
1843 done
1845 # files.list provides a list of all packages files.
1846 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1847 $PKGS/files.list
1849 # list of duplicates
1850 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
1851 else
1852 # if receipt variable HOST_ARCH absent/empty or contains ARCH
1853 if [ -z "$HOST_ARCH" -o "${HOST_ARCH/$ARCH/}" != "$HOST_ARCH" ]; then
1854 _ ' - absent: %s (%s)' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ARCH" | dblog
1855 fi
1856 fi
1857 done
1859 # Display list size.
1860 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)" | dblog
1861 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)" | dblog
1862 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)" | dblog
1863 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)" | dblog
1865 cd $PKGS
1868 # Check package duplicates
1869 if [ -s "$PKGS/packages.toremove" ]; then
1870 newline | dblog
1871 _ 'Removing duplicates:' | dblog
1872 while read pkgsum pkgfile; do
1873 echo " - $pkgfile" | dblog
1874 sed -i "/${pkgfile%.tazpkg}/d" $PKGS/packages.list
1875 sed -i "/ $pkgfile/d" $PKGS/packages.md5
1876 [ -n "$rmpkg" ] && rm $PKGS/$pkgfile # remove packages only with --rmpkg
1877 done < $PKGS/packages.toremove
1878 newline | dblog
1879 fi
1880 rm $PKGS/packages.toremove
1883 # files.list.lzma
1884 _n 'Creating file "%s"' 'files.list.lzma' | dblog
1885 touch files.list
1886 # pkgs.slitaz.org strongly depends on list sorted by packages names
1887 lzma e files.list files.list.lzma
1888 echo " ($(filesize $PKGS/files.list.lzma))" | dblog
1890 # Pre-sorting filenames causes 10% smaller resulting lzma file
1891 _n 'Creating file "%s"' 'files-list.lzma' | dblog
1892 cat files.list | sort -k2 -o files.list.sorted
1893 lzma e files.list.sorted files-list.lzma
1894 rm -f files.list files.list.sorted
1895 echo " ($(filesize $PKGS/files-list.lzma))" | dblog
1897 [ -e files.list.md5 ] && rm files.list.md5
1898 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
1900 # packages.info.lzma
1901 PI=packages.info
1902 _n 'Creating file "%s"' 'packages.info.lzma' | dblog
1903 touch $PI
1904 lzma e $PI $PI.lzma
1905 echo " ($(filesize $PKGS/packages.info.lzma))" | dblog
1907 # Make bundle to fast recharge
1908 _n 'Creating file "%s"' 'bundle.tar.lzma' | dblog
1909 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
1910 # Make sure to get "mirrors" file
1911 until [ -e 'mirrors' ]; do
1912 wget -q http://mirror1.slitaz.org/mirrors
1913 echo -n '.' | dblog; sleep 5
1914 done
1915 # Make sure to get "extra.list" file
1916 until [ -e 'extra.list' ]; do
1917 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
1918 echo -n '.' | dblog; sleep 5
1919 done
1920 busybox tar -chaf bundle.tar.lzma \
1921 mirrors extra.list files-list.md5 packages.info descriptions.txt \
1922 packages.desc packages.md5 packages.txt packages.list packages.equiv
1923 rm ./mirrors
1924 echo " ($(filesize $PKGS/bundle.tar.lzma))" | dblog
1926 # Display some info.
1927 separator | dblog
1928 nb=$(ls $PKGS/*.tazpkg | wc -l)
1929 time=$(($(date +%s) - $time))
1930 # L10n: 's' is for seconds (cooking time)
1931 { _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline; } | dblog
1934 # Create all flavors files at once. Do we really need code to monitor
1935 # flavors changes? Lets just build them with packages lists before
1936 # syncing the mirror.
1937 [ "$2" != '--flavors' ] && exit 1
1939 if [ ! -d "$flavors" ]; then
1940 { _ 'Missing flavors folder "%s"' "$flavors"; newline; } | dblog
1941 exit 1
1942 fi
1944 [ ! -d "$live" ] && mkdir -p $live
1945 _ 'Creating flavors files in "%s"' "$live" | dblog
1946 _ 'Cook pkgdb: Creating all flavors' | log
1947 separator | dblog
1949 _ 'Recharging lists to use latest packages...' | dblog
1950 tazpkg recharge >/dev/null 2>/dev/null
1952 # We need a custom tazlito config to set working dir to /home/slitaz.
1953 if [ ! -f "$live/tazlito.conf" ]; then
1954 _ 'Creating configuration file "%s"' 'tazlito.conf' | dblog
1955 cp /etc/tazlito/tazlito.conf $live
1956 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1957 $live/tazlito.conf
1958 fi
1960 # Update Hg flavors repo and pack.
1961 if [ -d "$flavors/.hg" ]; then
1962 cd $flavors; hg pull -u
1963 fi
1965 cd $live
1966 _ 'Starting to generate flavors...' | dblog
1967 rm -f flavors.list *.flavor
1968 for i in $flavors/*; do
1969 fl=$(basename $i)
1970 _ 'Packing flavor "%s"' "$fl" | dblog
1971 tazlito pack-flavor $fl >/dev/null || exit 1
1972 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
1973 done
1974 cp -f $live/*.flavor $live/flavors.list $PKGS
1975 separator | dblog
1976 { _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline; } | dblog
1977 rm -f $command
1978 separator | dblog
1979 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" | dblog
1980 ;;
1982 *)
1983 # Just cook and generate a package.
1984 check_root
1985 time=$(date +%s)
1986 pkg="$1"
1987 [ -z "$pkg" ] && usage
1988 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1989 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
1990 receipt="$WOK/$pkg/receipt"
1991 check_pkg_in_wok
1992 newline
1994 unset inst
1995 unset_receipt
1996 . $receipt
1998 # Handle cross compilation.
1999 case "$ARCH" in
2000 arm*)
2001 if [ -z "$HOST_ARCH" ]; then
2002 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
2003 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
2004 _ 'cook: %s' "$error"
2005 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2006 _ 'Cook skip: %s' "$error" | log
2007 newline
2008 exit 1
2009 fi ;;
2010 esac
2012 # Some packages are not included in some arch or fail to cross compile.
2013 : ${HOST_ARCH=i486}
2014 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
2015 # Handle arm{v6hf,v7,..}
2016 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
2017 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
2018 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
2019 _ 'cook: %s' "error"
2020 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2021 _ 'Cook skip: %s' "$error" | log
2022 sed -i /^${pkg}$/d $broken
2023 newline
2024 exit 0
2025 fi
2027 # Skip blocked, 3 lines also for the Cooker.
2028 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
2029 _ 'Package "%s" is blocked' "$pkg"; newline
2030 exit 0
2031 fi
2033 try_aufs_chroot "$@"
2035 # Log and source receipt.
2036 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
2037 echo "cook:$pkg" > $command
2038 [ "$lastcooktime" ] &&
2039 echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
2040 while read cmd duration start; do
2041 [ $(($start + $duration)) -lt $(date +%s) ] &&
2042 echo "sed -i '/^$cmd $duration/d' $cooktime"
2043 done < $cooktime | sh
2045 # Display and log info if cook process stopped.
2046 # FIXME: gettext not working (in single quotes) here!
2047 trap '_ "\n\nCook stopped: control-C\n\n" | \
2048 tee -a $LOGS/$pkg.log' INT
2050 # Handle --options
2051 case "$2" in
2052 --clean|-c)
2053 action 'Cleaning "%s"' "$pkg"
2054 cd $WOK/$pkg; rm -rf install taz source
2055 status; newline
2056 exit 0 ;;
2058 --install|-i)
2059 inst='yes' ;;
2061 --getsrc|-gs)
2062 title 'Getting source for "%s"' "$pkg"
2063 get_source
2064 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
2065 exit 0 ;;
2067 --block|-b)
2068 action 'Blocking package "%s"' "$pkg"
2069 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
2070 status; newline
2071 exit 0 ;;
2073 --unblock|-ub)
2074 action 'Unblocking package "%s"' "$pkg"
2075 sed -i "/^${pkg}$/"d $blocked
2076 status; newline
2077 exit 0 ;;
2079 --pack)
2080 if [ -d $WOK/$pkg/taz ]; then
2081 rm -rf $WOK/$pkg/taz
2082 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
2083 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
2084 clean_log
2085 else
2086 _ 'Need to build "%s"' "$pkg"
2087 exit 0
2088 fi
2089 exit 0 ;;
2091 --cdeps)
2092 if [ ! -d $WOK/$pkg/taz ]; then
2093 _ 'Need to build "%s"' "$pkg"
2094 exit 0
2095 fi
2097 title 'Checking depends'
2098 lddlist='/tmp/lddlist'; touch $lddlist
2099 missing='/var/cache/missing.file'
2101 # find all deps using ldd
2102 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
2103 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
2104 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
2105 done #"
2107 # remove exe/so duplicates
2108 sort -u $lddlist > $lddlist.sorted
2110 # search packages
2111 for exefile in $(cat $lddlist.sorted); do
2112 search_file $exefile
2113 echo "$found" >> $lddlist.pkgs
2114 echo -n '.'
2115 done
2116 echo
2118 # remove packages duplicates
2119 sort -u $lddlist.pkgs > $lddlist.final
2120 sort -u $missing > $missing.final
2121 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
2122 exit 0 ;;
2123 esac
2125 # Rotate log
2126 for i in $(seq 9 -1 1); do
2127 j=$(($i - 1))
2128 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2129 done
2130 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2132 # Check if wanted is built now so we have separate log files.
2133 for wanted in $WANTED ; do
2134 if grep -q "^$wanted$" $blocked; then
2135 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
2136 newline
2137 rm -f $command
2138 exit 1
2139 fi
2140 if grep -q "^$wanted$" $broken; then
2141 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
2142 newline
2143 rm -f $command
2144 exit 1
2145 fi
2146 if [ ! -d "$WOK/$wanted/install" ]; then
2147 cook "$wanted" || exit 1
2148 fi
2149 done
2151 # Cook and pack or exit on error and log everything.
2152 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
2153 remove_deps | tee -a $LOGS/$pkg.log
2154 cookit_quality
2155 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2156 clean_log
2158 # Exit if any error in packing.
2159 lerror=$(_n 'ERROR')
2160 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2161 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2162 debug_info | tee -a $LOGS/$pkg.log
2163 rm -f $command
2164 exit 1
2165 fi
2167 # Create an XML feed
2168 gen_rss
2170 # Time and summary
2171 time=$(($(date +%s) - $time))
2172 summary | tee -a $LOGS/$pkg.log
2173 newline
2175 # We may want to install/update (outside aufs jail !).
2176 [ -s /aufs-umount.sh ] ||
2177 install_package
2179 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2180 # You want automation: use the Cooker Build Bot.
2181 rm -f $command ;;
2182 esac
2184 exit 0