cookutils view cook @ rev 836

cook: add compress_ui()
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Nov 14 16:58:35 2016 +0200 (2016-11-14)
parents 60a7e8dec37c
children 275599c3423c
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 local time=$(($2 - $1))
523 local saving=$(( ($3 - $4) / 1024 ))
524 _ ' Time: %s. Size: %s B -> %s B. Save: %s KB' "$(disp_time $time)" "$3" "$4" "$saving"
525 }
528 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
529 # as removing unneeded files like in Python packages. Cross compiled binaries
530 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
531 # Stripping can be disabled with COOKOPTS="!strip"
533 strip_package() {
534 [ "${COOKOPTS/!strip/}" != "$COOKOPTS" ] && return
536 case "$ARCH" in
537 arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
538 *) export STRIP='strip' ;;
539 esac
540 action 'Executing strip on all files...'
541 local size0=0 size1=0 oldsize newsize
542 local time0=$(date +%s)
544 # Strip executable files
545 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
546 if [ -d "$dir" ]; then
547 oldsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
548 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
549 newsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
550 size0=$((size0 + oldsize)); size1=$((size1 + newsize))
551 fi
552 done
554 # Strip shared and static libraries
555 # Remove Python *.pyc and *.pyo, Perl perllocal.pod and .packlist
556 oldsize=$(find $fs -type f \( \
557 -name '*.so*' -o -name '*.a' -o \
558 -name '*.pyc' -o -name '*.pyo' -o \
559 -name 'perllocal.pod' -o -name '.packlist' \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
561 find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
562 find $fs -name '*.a' -exec $STRIP --strip-debug '{}' 2>/dev/null \;
563 find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
564 find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \) -delete 2>/dev/null
566 newsize=$(find $fs -type f \( \
567 -name '*.so*' -o -name '*.a' -o \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
569 size0=$((size0 + oldsize)); size1=$((size1 + newsize))
571 local time1=$(date +%s)
572 status
573 comp_summary "$time0" "$time1" "$size0" "$size1"
574 }
577 # Update installed.cook.diff
579 update_installed_cook_diff() {
580 # If a cook failed deps are removed.
581 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
582 cd $CACHE
583 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
584 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
585 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
586 }
589 # Remove installed deps.
591 remove_deps() {
592 # Now remove installed build deps.
593 diff='/tmp/installed.cook.diff'
594 if [ -s $diff ]; then
595 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
596 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
597 _n 'Build dependencies to remove:'; echo " $nb"
598 [ -n "$root" ] && echo "root=\"$root\""
599 _n 'Removing:'
600 for dep in $deps; do
601 echo -n " $dep"
602 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
603 done
604 newline; newline
605 # Keep the last diff for debug and info.
606 mv -f $diff $CACHE/installed.diff
607 fi
608 }
611 # Function to compress all man pages
612 # Compressing can be disabled with COOKOPTS="!manz"
614 compress_manpages() {
615 [ "${COOKOPTS/!manz/}" != "$COOKOPTS" ] && return
617 case "$ARCH" in
618 arm*) return;; # While SliTaz-arm miss `advancecomp`
619 esac
620 # Don't compress man pages for splitted packages
621 [ -n "$WANTED" ] && return
622 local manpath="$install/usr/share/man" dest link
623 [ -d "$manpath" ] || return
625 action 'Compressing man pages...'
627 local size0=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
628 local time0=$(date +%s)
629 # We'll use only Gzip compression, so decompress other formats first
630 find $manpath -type f -name '*.bz2' -exec bunzip2 \{\} \;
631 find $manpath -type f -name '*.xz' -exec unxz \{\} \;
633 # Fast compress with gzip
634 find $manpath -type f -name '*.[1-9]' -exec gzip \{\} \;
636 # Fix symlinks
637 for i in $(find $install/usr/share/man -type l); do
638 dest=$(readlink $i | sed 's|\.[gbx]z2*$||')
639 link=$(echo $i | sed 's|\.[gbx]z2*$||')
640 rm $i; ln -s $dest.gz $link.gz
641 done
643 # Recompress with advdef (it can't compress, only recompress)
644 tazpkg -gi advancecomp --quiet
645 for i in $(find $install/usr/share/man -type f); do
646 advdef -z4q $i
647 done
649 local size1=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
650 local time1=$(date +%s)
651 status
652 comp_summary "$time0" "$time1" "$size0" "$size1"
653 }
656 # Function used after compile_rules() to compress all png images
657 # Compressing can be disabled with COOKOPTS="!pngz"
659 cook_compress_png() {
660 [ "${COOKOPTS/!pngz/}" != "$COOKOPTS" ] && return
661 case "$ARCH" in
662 arm*) return;; # While SliTaz-arm miss `pngquant` and `optipng`
663 esac
664 [ -z "$(find $install -type f -name '*.png')" ] && return
666 action 'Compressing png images...'
667 local size0=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
668 local time0=$(date +%s)
670 local use_pq=true use_op=true
671 [ "${COOKOPTS/!pngquant/}" != "$COOKOPTS" ] && use_pq=false
672 [ "${COOKOPTS/!optipng/}" != "$COOKOPTS" ] && use_op=false
674 $use_pq && tazpkg -gi pngquant --quiet
675 $use_op && tazpkg -gi optipng --quiet
677 local oplevel=$(echo $COOKOPTS | grep 'op[0-8]' | sed 's|.*op\([0-8]\).*|\1|')
678 [ -z "$oplevel" ] && oplevel='2'
679 [ "$oplevel" == '8' ] && oplevel='7 -zm1-9'
681 for i in $(find $install -type f -name '*.png'); do
682 $use_pq && pngquant -f --skip-if-larger --ext .png --speed 1 "$i"
683 $use_op && optipng -quiet -strip all -o$oplevel "$i"
684 done
686 local size1=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
687 local time1=$(date +%s)
688 status
689 comp_summary "$time0" "$time1" "$size0" "$size1"
690 }
693 # Function used after compile_rules() to compress all svg images
694 # Compressing can be disabled with COOKOPTS="!svgz"
696 cook_compress_svg() {
697 [ "${COOKOPTS/!svgz/}" != "$COOKOPTS" ] && return
698 case "$ARCH" in
699 arm*) return;; # While SliTaz-arm miss `svgcleaner`
700 esac
701 [ -z "$(find $install -type f -name '*.svg')" ] && return
703 action 'Compressing svg images...'
704 local size0=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
705 local time0=$(date +%s)
706 tazpkg -gi svgcleaner --quiet
707 cleaner_log="$(mktemp)"
708 for i in $(find $install -type f -name '*.svg'); do
709 echo -n "$i: " >> "$cleaner_log"
710 svgcleaner "$i" "$i" --remove-unresolved-classes false --quiet true >> "$cleaner_log"
711 done
712 local size1=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
713 local time1=$(date +%s)
714 status
715 comp_summary "$time0" "$time1" "$size0" "$size1"
716 sed -i '/: $/d' "$cleaner_log"
717 if [ -s "$cleaner_log" ]; then
718 echo 'Cleaner warnings and errors:'
719 awk '{printf " %s\n", $0;}' "$cleaner_log"
720 echo
721 fi
722 rm "$cleaner_log"
723 }
726 # Function used after compile_rules() to shrink all *.ui and *.glade files:
727 # remove insignificant spaces and comments
728 # Compressing can be disabled with COOKOPTS="!uiz"
730 compress_ui() {
731 [ "${COOKOPTS/!uiz/}" != "$COOKOPTS" ] && return
732 case "$ARCH" in
733 arm*) return;; # While SliTaz-arm miss `xmlstarlet`
734 esac
735 [ -z "$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) )" ] && return
737 action 'Compressing ui files...'
738 local size0=$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
739 local time0=$(date +%s)
740 tazpkg -gi xmlstarlet --quiet
741 temp_ui="$(mktemp)"
742 for ui in $(find $install -type f \( -name '*.ui' -o -name '*.glade' \) ); do
743 xmlstarlet c14n --without-comments "$ui" | xmlstarlet sel -B -t -c '*' > "$temp_ui"
744 cat "$temp_ui" > "$ui"
745 done
746 local size1=$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
747 local time1=$(date +%s)
748 status
749 comp_summary "$time0" "$time1" "$size0" "$size1"
750 rm "$temp_ui"
751 }
754 # The main cook function.
756 cookit() {
757 title 'Cook: %s' "$PACKAGE $VERSION"
758 set_paths
760 # Handle cross-tools.
761 case "$ARCH" in
762 arm*|x86_64)
763 # CROSS_COMPILE is used by at least Busybox and the kernel to set
764 # the cross-tools prefix. Sysroot is the root of our target arch
765 sysroot="$CROSS_TREE/sysroot"
766 tools="$CROSS_TREE/tools"
767 # Set root path when cross compiling. ARM tested but not x86_64
768 # When cross compiling we must install build deps in $sysroot.
769 arch="-$ARCH"
770 root="$sysroot"
771 _ '%s sysroot: %s' "$ARCH" "$sysroot"
772 _ 'Adding "%s" to PATH' "$tools/bin"
773 export PATH="$PATH:$tools/bin"
774 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
775 export CROSS_COMPILE="$HOST_SYSTEM-"
776 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
777 if [ "$ARCH" == 'x86_64' ]; then
778 export CC="$HOST_SYSTEM-gcc -m64"
779 export CXX="$HOST_SYSTEM-g++ -m64"
780 else
781 export CC="$HOST_SYSTEM-gcc"
782 export CXX="$HOST_SYSTEM-g++"
783 fi
784 export AR="$HOST_SYSTEM-ar"
785 export AS="$HOST_SYSTEM-as"
786 export RANLIB="$HOST_SYSTEM-ranlib"
787 export LD="$HOST_SYSTEM-ld"
788 export STRIP="$HOST_SYSTEM-strip"
789 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
790 esac
792 [ -n "$QA" ] && receipt_quality
793 cd $pkgdir
794 [ -z "$continue" ] && rm -rf source 2>/dev/null
795 rm -rf install taz 2>/dev/null
797 # Disable -pipe if less than 512Mb free RAM.
798 free=$(free | awk '/buffers:/{print $4}')
799 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
800 _ 'Disabling -pipe compile flag: %d RAM free' "$free"
801 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
802 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
803 fi
804 unset free
806 # Export flags and path to be used by make and receipt.
807 DESTDIR="$pkgdir/install"
808 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
809 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
810 #LDFLAGS
812 # Check for build deps and handle implicit depends of *-dev packages
813 # (ex: libusb-dev :: libusb).
814 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
815 touch $CACHE/installed.local $CACHE/installed.web
816 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
817 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
818 for dep in $BUILD_DEPENDS; do
819 implicit="${dep%-dev}"
820 # Don't add implicit dependency if it defined in DEPENDS
821 # echo '' $DEPENDS '' | fgrep -q " $implicit " && implicit=''
822 for i in $dep $implicit; do
823 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
824 # Try local package first. In some cases implicit doesn't exist, ex:
825 # libboost-dev exists but not libboost, so check if we got vers.
826 unset vers
827 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
828 # We may have a local package.
829 if [ -z "$vers" ]; then
830 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info 2> /dev/null)
831 fi
832 debug "bdep: $i version: $vers"
833 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
834 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
835 else
836 # Priority to package version in wok (maybe more up-to-date)
837 # than the mirrored one.
838 if [ -n "$vers" ]; then
839 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
840 echo $i >> $CACHE/installed.web
841 else
842 # So package exists in wok but not available.
843 _ 'Missing dep (wok/pkg): %s' "$i $vers"
844 echo $i >> $CACHE/missing.dep
845 fi
846 else
847 # Package is not in wok but may be in online repo.
848 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
849 echo $i >> $CACHE/installed.web
850 else
851 _ 'ERROR: unknown dep "%s"' "$i"
852 exit 1
853 fi
854 fi
855 fi
856 fi
857 done
858 done
860 # Get the list of installed packages
861 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
863 # Have we a missing build dep to cook?
864 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
865 _ 'Auto cook config is set: %s' "$AUTO_COOK"
866 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
867 for i in $(uniq $CACHE/missing.dep); do
868 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
869 tee -a $LOGS/$PACKAGE.log.$$
870 # programmers: next two messages are exact copy from remove_deps()
871 togrep1=$(_n 'Build dependencies to remove:')
872 togrep2=$(_n 'Removing:')
873 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
874 fgrep $togrep1 $LOGS/$i.log && \
875 fgrep $togrep2 $LOGS/$i.log && newline) | \
876 tee -a $LOGS/$PACKAGE.log.$$ && break
877 done
878 rm -f $CACHE/missing.dep
879 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
880 fi
882 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
883 # is enabled and cook fails we have ERROR in log, if no auto cook we have
884 # missing dep in cached file.
885 lerror=$(_n 'ERROR')
886 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
887 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
888 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
889 exit 1
890 fi
892 # Install local packages: package-version$arch
893 cd $PKGS
894 for i in $(uniq $CACHE/installed.local); do
895 _ 'Installing dep (pkg/local): %s' "$i"
896 tazpkg install $i --root=$root --local --quiet
897 done
899 # Install web or cached packages (if mirror is set to $PKGS we only
900 # use local packages).
901 for i in $(uniq $CACHE/installed.web); do
902 _ 'Installing dep (web/cache): %s' "$i"
903 tazpkg get-install $i --root=$root --quiet
904 done
906 update_installed_cook_diff
908 # Get source tarball and make sure we have source dir named:
909 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
910 # tarball if it exists.
911 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
912 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
913 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
914 LZMA_SRC=''
915 else
916 get_source || exit 1
917 fi
918 fi
919 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
920 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
921 if ! extract_source ; then
922 get_source
923 extract_source || exit 1
924 fi
925 if [ -n "$LZMA_SRC" ]; then
926 cd $pkgdir/source
927 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
928 mv tmp tmp-1; mkdir tmp
929 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
930 fi
931 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
932 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
933 fi
934 fi
935 cd $pkgdir/source/tmp
936 # Some archives are not well done and don't extract to one dir (ex lzma).
937 files=$(ls | wc -l)
938 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
939 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
940 mv * ../$PACKAGE-$VERSION/$TARBALL
941 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
942 mv * ../$PACKAGE-$VERSION
943 cd ..; rm -rf tmp
944 fi
946 # Libtool shared libs path hack.
947 case "$ARCH" in
948 arm*) cross libhack ;;
949 esac
951 # Execute receipt rules.
952 if grep -q ^compile_rules $receipt; then
953 _ 'Executing: %s' 'compile_rules'
954 echo "CFLAGS : $CFLAGS"
955 #echo "LDFLAGS : $LDFLAGS"
956 [ -d "$src" ] && cd $src
957 compile_rules $@ || exit 1
958 # Stay compatible with _pkg
959 [ -d "$src/_pkg" ] && mv $src/_pkg $install
960 # QA: compile_rules success so valid.
961 mkdir -p $install
962 else
963 # QA: no compile_rules so no error, valid.
964 mkdir -p $install
965 fi
967 # Actions to do after compiling the package
968 footer
969 compress_manpages
970 cook_compress_png
971 cook_compress_svg
972 compress_ui
973 footer
975 # Execute testsuite.
976 if grep -q ^testsuite $receipt; then
977 title 'Running testsuite'
978 testsuite $@ || exit 1
979 footer
980 fi
982 fix_desktop_files
984 update_installed_cook_diff force
985 }
988 # Cook quality assurance.
990 cookit_quality() {
991 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
992 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
993 fi
994 # ERROR can be echoed any time in cookit()
995 lerror=$(_n 'ERROR')
996 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
997 grep -Eq "(^$lerror|undefined reference to)" ; then
998 debug_info | tee -a $LOGS/$pkg.log
999 rm -f $command
1000 exit 1
1001 fi
1005 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
1006 # but it doesn't handle EXTRAVERSION.
1008 packit() {
1009 set_paths
1011 # Handle cross compilation
1012 case "$ARCH" in
1013 arm*|x86_64) arch="-$ARCH" ;;
1014 esac
1016 title 'Pack: %s' "$PACKAGE $VERSION$arch"
1018 if grep -q ^genpkg_rules $receipt; then
1019 _ 'Executing: %s' 'genpkg_rules'
1020 set -e; cd $pkgdir; mkdir -p $fs
1021 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
1022 $LOGS/$pkg.log
1023 else
1024 _ 'No packages rules: meta package'
1025 mkdir -p $fs
1026 fi
1028 # First QA check to stop now if genpkg_rules failed.
1029 lerror=$(_n 'ERROR')
1030 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1031 exit 1
1032 fi
1034 cd $taz
1035 for file in receipt description.txt; do
1036 [ ! -f "../$file" ] && continue
1037 action 'Copying "%s"...' "$file"
1038 cp -f ../$file $pack; chown 0.0 $pack/$file; status
1039 done
1040 copy_generic_files
1042 # Strip and stuff files.
1043 strip_package
1045 # Create files.list with redirecting find output.
1046 action 'Creating the list of files...'
1047 cd $fs
1048 find . -type f -print > ../files.list
1049 find . -type l -print >> ../files.list
1050 cd ..; sed -i s/'^.'/''/ files.list
1051 status
1053 # Md5sum of files.
1054 action 'Creating md5sum of files...'
1055 while read file; do
1056 [ -L "fs$file" ] && continue
1057 [ -f "fs$file" ] || continue
1058 case "$file" in
1059 /lib/modules/*/modules.*|*.pyc) continue ;;
1060 esac
1061 md5sum "fs$file" | sed 's/ fs/ /'
1062 done < files.list > md5sum
1063 status
1065 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1066 2>/dev/null | awk 'END{ print $1 }')
1068 # Build cpio archives.
1069 action 'Compressing the FS...'
1070 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1071 rm -rf fs
1072 status
1074 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
1075 2>/dev/null | awk 'END{ print $1 }')
1077 action 'Updating receipt sizes...'
1078 sed -i s/^PACKED_SIZE.*$// receipt
1079 sed -i s/^UNPACKED_SIZE.*$// receipt
1080 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1081 status
1083 # Set extra version.
1084 if [ -n "$EXTRAVERSION" ]; then
1085 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
1086 sed -i s/^EXTRAVERSION.*$// receipt
1087 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1088 status
1089 fi
1091 # Compress.
1092 action 'Creating full cpio archive...'
1093 find . -print | cpio -o -H newc --quiet > \
1094 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1095 status
1097 action 'Restoring original package tree...'
1098 unlzma -c fs.cpio.lzma | cpio -idm --quiet
1099 status
1101 rm fs.cpio.lzma; cd ..
1103 # QA and give info.
1104 tazpkg=$(ls *.tazpkg)
1105 packit_quality
1106 footer "$(_ 'Package "%s" created' "$tazpkg")"
1110 # Verify package quality and consistency.
1112 packit_quality() {
1113 #action 'QA: checking for broken link...'
1114 #link=$(find $fs/usr -type l -follow)
1115 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
1116 #status
1118 # Exit if any error found in log file.
1119 lerror=$(_n 'ERROR')
1120 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1121 rm -f $command
1122 exit 1
1123 fi
1125 action 'QA: checking for empty package...'
1126 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
1127 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
1128 newline; _ 'ERROR: empty package'
1129 rm -f $command
1130 exit 1
1131 else
1132 :; status
1133 # Find and remove old package(s)
1134 tempd="$(mktemp -d)"; cd "$tempd"
1135 for testpkg in $(ls $PKGS/$pkg-*.tazpkg 2> /dev/null); do
1136 # Extract receipt from each matched package
1137 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
1138 name=$(. receipt; echo $PACKAGE)
1139 rm receipt
1140 if [ "$name" == "$pkg" ]; then
1141 action 'Removing old package "%s"' "$(basename "$testpkg")"
1142 rm -f "$testpkg"
1143 status
1144 fi
1145 done
1146 rm -r "$tempd"
1147 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
1148 sed -i /^${pkg}$/d $broken
1149 #action 'Removing source tree...'
1150 #rm -f $WOK/$pkg/source; status
1151 fi
1155 # Reverse "cat" command: prints input lines in the reverse order
1157 tac() {
1158 sed '1!G;h;$!d' $1
1162 # Install package on --install or update the chroot.
1164 install_package() {
1165 case "$ARCH" in
1166 arm*|x86_64)
1167 arch="-$ARCH"
1168 root="$CROSS_TREE/sysroot" ;;
1169 esac
1170 # Install package if requested but skip install if target host doesn't
1171 # match build system or it will break the build chroot.
1172 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1173 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
1174 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1175 cd $PKGS
1176 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1177 else
1178 _ 'Unable to install package, build has failed.'; newline
1179 exit 1
1180 fi
1181 fi
1183 # Install package if part of the chroot to keep env up-to-date.
1184 if [ -d "$root$INSTALLED/$pkg" ]; then
1185 . /etc/slitaz/cook.conf
1186 . $WOK/$pkg/taz/$pkg-*/receipt
1187 _ 'Updating %s chroot environment...' "$ARCH"
1188 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
1189 cd $PKGS
1190 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1191 fi
1195 # remove chroot jail
1197 umount_aufs() {
1198 tac ${1}rw/aufs-umount.sh | sh
1199 rm -rf ${1}rw
1200 umount ${1}root
1201 rmdir ${1}r*
1205 # Launch the cook command into a chroot jail protected by aufs.
1206 # The current filesystems are used read-only and updates are
1207 # stored in a separate branch.
1209 try_aufs_chroot() {
1211 base="/dev/shm/aufsmnt$$"
1213 # Can we setup the chroot? Is it already done?
1214 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1215 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1216 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1217 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1218 mkdir ${base}root ${base}rw || return
1220 _ 'Setup aufs chroot...'
1222 # Sanity check
1223 for i in / /proc /sys /dev/shm /home ; do
1224 case " $AUFS_MOUNTS " in
1225 *\ $i\ *) ;;
1226 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1227 esac
1228 done
1229 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1230 mount --bind $mnt ${base}root$mnt
1231 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1232 _ 'Aufs mount failure'
1233 umount ${base}root
1234 rm -rf ${base}r*
1235 return
1236 fi
1237 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1238 done
1239 trap "umount_aufs ${base}" INT
1241 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1242 status=$?
1244 _ 'Leaving aufs chroot...'
1245 umount_aufs $base
1246 # Install package outside the aufs jail
1247 install_package
1248 exit $status
1252 # Encode predefined XML entities
1254 xml_ent() {
1255 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1259 # Create a XML feed for freshly built packages.
1261 gen_rss() {
1262 pubdate=$(date '+%a, %d %b %Y %X')
1263 cat > $FEEDS/$pkg.xml <<EOT
1264 <item>
1265 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1266 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1267 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1268 <pubDate>$pubdate</pubDate>
1269 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1270 </item>
1271 EOT
1275 # Truncate stdout log file to $1 Mb.
1277 loglimit() {
1278 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1279 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1280 else
1281 tee /dev/stderr
1282 fi
1286 # Search file in mirrored packages
1288 search_file_mirror() {
1289 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1293 # Search file in local wok packages
1295 search_file_local() {
1296 # existing packages have precedence over the package/taz folder
1297 srch=$1
1298 { for package in $(find $PKGS -name '*.tazpkg'); do
1299 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1300 grep /$srch\$)" ]; then
1301 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1302 fi
1303 done } | sort -u
1307 # Ask in multiple choice
1309 ask_multiple() {
1310 local multiples first my_choice
1311 multiples="$1"
1312 first=$(echo "$multiples" | head -n1)
1313 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1314 _ 'Select one [%s]: ' "$first"; read my_choice
1315 found="${my_choice:-$first}"
1319 # Search file in local cache (fast), local wok packages, mirrored packages
1321 search_file() {
1322 local srch cache missing
1323 srch="$1"
1324 cache='/var/cache/ldsearch.cache'
1325 missing='/var/cache/missing.file'
1326 touch $cache $missing
1327 found=$(grep $srch $cache | cut -d$'\t' -f2)
1328 if [ -z "$found" ]; then
1329 found=$(search_file_local $srch)
1330 if [ -n "$found" ]; then
1331 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1332 ask_multiple "$found"
1333 fi
1334 echo -e "$srch\t$found" >> $cache
1335 else
1336 found=$(search_file_mirror $srch)
1337 if [ -n "$found" ]; then
1338 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1339 ask_multiple "$found"
1340 fi
1341 echo -e "$srch\t$found" >> $cache
1342 else
1343 echo "$srch" >> $missing
1344 fi
1345 fi
1346 fi
1350 # Return size of file in human readible format
1351 # Note, "du" in opposite returns size occupied by file on disk (4KB multiple in most cases)
1352 filesize() {
1353 busybox ls -lh "$1" | awk '{print $5 "B"}'
1358 # Receipt functions to ease packaging
1361 get_dev_files() {
1362 action 'Getting standard devel files...'
1363 mkdir -p $fs/usr/lib
1364 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1365 cp -a $install/usr/lib/*a $fs/usr/lib
1366 cp -a $install/usr/include $fs/usr
1367 status
1371 # Function to use in compile_rules() to copy man page from $src to $install
1373 cook_pick_manpages() {
1374 local name section
1375 action 'Copying man pages...'
1377 for i in $@; do
1378 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1379 section=${name##*/}; section=${section##*.}
1380 mkdir -p $install/usr/share/man/man$section
1381 cp -a $i $install/usr/share/man/man$section
1382 done
1383 status
1387 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1389 cook_copy_files() {
1390 action 'Copying files...'
1391 cd $install
1392 local i j
1393 for i in $@; do
1394 for j in $(find . -name $i ! -type d); do
1395 mkdir -p $fs$(dirname ${j#.})
1396 cp -a $j $fs/${j#.}
1397 done
1398 done
1399 cd - >/dev/null
1400 status
1404 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1406 cook_copy_folders() {
1407 action 'Copying folders...'
1408 cd $install
1409 local i j
1410 for i in $@; do
1411 for j in $(find . -name $i -type d); do
1412 mkdir -p $fs$(dirname ${j#.})
1413 cp -a $j $fs/${j#.}
1414 done
1415 done
1416 cd - >/dev/null
1417 status
1421 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1422 # (default: 16 and 48) from $install to $fs
1424 cook_copy_icons() {
1425 local sizes=$@
1426 action 'Copying hicolor icons...'
1427 mkdir -p $fs/usr/share/icons/hicolor
1428 for i in ${sizes:-16 48}; do
1429 [ -e "$install/usr/share/icons/hicolor/${i}x$i" ] &&
1430 cp -a $install/usr/share/icons/hicolor/${i}x$i \
1431 $fs/usr/share/icons/hicolor
1432 done
1433 status
1436 dblog() { tee -a $LOGS/pkgdb.log; }
1442 # Commands
1445 case "$1" in
1446 usage|help|-u|-h)
1447 usage ;;
1449 list-wok)
1450 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1451 cd $WOK
1452 if [ "$ARCH" != 'i486' ]; then
1453 count=0
1454 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1455 do
1456 unset HOST_ARCH
1457 . $pkg
1458 count=$(($count + 1))
1459 colorize 34 "$PACKAGE"
1460 done
1461 else
1462 count=$(ls | wc -l)
1463 ls -1
1464 fi
1465 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1466 ;;
1468 activity)
1469 cat $activity ;;
1471 search)
1472 # Just a simple search function, we dont need more actually.
1473 query="$2"
1474 title 'Search results for "%s"' "$query"
1475 cd $WOK; ls -1 | grep "$query"
1476 footer ;;
1478 setup)
1479 # Setup a build environment
1480 check_root
1481 _ 'Cook: setup environment' | log
1482 title 'Setting up your environment'
1483 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1484 cd $SLITAZ
1485 init_db_files
1486 _ 'Checking for packages to install...'
1487 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1488 # ARCH-setup or 'cross check' should be used before: cook setup
1489 case "$ARCH" in
1490 arm*|x86_64)
1491 if [ ! -x '/usr/bin/cross' ]; then
1492 _ 'ERROR: %s is not installed' 'cross'
1493 exit 1
1494 fi
1495 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1496 . /etc/slitaz/cross.conf ;;
1497 esac
1498 for pkg in $SETUP_PKGS; do
1499 if [ -n "$forced" ]; then
1500 tazpkg -gi $pkg --forced
1501 else
1502 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1503 fi
1504 done
1506 # Handle --options
1507 case "$2" in
1508 --wok) hg clone $WOK_URL wok || exit 1 ;;
1509 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1510 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1511 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1512 esac
1514 # SliTaz group and permissions
1515 if ! grep -q ^slitaz /etc/group; then
1516 _ 'Adding group "%s"' 'slitaz'
1517 addgroup slitaz
1518 fi
1519 _ 'Setting permissions for group "%s"...' 'slitaz'
1520 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1521 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1522 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1524 *-setup)
1525 # Setup for cross compiling.
1526 arch="${1%-setup}"
1527 check_root
1528 . /etc/slitaz/cook.conf
1529 for pkg in $CROSS_SETUP; do
1530 if [ -n "$forced" ]; then
1531 tazpkg -gi $pkg --forced
1532 else
1533 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1534 fi
1535 done
1537 _ 'Cook: setup %s cross environment' "$arch" | log
1538 title 'Setting up your %s cross environment' "$arch"
1539 init_db_files
1540 sed -i \
1541 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1542 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1543 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1544 /etc/slitaz/cook.conf
1545 case "$arch" in
1546 arm)
1547 flags='-O2 -march=armv6'
1548 host="$ARCH-slitaz-linux-gnueabi" ;;
1549 armv6hf)
1550 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1551 host="$ARCH-slitaz-linux-gnueabi" ;;
1552 armv7)
1553 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1554 host="$ARCH-slitaz-linux-gnueabi" ;;
1555 x86_64)
1556 flags='-O2 -mtune=generic -pipe'
1557 host="$ARCH-slitaz-linux" ;;
1558 esac
1559 sed -i \
1560 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1561 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1562 . /etc/slitaz/cook.conf
1563 sysroot="$CROSS_TREE/sysroot"
1564 tools="/cross/$arch/tools"
1565 root="$sysroot"
1566 # L10n: keep the same width of translations to get a consistent view
1567 _ 'Target arch : %s' "$ARCH"
1568 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1569 _ 'Build flags : %s' "$flags"
1570 _ 'Arch sysroot : %s' "$sysroot"
1571 _ 'Tools prefix : %s' "$tools/bin"
1572 # Tell the packages manager where to find packages.
1573 _ 'Packages DB : %s' "$root$DB"
1574 mkdir -p $root$INSTALLED
1575 cd $root$DB; rm -f *.bak
1576 for list in packages.list packages.desc packages.equiv packages.md5; do
1577 rm -f $list
1578 ln -s $SLITAZ/packages/$list $list
1579 done
1580 # We must have the cross compiled glibc-base installed or default
1581 # i486 package will be used as dep by tazpkg and then break the
1582 # cross environment
1583 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1584 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1585 fi
1586 # Show GCC version or warn if not yet compiled.
1587 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1588 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1589 else
1590 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1591 _ 'Run "%s" to cook a toolchain' 'cross compile'
1592 fi
1593 footer ;;
1595 test)
1596 # Test a cook environment.
1597 _ 'Cook test: testing the cook environment' | log
1598 [ ! -d "$WOK" ] && exit 1
1599 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1600 cook cooktest ;;
1602 new)
1603 # Create the package folder and an empty receipt.
1604 pkg="$2"
1605 [ -z "$pkg" ] && usage
1606 newline
1607 if [ -d "$WOK/$pkg" ]; then
1608 _ 'Package "%s" already exists.' "$pkg"
1609 exit 1
1610 fi
1612 action 'Creating folder "%s"' "$WOK/$pkg"
1613 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1615 action 'Preparing the package receipt...'
1616 cp $DATA/receipt .
1617 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1618 status; newline
1620 # Interactive mode, asking and seding.
1621 case "$3" in
1622 --interactive|-x)
1623 _ 'Entering interactive mode...'
1624 separator
1625 _ 'Package : %s' "$pkg"
1627 _n 'Version : ' ; read answer
1628 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1630 _n 'Category : ' ; read answer
1631 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1633 # L10n: Short description
1634 _n 'Short desc : ' ; read answer
1635 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1637 _n 'Maintainer : ' ; read answer
1638 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1640 _n 'License : ' ; read answer
1641 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1643 _n 'Web site : ' ; read answer
1644 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1645 newline
1647 # Wget URL.
1648 _ 'Wget URL to download source tarball.'
1649 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1650 _n 'Wget url : ' ; read answer
1651 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1653 # Ask for a stuff dir.
1654 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1655 if [ "$?" -eq 0 ]; then
1656 action 'Creating the stuff directory...'
1657 mkdir $WOK/$pkg/stuff; status
1658 fi
1660 # Ask for a description file.
1661 confirm "$(_n 'Are you going to write a description? (y/N)')"
1662 if [ "$?" -eq 0 ]; then
1663 action 'Creating the "%s" file...' 'description.txt'
1664 touch $WOK/$pkg/description.txt; status
1665 fi
1667 footer "$(_ 'Receipt is ready to use.')" ;;
1668 esac ;;
1670 list)
1671 # Cook a list of packages (better use the Cooker since it will order
1672 # packages before executing cook).
1673 check_root
1674 if [ -z "$2" ]; then
1675 newline; _ 'No list in argument.'; newline
1676 exit 1
1677 fi
1678 if [ ! -f "$2" ]; then
1679 newline; _ 'List "%s" not found.' "$2"; newline
1680 exit 1
1681 fi
1683 _ 'Starting cooking the list "%s"' "$2" | log
1685 for pkg in $(cat $2); do
1686 cook $pkg || broken
1687 done ;;
1689 clean-wok)
1690 check_root
1691 newline; action 'Cleaning all packages files...'
1692 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1693 status; newline ;;
1695 clean-src)
1696 check_root
1697 newline; action 'Cleaning all packages sources...'
1698 rm -rf $WOK/*/source
1699 status; newline ;;
1701 uncook)
1702 cd $WOK
1703 count=0
1704 title 'Checking for uncooked packages'
1706 for pkg in *; do
1707 unset HOST_ARCH EXTRAVERSION
1708 [ ! -e $pkg/receipt ] && continue
1709 . $pkg/receipt
1710 # Source cooked pkg receipt to get EXTRAVERSION
1711 if [ -d "$WOK/$pkg/taz" ]; then
1712 cd $WOK/$pkg/taz/$pkg-*
1713 . receipt; cd $WOK
1714 fi
1715 case "$ARCH" in
1716 i486)
1717 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1718 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1719 count=$(($count + 1))
1720 colorize 34 "$pkg"
1721 fi ;;
1722 arm*)
1723 # Check only packages included in arch
1724 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1725 # *.tazpkg
1726 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1727 count=$(($count + 1))
1728 colorize 34 "$pkg"
1729 fi
1730 fi ;;
1731 esac
1732 done
1734 if [ "$count" -gt "0" ]; then
1735 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1736 else
1737 _ 'All packages are cooked :-)'
1738 newline
1739 fi
1740 ;;
1742 pkgdb)
1743 # Create suitable packages list for TazPKG and only for built packages
1744 # as well as flavors files for TazLiTo. We dont need logs since we do it
1745 # manually to ensure everything is fine before syncing the mirror.
1747 rm $LOGS/pkgdb.log 2>/dev/null
1749 case "$2" in
1750 --flavors|--rmpkg) ;;
1751 *)
1752 [ -n "$2" ] && PKGS="$2"
1753 if [ ! -d "$PKGS" ]; then
1754 { newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline; } | dblog
1755 exit 1
1756 fi ;;
1757 esac
1759 time=$(date +%s)
1760 flavors="$SLITAZ/flavors"
1761 live="$SLITAZ/live"
1763 echo 'cook:pkgdb' > $command
1764 _ 'Cook pkgdb: Creating all packages lists' | log
1765 newline; { _ 'Creating lists for "%s"' "$PKGS"; separator; } | dblog
1767 { _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"; newline; } | dblog
1769 cd $PKGS
1770 rm -f packages.* extra.list
1771 touch packages.equiv
1773 _n 'Creating file "%s"' 'packages.list' | dblog
1774 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1775 echo " ($(filesize $PKGS/packages.list))" | dblog
1777 _n 'Creating file "%s"' 'packages.md5' | dblog
1778 md5sum *.tazpkg > $PKGS/packages.md5
1779 echo " ($(filesize $PKGS/packages.md5))" | dblog
1780 cp $PKGS/packages.md5 $PKGS/packages.toremove # list of duplicates
1782 md5sum packages.md5 | cut -d' ' -f1 > ID
1783 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
1785 _n 'Creating file "%s"' 'descriptions.txt' | dblog
1786 rm $PKGS/descriptions.txt 2>/dev/null
1787 for i in $(ls $WOK | sort); do
1788 if [ -e "$WOK/$i/description.txt" ]; then
1789 echo "$i" >> descriptions.txt
1790 cat "$WOK/$i/description.txt" | sed 's|^$| |' >> descriptions.txt
1791 echo >> descriptions.txt
1792 fi
1793 done
1794 echo " ($(filesize $PKGS/descriptions.txt))" | dblog
1797 _ 'Creating lists from "%s"' "$WOK" | dblog
1798 cd $WOK
1799 for pkg in *; do
1800 unset_receipt
1801 . $pkg/receipt
1802 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1803 [ -s $pkg/taz/*/receipt ] && . $pkg/taz/*/receipt
1805 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ] || \
1806 [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1808 # packages.desc lets us search easily in DB
1809 cat >> $PKGS/packages.desc <<EOT
1810 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1811 EOT
1813 # packages.txt used by tazpkg and tazpkg-web also to provide
1814 # a human readable package list with version and description.
1815 cat >> $PKGS/packages.txt <<EOT
1816 $PACKAGE
1817 $VERSION$EXTRAVERSION
1818 $SHORT_DESC
1819 $PACKED_SIZE ($UNPACKED_SIZE installed)
1821 EOT
1823 # packages.info combines TazPkg separate files
1824 # and will substitute them all
1825 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1826 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1827 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
1828 cat >> $PKGS/packages.info <<EOT
1829 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
1830 EOT
1832 # packages.equiv is used by tazpkg install to check depends.
1833 for i in $PROVIDE; do
1834 DEST=''
1835 echo $i | fgrep -q : && DEST="${i#*:}:"
1836 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1837 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1838 $PKGS/packages.equiv
1839 else
1840 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1841 fi
1842 done
1844 # files.list provides a list of all packages files.
1845 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1846 $PKGS/files.list
1848 # list of duplicates
1849 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
1850 else
1851 # if receipt variable HOST_ARCH absent/empty or contains ARCH
1852 if [ -z "$HOST_ARCH" -o "${HOST_ARCH/$ARCH/}" != "$HOST_ARCH" ]; then
1853 _ ' - absent: %s (%s)' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ARCH" | dblog
1854 fi
1855 fi
1856 done
1858 # Display list size.
1859 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)" | dblog
1860 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)" | dblog
1861 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)" | dblog
1862 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)" | dblog
1864 cd $PKGS
1867 # Check package duplicates
1868 if [ -s "$PKGS/packages.toremove" ]; then
1869 newline | dblog
1870 _ 'Removing duplicates:' | dblog
1871 while read pkgsum pkgfile; do
1872 echo " - $pkgfile" | dblog
1873 sed -i "/${pkgfile%.tazpkg}/d" $PKGS/packages.list
1874 sed -i "/ $pkgfile/d" $PKGS/packages.md5
1875 [ -n "$rmpkg" ] && rm $PKGS/$pkgfile # remove packages only with --rmpkg
1876 done < $PKGS/packages.toremove
1877 newline | dblog
1878 fi
1879 rm $PKGS/packages.toremove
1882 # files.list.lzma
1883 _n 'Creating file "%s"' 'files.list.lzma' | dblog
1884 touch files.list
1885 # pkgs.slitaz.org strongly depends on list sorted by packages names
1886 lzma e files.list files.list.lzma
1887 echo " ($(filesize $PKGS/files.list.lzma))" | dblog
1889 # Pre-sorting filenames causes 10% smaller resulting lzma file
1890 _n 'Creating file "%s"' 'files-list.lzma' | dblog
1891 cat files.list | sort -k2 -o files.list.sorted
1892 lzma e files.list.sorted files-list.lzma
1893 rm -f files.list files.list.sorted
1894 echo " ($(filesize $PKGS/files-list.lzma))" | dblog
1896 [ -e files.list.md5 ] && rm files.list.md5
1897 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
1899 # packages.info.lzma
1900 PI=packages.info
1901 _n 'Creating file "%s"' 'packages.info.lzma' | dblog
1902 touch $PI
1903 lzma e $PI $PI.lzma
1904 echo " ($(filesize $PKGS/packages.info.lzma))" | dblog
1906 # Make bundle to fast recharge
1907 _n 'Creating file "%s"' 'bundle.tar.lzma' | dblog
1908 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
1909 # Make sure to get "mirrors" file
1910 until [ -e 'mirrors' ]; do
1911 wget -q http://mirror1.slitaz.org/mirrors
1912 echo -n '.' | dblog; sleep 5
1913 done
1914 # Make sure to get "extra.list" file
1915 until [ -e 'extra.list' ]; do
1916 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
1917 echo -n '.' | dblog; sleep 5
1918 done
1919 busybox tar -chaf bundle.tar.lzma \
1920 mirrors extra.list files-list.md5 packages.info descriptions.txt \
1921 packages.desc packages.md5 packages.txt packages.list packages.equiv
1922 rm ./mirrors
1923 echo " ($(filesize $PKGS/bundle.tar.lzma))" | dblog
1925 # Display some info.
1926 separator | dblog
1927 nb=$(ls $PKGS/*.tazpkg | wc -l)
1928 time=$(($(date +%s) - $time))
1929 # L10n: 's' is for seconds (cooking time)
1930 { _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline; } | dblog
1933 # Create all flavors files at once. Do we really need code to monitor
1934 # flavors changes? Lets just build them with packages lists before
1935 # syncing the mirror.
1936 [ "$2" != '--flavors' ] && exit 1
1938 if [ ! -d "$flavors" ]; then
1939 { _ 'Missing flavors folder "%s"' "$flavors"; newline; } | dblog
1940 exit 1
1941 fi
1943 [ ! -d "$live" ] && mkdir -p $live
1944 _ 'Creating flavors files in "%s"' "$live" | dblog
1945 _ 'Cook pkgdb: Creating all flavors' | log
1946 separator | dblog
1948 _ 'Recharging lists to use latest packages...' | dblog
1949 tazpkg recharge >/dev/null 2>/dev/null
1951 # We need a custom tazlito config to set working dir to /home/slitaz.
1952 if [ ! -f "$live/tazlito.conf" ]; then
1953 _ 'Creating configuration file "%s"' 'tazlito.conf' | dblog
1954 cp /etc/tazlito/tazlito.conf $live
1955 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1956 $live/tazlito.conf
1957 fi
1959 # Update Hg flavors repo and pack.
1960 if [ -d "$flavors/.hg" ]; then
1961 cd $flavors; hg pull -u
1962 fi
1964 cd $live
1965 _ 'Starting to generate flavors...' | dblog
1966 rm -f flavors.list *.flavor
1967 for i in $flavors/*; do
1968 fl=$(basename $i)
1969 _ 'Packing flavor "%s"' "$fl" | dblog
1970 tazlito pack-flavor $fl >/dev/null || exit 1
1971 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
1972 done
1973 cp -f $live/*.flavor $live/flavors.list $PKGS
1974 separator | dblog
1975 { _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline; } | dblog
1976 rm -f $command
1977 separator | dblog
1978 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" | dblog
1979 ;;
1981 *)
1982 # Just cook and generate a package.
1983 check_root
1984 time=$(date +%s)
1985 pkg="$1"
1986 [ -z "$pkg" ] && usage
1987 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1988 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
1989 receipt="$WOK/$pkg/receipt"
1990 check_pkg_in_wok
1991 newline
1993 unset inst
1994 unset_receipt
1995 . $receipt
1997 # Handle cross compilation.
1998 case "$ARCH" in
1999 arm*)
2000 if [ -z "$HOST_ARCH" ]; then
2001 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
2002 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
2003 _ 'cook: %s' "$error"
2004 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2005 _ 'Cook skip: %s' "$error" | log
2006 newline
2007 exit 1
2008 fi ;;
2009 esac
2011 # Some packages are not included in some arch or fail to cross compile.
2012 : ${HOST_ARCH=i486}
2013 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
2014 # Handle arm{v6hf,v7,..}
2015 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
2016 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
2017 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
2018 _ 'cook: %s' "error"
2019 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2020 _ 'Cook skip: %s' "$error" | log
2021 sed -i /^${pkg}$/d $broken
2022 newline
2023 exit 0
2024 fi
2026 # Skip blocked, 3 lines also for the Cooker.
2027 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
2028 _ 'Package "%s" is blocked' "$pkg"; newline
2029 exit 0
2030 fi
2032 try_aufs_chroot "$@"
2034 # Log and source receipt.
2035 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
2036 echo "cook:$pkg" > $command
2037 [ "$lastcooktime" ] &&
2038 echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
2039 while read cmd duration start; do
2040 [ $(($start + $duration)) -lt $(date +%s) ] &&
2041 echo "sed -i '/^$cmd $duration/d' $cooktime"
2042 done < $cooktime | sh
2044 # Display and log info if cook process stopped.
2045 # FIXME: gettext not working (in single quotes) here!
2046 trap '_ "\n\nCook stopped: control-C\n\n" | \
2047 tee -a $LOGS/$pkg.log' INT
2049 # Handle --options
2050 case "$2" in
2051 --clean|-c)
2052 action 'Cleaning "%s"' "$pkg"
2053 cd $WOK/$pkg; rm -rf install taz source
2054 status; newline
2055 exit 0 ;;
2057 --install|-i)
2058 inst='yes' ;;
2060 --getsrc|-gs)
2061 title 'Getting source for "%s"' "$pkg"
2062 get_source
2063 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
2064 exit 0 ;;
2066 --block|-b)
2067 action 'Blocking package "%s"' "$pkg"
2068 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
2069 status; newline
2070 exit 0 ;;
2072 --unblock|-ub)
2073 action 'Unblocking package "%s"' "$pkg"
2074 sed -i "/^${pkg}$/"d $blocked
2075 status; newline
2076 exit 0 ;;
2078 --pack)
2079 if [ -d $WOK/$pkg/taz ]; then
2080 rm -rf $WOK/$pkg/taz
2081 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
2082 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
2083 clean_log
2084 else
2085 _ 'Need to build "%s"' "$pkg"
2086 exit 0
2087 fi
2088 exit 0 ;;
2090 --cdeps)
2091 if [ ! -d $WOK/$pkg/taz ]; then
2092 _ 'Need to build "%s"' "$pkg"
2093 exit 0
2094 fi
2096 title 'Checking depends'
2097 lddlist='/tmp/lddlist'; touch $lddlist
2098 missing='/var/cache/missing.file'
2100 # find all deps using ldd
2101 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
2102 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
2103 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
2104 done #"
2106 # remove exe/so duplicates
2107 sort -u $lddlist > $lddlist.sorted
2109 # search packages
2110 for exefile in $(cat $lddlist.sorted); do
2111 search_file $exefile
2112 echo "$found" >> $lddlist.pkgs
2113 echo -n '.'
2114 done
2115 echo
2117 # remove packages duplicates
2118 sort -u $lddlist.pkgs > $lddlist.final
2119 sort -u $missing > $missing.final
2120 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
2121 exit 0 ;;
2122 esac
2124 # Rotate log
2125 for i in $(seq 9 -1 1); do
2126 j=$(($i - 1))
2127 [ -e $LOGS/$pkg.log.$j ] &&
2128 mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2129 done
2130 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