cookutils view cook @ rev 834

cook: remake compressors (few more to come), introduce COOKOPTS.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Nov 14 07:01:25 2016 +0200 (2016-11-14)
parents cf394b12c320
children 11a3c021e563
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=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
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 # L10n: 's' is for seconds (cooking time)
392 _ 'Cook time : %s' "$(disp_time "$time")"
393 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
394 _ 'Host arch : %s' "$ARCH"
395 separator
396 }
399 # Display debugging error info.
401 debug_info() {
402 title 'Debug information'
403 # L10n: specify your format of date and time (to help: man date)
404 # L10n: not bad one is '+%x %R'
405 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
406 [ "$time" ] && _ 'Cook time: %ds' "$(($(date +%s) - $time))"
407 # L10n: Please, translate all messages beginning with ERROR in a same way
408 lerror=$(_n 'ERROR')
409 for error in \
410 ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
411 'error:' 'fatal error:' 'undefined reference to' \
412 'Unable to connect to' 'link: cannot find the library' \
413 'CMake Error' ': No such file or directory' \
414 'Could not read symbols: File in wrong format'
415 do
416 fgrep "$error" $LOGS/$pkg.log
417 done > $LOGS/$pkg.log.debug_info 2>&1
418 cat $LOGS/$pkg.log.debug_info
419 rm -f $LOGS/$pkg.log.debug_info
420 footer
421 }
424 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
425 # so some packages need to copy these files with the receipt and genpkg_rules.
427 copy_generic_files() {
428 # $LOCALE is set in cook.conf
429 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
430 if [ -d "$install/usr/share/locale" ]; then
431 mkdir -p $fs/usr/share/locale
432 for i in $LOCALE; do
433 if [ -d "$install/usr/share/locale/$i" ]; then
434 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
435 fi
436 done
437 fi
438 fi
440 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
441 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
442 if [ -d "$install/usr/share/pixmaps" ]; then
443 mkdir -p $fs/usr/share/pixmaps
444 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
445 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
446 $fs/usr/share/pixmaps
447 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
448 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
449 $fs/usr/share/pixmaps
450 fi
451 fi
453 # Custom or homemade PNG pixmap can be in stuff.
454 if [ -f "$stuff/$PACKAGE.png" ]; then
455 mkdir -p $fs/usr/share/pixmaps
456 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
457 fi
458 fi
460 # Desktop entry (.desktop).
461 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
462 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
463 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
464 mkdir -p $fs/usr/share
465 cp -a $install/usr/share/applications $fs/usr/share
466 fi
467 fi
469 # Homemade desktop file(s) can be in stuff.
470 if [ -d "$stuff/applications" ]; then
471 mkdir -p $fs/usr/share
472 cp -a $stuff/applications $fs/usr/share
473 fi
474 if [ -f "$stuff/$PACKAGE.desktop" ]; then
475 mkdir -p $fs/usr/share/applications
476 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
477 fi
479 # Add custom licenses
480 if [ -d "$stuff/licenses" ]; then
481 mkdir -p $fs/usr/share/licenses
482 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
483 fi
484 }
487 # Fix common errors and warnings in the .desktop files
488 # Fixing can be disabled with COOKOPTS="!fixdesktops"
490 fix_desktop_files() {
491 [ "${COOKOPTS/!fixdesktops/}" != "$COOKOPTS" ] && return
492 [ -z "$(find $install -type f -name '*.desktop')" ] && return
494 if [ -n "$QA" -a -z "$(which desktop-file-validate)" ]; then
495 tazpkg -gi desktop-file-utils-extra --quiet
496 fi
498 for desktop in $(find $install -type f -name '*.desktop'); do
499 cp "$desktop" "$desktop.orig"
501 # Sort out .desktop file (is prerequisite to correct working of `fix-desktop-file`)
502 sdft "$desktop" -i
504 # Fix common errors in .desktop file
505 fix-desktop-file "$desktop"
507 if [ -n "$QA" ]; then
508 # Check the rest of errors, warnings and tips
509 _ 'QA: Checking %s...' "$(basename $desktop)"
510 diff "$desktop.orig" "$desktop"
511 desktop-file-validate "$desktop" | busybox fold -s
512 echo
513 fi
515 rm "$desktop.orig"
516 done
517 }
520 # Compressor mini summary
522 comp_summary() {
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 # Don't compress man pages for splitted packages
622 [ -n "$WANTED" ] && return
623 local manpath="$install/usr/share/man" dest link
624 [ -d "$manpath" ] || return
626 action 'Compressing man pages...'
628 local size0=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
629 local time0=$(date +%s)
630 # We'll use only Gzip compression, so decompress other formats first
631 find $manpath -type f -name '*.bz2' -exec bunzip2 \{\} \;
632 find $manpath -type f -name '*.xz' -exec unxz \{\} \;
634 # Fast compress with gzip
635 find $manpath -type f -name '*.[1-9]' -exec gzip \{\} \;
637 # Fix symlinks
638 for i in $(find $install/usr/share/man -type l); do
639 dest=$(readlink $i | sed 's|\.[gbx]z2*$||')
640 link=$(echo $i | sed 's|\.[gbx]z2*$||')
641 rm $i; ln -s $dest.gz $link.gz
642 done
644 # Recompress with advdef (it can't compress, only recompress)
645 tazpkg -gi advancecomp --quiet
646 for i in $(find $install/usr/share/man -type f); do
647 advdef -z4q $i
648 done
650 local size1=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
651 local time1=$(date +%s)
652 status
653 comp_summary "$time0" "$time1" "$size0" "$size1"
654 }
657 # Function used after compile_rules() to compress all png images
658 # Compressing can be disabled with COOKOPTS="!pngz"
660 cook_compress_png() {
661 [ "${COOKOPTS/!pngz/}" != "$COOKOPTS" ] && return
662 case "$ARCH" in
663 arm*) return;; # While SliTaz-arm miss `pngquant` and `optipng`
664 esac
665 [ -z "$(find $install -type f -name '*.png')" ] && return
667 action 'Compressing png images...'
668 local size0=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
669 local time0=$(date +%s)
671 local use_pq=true use_op=true
672 [ "${COOKOPTS/!pngquant/}" != "$COOKOPTS" ] && use_pq=false
673 [ "${COOKOPTS/!optipng/}" != "$COOKOPTS" ] && use_op=false
675 $use_pq && tazpkg -gi pngquant --quiet
676 $use_op && tazpkg -gi optipng --quiet
678 local oplevel=$(echo $COOKOPTS | grep 'op[0-8]' | sed 's|.*op\([0-8]\).*|\1|')
679 [ -z "$oplevel" ] && oplevel='2'
680 [ "$oplevel" == '8' ] && oplevel='7 -zm1-9'
682 for i in $(find $install -type f -name '*.png'); do
683 $use_pq && pngquant -f --skip-if-larger --ext .png --speed 1 "$i"
684 $use_op && optipng -quiet -strip all -o$oplevel "$i"
685 done
687 local size1=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
688 local time1=$(date +%s)
689 status
690 comp_summary "$time0" "$time1" "$size0" "$size1"
691 }
694 # Function used after compile_rules() to compress all svg images
695 # Compressing can be disabled with COOKOPTS="!svgz"
697 cook_compress_svg() {
698 [ "${COOKOPTS/!svgz/}" != "$COOKOPTS" ] && return
699 case "$ARCH" in
700 arm*) return;; # While SliTaz-arm miss `svgcleaner`
701 esac
702 [ -z "$(find $install -type f -name '*.svg')" ] && return
704 action 'Compressing svg images...'
705 local size0=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
706 local time0=$(date +%s)
707 tazpkg -gi svgcleaner --quiet
708 cleaner_log="$(mktemp)"
709 for i in $(find $install -type f -name '*.svg'); do
710 echo -n "$i: " >> "$cleaner_log"
711 svgcleaner "$i" "$i" --remove-unresolved-classes false --quiet true >> "$cleaner_log"
712 done
713 local size1=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
714 local time1=$(date +%s)
715 status
716 comp_summary "$time0" "$time1" "$size0" "$size1"
717 sed -i '/: $/d' "$cleaner_log"
718 if [ -s "$cleaner_log" ]; then
719 echo 'Cleaner warnings and errors:'
720 awk '{printf " %s\n", $0;}' "$cleaner_log"
721 echo
722 fi
723 rm "$cleaner_log"
724 }
727 # The main cook function.
729 cookit() {
730 title 'Cook: %s' "$PACKAGE $VERSION"
731 set_paths
733 # Handle cross-tools.
734 case "$ARCH" in
735 arm*|x86_64)
736 # CROSS_COMPILE is used by at least Busybox and the kernel to set
737 # the cross-tools prefix. Sysroot is the root of our target arch
738 sysroot="$CROSS_TREE/sysroot"
739 tools="$CROSS_TREE/tools"
740 # Set root path when cross compiling. ARM tested but not x86_64
741 # When cross compiling we must install build deps in $sysroot.
742 arch="-$ARCH"
743 root="$sysroot"
744 _ '%s sysroot: %s' "$ARCH" "$sysroot"
745 _ 'Adding "%s" to PATH' "$tools/bin"
746 export PATH="$PATH:$tools/bin"
747 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
748 export CROSS_COMPILE="$HOST_SYSTEM-"
749 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
750 if [ "$ARCH" == 'x86_64' ]; then
751 export CC="$HOST_SYSTEM-gcc -m64"
752 export CXX="$HOST_SYSTEM-g++ -m64"
753 else
754 export CC="$HOST_SYSTEM-gcc"
755 export CXX="$HOST_SYSTEM-g++"
756 fi
757 export AR="$HOST_SYSTEM-ar"
758 export AS="$HOST_SYSTEM-as"
759 export RANLIB="$HOST_SYSTEM-ranlib"
760 export LD="$HOST_SYSTEM-ld"
761 export STRIP="$HOST_SYSTEM-strip"
762 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
763 esac
765 [ -n "$QA" ] && receipt_quality
766 cd $pkgdir
767 [ -z "$continue" ] && rm -rf source 2>/dev/null
768 rm -rf install taz 2>/dev/null
770 # Disable -pipe if less than 512Mb free RAM.
771 free=$(free | awk '/buffers:/{print $4}')
772 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
773 _ 'Disabling -pipe compile flag: %d RAM free' "$free"
774 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
775 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
776 fi
777 unset free
779 # Export flags and path to be used by make and receipt.
780 DESTDIR="$pkgdir/install"
781 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
782 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
783 #LDFLAGS
785 # Check for build deps and handle implicit depends of *-dev packages
786 # (ex: libusb-dev :: libusb).
787 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
788 touch $CACHE/installed.local $CACHE/installed.web
789 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
790 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
791 for dep in $BUILD_DEPENDS; do
792 implicit="${dep%-dev}"
793 # Don't add implicit dependency if it defined in DEPENDS
794 # echo '' $DEPENDS '' | fgrep -q " $implicit " && implicit=''
795 for i in $dep $implicit; do
796 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
797 # Try local package first. In some cases implicit doesn't exist, ex:
798 # libboost-dev exists but not libboost, so check if we got vers.
799 unset vers
800 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
801 # We may have a local package.
802 if [ -z "$vers" ]; then
803 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info 2> /dev/null)
804 fi
805 debug "bdep: $i version: $vers"
806 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
807 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
808 else
809 # Priority to package version in wok (maybe more up-to-date)
810 # than the mirrored one.
811 if [ -n "$vers" ]; then
812 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
813 echo $i >> $CACHE/installed.web
814 else
815 # So package exists in wok but not available.
816 _ 'Missing dep (wok/pkg): %s' "$i $vers"
817 echo $i >> $CACHE/missing.dep
818 fi
819 else
820 # Package is not in wok but may be in online repo.
821 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
822 echo $i >> $CACHE/installed.web
823 else
824 _ 'ERROR: unknown dep "%s"' "$i"
825 exit 1
826 fi
827 fi
828 fi
829 fi
830 done
831 done
833 # Get the list of installed packages
834 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
836 # Have we a missing build dep to cook?
837 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
838 _ 'Auto cook config is set: %s' "$AUTO_COOK"
839 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
840 for i in $(uniq $CACHE/missing.dep); do
841 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
842 tee -a $LOGS/$PACKAGE.log.$$
843 # programmers: next two messages are exact copy from remove_deps()
844 togrep1=$(_n 'Build dependencies to remove:')
845 togrep2=$(_n 'Removing:')
846 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
847 fgrep $togrep1 $LOGS/$i.log && \
848 fgrep $togrep2 $LOGS/$i.log && newline) | \
849 tee -a $LOGS/$PACKAGE.log.$$ && break
850 done
851 rm -f $CACHE/missing.dep
852 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
853 fi
855 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
856 # is enabled and cook fails we have ERROR in log, if no auto cook we have
857 # missing dep in cached file.
858 lerror=$(_n 'ERROR')
859 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
860 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
861 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
862 exit 1
863 fi
865 # Install local packages: package-version$arch
866 cd $PKGS
867 for i in $(uniq $CACHE/installed.local); do
868 _ 'Installing dep (pkg/local): %s' "$i"
869 tazpkg install $i --root=$root --local --quiet
870 done
872 # Install web or cached packages (if mirror is set to $PKGS we only
873 # use local packages).
874 for i in $(uniq $CACHE/installed.web); do
875 _ 'Installing dep (web/cache): %s' "$i"
876 tazpkg get-install $i --root=$root --quiet
877 done
879 update_installed_cook_diff
881 # Get source tarball and make sure we have source dir named:
882 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
883 # tarball if it exists.
884 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
885 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
886 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
887 LZMA_SRC=''
888 else
889 get_source || exit 1
890 fi
891 fi
892 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
893 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
894 if ! extract_source ; then
895 get_source
896 extract_source || exit 1
897 fi
898 if [ -n "$LZMA_SRC" ]; then
899 cd $pkgdir/source
900 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
901 mv tmp tmp-1; mkdir tmp
902 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
903 fi
904 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
905 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
906 fi
907 fi
908 cd $pkgdir/source/tmp
909 # Some archives are not well done and don't extract to one dir (ex lzma).
910 files=$(ls | wc -l)
911 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
912 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
913 mv * ../$PACKAGE-$VERSION/$TARBALL
914 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
915 mv * ../$PACKAGE-$VERSION
916 cd ..; rm -rf tmp
917 fi
919 # Libtool shared libs path hack.
920 case "$ARCH" in
921 arm*) cross libhack ;;
922 esac
924 # Execute receipt rules.
925 if grep -q ^compile_rules $receipt; then
926 _ 'Executing: %s' 'compile_rules'
927 echo "CFLAGS : $CFLAGS"
928 #echo "LDFLAGS : $LDFLAGS"
929 [ -d "$src" ] && cd $src
930 compile_rules $@ || exit 1
931 # Stay compatible with _pkg
932 [ -d "$src/_pkg" ] && mv $src/_pkg $install
933 # QA: compile_rules success so valid.
934 mkdir -p $install
935 else
936 # QA: no compile_rules so no error, valid.
937 mkdir -p $install
938 fi
940 # Actions to do after compiling the package
941 footer
942 compress_manpages
943 cook_compress_png
944 cook_compress_svg
945 footer
947 # Execute testsuite.
948 if grep -q ^testsuite $receipt; then
949 title 'Running testsuite'
950 testsuite $@ || exit 1
951 footer
952 fi
954 fix_desktop_files
956 update_installed_cook_diff force
957 }
960 # Cook quality assurance.
962 cookit_quality() {
963 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
964 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
965 fi
966 # ERROR can be echoed any time in cookit()
967 lerror=$(_n 'ERROR')
968 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
969 grep -Eq "(^$lerror|undefined reference to)" ; then
970 debug_info | tee -a $LOGS/$pkg.log
971 rm -f $command
972 exit 1
973 fi
974 }
977 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
978 # but it doesn't handle EXTRAVERSION.
980 packit() {
981 set_paths
983 # Handle cross compilation
984 case "$ARCH" in
985 arm*|x86_64) arch="-$ARCH" ;;
986 esac
988 title 'Pack: %s' "$PACKAGE $VERSION$arch"
990 if grep -q ^genpkg_rules $receipt; then
991 _ 'Executing: %s' 'genpkg_rules'
992 set -e; cd $pkgdir; mkdir -p $fs
993 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
994 $LOGS/$pkg.log
995 else
996 _ 'No packages rules: meta package'
997 mkdir -p $fs
998 fi
1000 # First QA check to stop now if genpkg_rules failed.
1001 lerror=$(_n 'ERROR')
1002 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1003 exit 1
1004 fi
1006 cd $taz
1007 for file in receipt description.txt; do
1008 [ ! -f "../$file" ] && continue
1009 action 'Copying "%s"...' "$file"
1010 cp -f ../$file $pack; chown 0.0 $pack/$file; status
1011 done
1012 copy_generic_files
1014 # Strip and stuff files.
1015 strip_package
1017 # Create files.list with redirecting find output.
1018 action 'Creating the list of files...'
1019 cd $fs
1020 find . -type f -print > ../files.list
1021 find . -type l -print >> ../files.list
1022 cd ..; sed -i s/'^.'/''/ files.list
1023 status
1025 # Md5sum of files.
1026 action 'Creating md5sum of files...'
1027 while read file; do
1028 [ -L "fs$file" ] && continue
1029 [ -f "fs$file" ] || continue
1030 case "$file" in
1031 /lib/modules/*/modules.*|*.pyc) continue ;;
1032 esac
1033 md5sum "fs$file" | sed 's/ fs/ /'
1034 done < files.list > md5sum
1035 status
1037 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1038 2>/dev/null | awk 'END{ print $1 }')
1040 # Build cpio archives.
1041 action 'Compressing the FS...'
1042 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1043 rm -rf fs
1044 status
1046 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
1047 2>/dev/null | awk 'END{ print $1 }')
1049 action 'Updating receipt sizes...'
1050 sed -i s/^PACKED_SIZE.*$// receipt
1051 sed -i s/^UNPACKED_SIZE.*$// receipt
1052 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1053 status
1055 # Set extra version.
1056 if [ -n "$EXTRAVERSION" ]; then
1057 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
1058 sed -i s/^EXTRAVERSION.*$// receipt
1059 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1060 status
1061 fi
1063 # Compress.
1064 action 'Creating full cpio archive...'
1065 find . -print | cpio -o -H newc --quiet > \
1066 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1067 status
1069 action 'Restoring original package tree...'
1070 unlzma -c fs.cpio.lzma | cpio -idm --quiet
1071 status
1073 rm fs.cpio.lzma; cd ..
1075 # QA and give info.
1076 tazpkg=$(ls *.tazpkg)
1077 packit_quality
1078 footer "$(_ 'Package "%s" created' "$tazpkg")"
1082 # Verify package quality and consistency.
1084 packit_quality() {
1085 #action 'QA: checking for broken link...'
1086 #link=$(find $fs/usr -type l -follow)
1087 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
1088 #status
1090 # Exit if any error found in log file.
1091 lerror=$(_n 'ERROR')
1092 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1093 rm -f $command
1094 exit 1
1095 fi
1097 action 'QA: checking for empty package...'
1098 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
1099 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
1100 newline; _ 'ERROR: empty package'
1101 rm -f $command
1102 exit 1
1103 else
1104 :; status
1105 # Find and remove old package(s)
1106 tempd="$(mktemp -d)"; cd "$tempd"
1107 for testpkg in $(ls $PKGS/$pkg-*.tazpkg 2> /dev/null); do
1108 # Extract receipt from each matched package
1109 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
1110 name=$(. receipt; echo $PACKAGE)
1111 rm receipt
1112 if [ "$name" == "$pkg" ]; then
1113 action 'Removing old package "%s"' "$(basename "$testpkg")"
1114 rm -f "$testpkg"
1115 status
1116 fi
1117 done
1118 rm -r "$tempd"
1119 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
1120 sed -i /^${pkg}$/d $broken
1121 #action 'Removing source tree...'
1122 #rm -f $WOK/$pkg/source; status
1123 fi
1127 # Reverse "cat" command: prints input lines in the reverse order
1129 tac() {
1130 sed '1!G;h;$!d' $1
1134 # Install package on --install or update the chroot.
1136 install_package() {
1137 case "$ARCH" in
1138 arm*|x86_64)
1139 arch="-$ARCH"
1140 root="$CROSS_TREE/sysroot" ;;
1141 esac
1142 # Install package if requested but skip install if target host doesn't
1143 # match build system or it will break the build chroot.
1144 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1145 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
1146 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1147 cd $PKGS
1148 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1149 else
1150 _ 'Unable to install package, build has failed.'; newline
1151 exit 1
1152 fi
1153 fi
1155 # Install package if part of the chroot to keep env up-to-date.
1156 if [ -d "$root$INSTALLED/$pkg" ]; then
1157 . /etc/slitaz/cook.conf
1158 . $WOK/$pkg/taz/$pkg-*/receipt
1159 _ 'Updating %s chroot environment...' "$ARCH"
1160 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
1161 cd $PKGS
1162 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1163 fi
1167 # remove chroot jail
1169 umount_aufs() {
1170 tac ${1}rw/aufs-umount.sh | sh
1171 rm -rf ${1}rw
1172 umount ${1}root
1173 rmdir ${1}r*
1177 # Launch the cook command into a chroot jail protected by aufs.
1178 # The current filesystems are used read-only and updates are
1179 # stored in a separate branch.
1181 try_aufs_chroot() {
1183 base="/dev/shm/aufsmnt$$"
1185 # Can we setup the chroot? Is it already done?
1186 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1187 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1188 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1189 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1190 mkdir ${base}root ${base}rw || return
1192 _ 'Setup aufs chroot...'
1194 # Sanity check
1195 for i in / /proc /sys /dev/shm /home ; do
1196 case " $AUFS_MOUNTS " in
1197 *\ $i\ *) ;;
1198 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1199 esac
1200 done
1201 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1202 mount --bind $mnt ${base}root$mnt
1203 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1204 _ 'Aufs mount failure'
1205 umount ${base}root
1206 rm -rf ${base}r*
1207 return
1208 fi
1209 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1210 done
1211 trap "umount_aufs ${base}" INT
1213 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1214 status=$?
1216 _ 'Leaving aufs chroot...'
1217 umount_aufs $base
1218 # Install package outside the aufs jail
1219 install_package
1220 exit $status
1224 # Encode predefined XML entities
1226 xml_ent() {
1227 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1231 # Create a XML feed for freshly built packages.
1233 gen_rss() {
1234 pubdate=$(date '+%a, %d %b %Y %X')
1235 cat > $FEEDS/$pkg.xml <<EOT
1236 <item>
1237 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1238 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1239 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1240 <pubDate>$pubdate</pubDate>
1241 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1242 </item>
1243 EOT
1247 # Truncate stdout log file to $1 Mb.
1249 loglimit() {
1250 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1251 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1252 else
1253 tee /dev/stderr
1254 fi
1258 # Search file in mirrored packages
1260 search_file_mirror() {
1261 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1265 # Search file in local wok packages
1267 search_file_local() {
1268 # existing packages have precedence over the package/taz folder
1269 srch=$1
1270 { for package in $(find $PKGS -name '*.tazpkg'); do
1271 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1272 grep /$srch\$)" ]; then
1273 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1274 fi
1275 done } | sort -u
1279 # Ask in multiple choice
1281 ask_multiple() {
1282 local multiples first my_choice
1283 multiples="$1"
1284 first=$(echo "$multiples" | head -n1)
1285 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1286 _ 'Select one [%s]: ' "$first"; read my_choice
1287 found="${my_choice:-$first}"
1291 # Search file in local cache (fast), local wok packages, mirrored packages
1293 search_file() {
1294 local srch cache missing
1295 srch="$1"
1296 cache='/var/cache/ldsearch.cache'
1297 missing='/var/cache/missing.file'
1298 touch $cache $missing
1299 found=$(grep $srch $cache | cut -d$'\t' -f2)
1300 if [ -z "$found" ]; then
1301 found=$(search_file_local $srch)
1302 if [ -n "$found" ]; then
1303 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1304 ask_multiple "$found"
1305 fi
1306 echo -e "$srch\t$found" >> $cache
1307 else
1308 found=$(search_file_mirror $srch)
1309 if [ -n "$found" ]; then
1310 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1311 ask_multiple "$found"
1312 fi
1313 echo -e "$srch\t$found" >> $cache
1314 else
1315 echo "$srch" >> $missing
1316 fi
1317 fi
1318 fi
1322 # Return size of file in human readible format
1323 # Note, "du" in opposite returns size occupied by file on disk (4KB multiple in most cases)
1324 filesize() {
1325 busybox ls -lh "$1" | awk '{print $5 "B"}'
1330 # Receipt functions to ease packaging
1333 get_dev_files() {
1334 action 'Getting standard devel files...'
1335 mkdir -p $fs/usr/lib
1336 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1337 cp -a $install/usr/lib/*a $fs/usr/lib
1338 cp -a $install/usr/include $fs/usr
1339 status
1343 # Function to use in compile_rules() to copy man page from $src to $install
1345 cook_pick_manpages() {
1346 local name section
1347 action 'Copying man pages...'
1349 for i in $@; do
1350 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1351 section=${name##*/}; section=${section##*.}
1352 mkdir -p $install/usr/share/man/man$section
1353 cp -a $i $install/usr/share/man/man$section
1354 done
1355 status
1359 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1361 cook_copy_files() {
1362 action 'Copying files...'
1363 cd $install
1364 local i j
1365 for i in $@; do
1366 for j in $(find . -name $i ! -type d); do
1367 mkdir -p $fs$(dirname ${j#.})
1368 cp -a $j $fs/${j#.}
1369 done
1370 done
1371 cd - >/dev/null
1372 status
1376 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1378 cook_copy_folders() {
1379 action 'Copying folders...'
1380 cd $install
1381 local i j
1382 for i in $@; do
1383 for j in $(find . -name $i -type d); do
1384 mkdir -p $fs$(dirname ${j#.})
1385 cp -a $j $fs/${j#.}
1386 done
1387 done
1388 cd - >/dev/null
1389 status
1393 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1394 # (default: 16 and 48) from $install to $fs
1396 cook_copy_icons() {
1397 local sizes=$@
1398 action 'Copying hicolor icons...'
1399 mkdir -p $fs/usr/share/icons/hicolor
1400 for i in ${sizes:-16 48}; do
1401 [ -e "$install/usr/share/icons/hicolor/${i}x$i" ] &&
1402 cp -a $install/usr/share/icons/hicolor/${i}x$i \
1403 $fs/usr/share/icons/hicolor
1404 done
1405 status
1408 dblog() { tee -a $LOGS/pkgdb.log; }
1414 # Commands
1417 case "$1" in
1418 usage|help|-u|-h)
1419 usage ;;
1421 list-wok)
1422 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1423 cd $WOK
1424 if [ "$ARCH" != 'i486' ]; then
1425 count=0
1426 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1427 do
1428 unset HOST_ARCH
1429 . $pkg
1430 count=$(($count + 1))
1431 colorize 34 "$PACKAGE"
1432 done
1433 else
1434 count=$(ls | wc -l)
1435 ls -1
1436 fi
1437 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1438 ;;
1440 activity)
1441 cat $activity ;;
1443 search)
1444 # Just a simple search function, we dont need more actually.
1445 query="$2"
1446 title 'Search results for "%s"' "$query"
1447 cd $WOK; ls -1 | grep "$query"
1448 footer ;;
1450 setup)
1451 # Setup a build environment
1452 check_root
1453 _ 'Cook: setup environment' | log
1454 title 'Setting up your environment'
1455 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1456 cd $SLITAZ
1457 init_db_files
1458 _ 'Checking for packages to install...'
1459 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1460 # ARCH-setup or 'cross check' should be used before: cook setup
1461 case "$ARCH" in
1462 arm*|x86_64)
1463 if [ ! -x '/usr/bin/cross' ]; then
1464 _ 'ERROR: %s is not installed' 'cross'
1465 exit 1
1466 fi
1467 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1468 . /etc/slitaz/cross.conf ;;
1469 esac
1470 for pkg in $SETUP_PKGS; do
1471 if [ -n "$forced" ]; then
1472 tazpkg -gi $pkg --forced
1473 else
1474 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1475 fi
1476 done
1478 # Handle --options
1479 case "$2" in
1480 --wok) hg clone $WOK_URL wok || exit 1 ;;
1481 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1482 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1483 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1484 esac
1486 # SliTaz group and permissions
1487 if ! grep -q ^slitaz /etc/group; then
1488 _ 'Adding group "%s"' 'slitaz'
1489 addgroup slitaz
1490 fi
1491 _ 'Setting permissions for group "%s"...' 'slitaz'
1492 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1493 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1494 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1496 *-setup)
1497 # Setup for cross compiling.
1498 arch="${1%-setup}"
1499 check_root
1500 . /etc/slitaz/cook.conf
1501 for pkg in $CROSS_SETUP; do
1502 if [ -n "$forced" ]; then
1503 tazpkg -gi $pkg --forced
1504 else
1505 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1506 fi
1507 done
1509 _ 'Cook: setup %s cross environment' "$arch" | log
1510 title 'Setting up your %s cross environment' "$arch"
1511 init_db_files
1512 sed -i \
1513 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1514 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1515 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1516 /etc/slitaz/cook.conf
1517 case "$arch" in
1518 arm)
1519 flags='-O2 -march=armv6'
1520 host="$ARCH-slitaz-linux-gnueabi" ;;
1521 armv6hf)
1522 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1523 host="$ARCH-slitaz-linux-gnueabi" ;;
1524 armv7)
1525 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1526 host="$ARCH-slitaz-linux-gnueabi" ;;
1527 x86_64)
1528 flags='-O2 -mtune=generic -pipe'
1529 host="$ARCH-slitaz-linux" ;;
1530 esac
1531 sed -i \
1532 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1533 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1534 . /etc/slitaz/cook.conf
1535 sysroot="$CROSS_TREE/sysroot"
1536 tools="/cross/$arch/tools"
1537 root="$sysroot"
1538 # L10n: keep the same width of translations to get a consistent view
1539 _ 'Target arch : %s' "$ARCH"
1540 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1541 _ 'Build flags : %s' "$flags"
1542 _ 'Arch sysroot : %s' "$sysroot"
1543 _ 'Tools prefix : %s' "$tools/bin"
1544 # Tell the packages manager where to find packages.
1545 _ 'Packages DB : %s' "$root$DB"
1546 mkdir -p $root$INSTALLED
1547 cd $root$DB; rm -f *.bak
1548 for list in packages.list packages.desc packages.equiv packages.md5; do
1549 rm -f $list
1550 ln -s $SLITAZ/packages/$list $list
1551 done
1552 # We must have the cross compiled glibc-base installed or default
1553 # i486 package will be used as dep by tazpkg and then break the
1554 # cross environment
1555 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1556 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1557 fi
1558 # Show GCC version or warn if not yet compiled.
1559 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1560 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1561 else
1562 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1563 _ 'Run "%s" to cook a toolchain' 'cross compile'
1564 fi
1565 footer ;;
1567 test)
1568 # Test a cook environment.
1569 _ 'Cook test: testing the cook environment' | log
1570 [ ! -d "$WOK" ] && exit 1
1571 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1572 cook cooktest ;;
1574 new)
1575 # Create the package folder and an empty receipt.
1576 pkg="$2"
1577 [ -z "$pkg" ] && usage
1578 newline
1579 if [ -d "$WOK/$pkg" ]; then
1580 _ 'Package "%s" already exists.' "$pkg"
1581 exit 1
1582 fi
1584 action 'Creating folder "%s"' "$WOK/$pkg"
1585 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1587 action 'Preparing the package receipt...'
1588 cp $DATA/receipt .
1589 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1590 status; newline
1592 # Interactive mode, asking and seding.
1593 case "$3" in
1594 --interactive|-x)
1595 _ 'Entering interactive mode...'
1596 separator
1597 _ 'Package : %s' "$pkg"
1599 _n 'Version : ' ; read answer
1600 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1602 _n 'Category : ' ; read answer
1603 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1605 # L10n: Short description
1606 _n 'Short desc : ' ; read answer
1607 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1609 _n 'Maintainer : ' ; read answer
1610 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1612 _n 'License : ' ; read answer
1613 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1615 _n 'Web site : ' ; read answer
1616 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1617 newline
1619 # Wget URL.
1620 _ 'Wget URL to download source tarball.'
1621 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1622 _n 'Wget url : ' ; read answer
1623 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1625 # Ask for a stuff dir.
1626 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1627 if [ "$?" -eq 0 ]; then
1628 action 'Creating the stuff directory...'
1629 mkdir $WOK/$pkg/stuff; status
1630 fi
1632 # Ask for a description file.
1633 confirm "$(_n 'Are you going to write a description? (y/N)')"
1634 if [ "$?" -eq 0 ]; then
1635 action 'Creating the "%s" file...' 'description.txt'
1636 touch $WOK/$pkg/description.txt; status
1637 fi
1639 footer "$(_ 'Receipt is ready to use.')" ;;
1640 esac ;;
1642 list)
1643 # Cook a list of packages (better use the Cooker since it will order
1644 # packages before executing cook).
1645 check_root
1646 if [ -z "$2" ]; then
1647 newline; _ 'No list in argument.'; newline
1648 exit 1
1649 fi
1650 if [ ! -f "$2" ]; then
1651 newline; _ 'List "%s" not found.' "$2"; newline
1652 exit 1
1653 fi
1655 _ 'Starting cooking the list "%s"' "$2" | log
1657 for pkg in $(cat $2); do
1658 cook $pkg || broken
1659 done ;;
1661 clean-wok)
1662 check_root
1663 newline; action 'Cleaning all packages files...'
1664 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1665 status; newline ;;
1667 clean-src)
1668 check_root
1669 newline; action 'Cleaning all packages sources...'
1670 rm -rf $WOK/*/source
1671 status; newline ;;
1673 uncook)
1674 cd $WOK
1675 count=0
1676 title 'Checking for uncooked packages'
1678 for pkg in *; do
1679 unset HOST_ARCH EXTRAVERSION
1680 [ ! -e $pkg/receipt ] && continue
1681 . $pkg/receipt
1682 # Source cooked pkg receipt to get EXTRAVERSION
1683 if [ -d "$WOK/$pkg/taz" ]; then
1684 cd $WOK/$pkg/taz/$pkg-*
1685 . receipt; cd $WOK
1686 fi
1687 case "$ARCH" in
1688 i486)
1689 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1690 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1691 count=$(($count + 1))
1692 colorize 34 "$pkg"
1693 fi ;;
1694 arm*)
1695 # Check only packages included in arch
1696 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1697 # *.tazpkg
1698 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1699 count=$(($count + 1))
1700 colorize 34 "$pkg"
1701 fi
1702 fi ;;
1703 esac
1704 done
1706 if [ "$count" -gt "0" ]; then
1707 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1708 else
1709 _ 'All packages are cooked :-)'
1710 newline
1711 fi
1712 ;;
1714 pkgdb)
1715 # Create suitable packages list for TazPKG and only for built packages
1716 # as well as flavors files for TazLiTo. We dont need logs since we do it
1717 # manually to ensure everything is fine before syncing the mirror.
1719 rm $LOGS/pkgdb.log 2>/dev/null
1721 case "$2" in
1722 --flavors|--rmpkg) ;;
1723 *)
1724 [ -n "$2" ] && PKGS="$2"
1725 if [ ! -d "$PKGS" ]; then
1726 { newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline; } | dblog
1727 exit 1
1728 fi ;;
1729 esac
1731 time=$(date +%s)
1732 flavors="$SLITAZ/flavors"
1733 live="$SLITAZ/live"
1735 echo 'cook:pkgdb' > $command
1736 _ 'Cook pkgdb: Creating all packages lists' | log
1737 newline; { _ 'Creating lists for "%s"' "$PKGS"; separator; } | dblog
1739 { _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"; newline; } | dblog
1741 cd $PKGS
1742 rm -f packages.* extra.list
1743 touch packages.equiv
1745 _n 'Creating file "%s"' 'packages.list' | dblog
1746 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1747 echo " ($(filesize $PKGS/packages.list))" | dblog
1749 _n 'Creating file "%s"' 'packages.md5' | dblog
1750 md5sum *.tazpkg > $PKGS/packages.md5
1751 echo " ($(filesize $PKGS/packages.md5))" | dblog
1752 cp $PKGS/packages.md5 $PKGS/packages.toremove # list of duplicates
1754 md5sum packages.md5 | cut -d' ' -f1 > ID
1755 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
1757 _n 'Creating file "%s"' 'descriptions.txt' | dblog
1758 rm $PKGS/descriptions.txt 2>/dev/null
1759 for i in $(ls $WOK | sort); do
1760 if [ -e "$WOK/$i/description.txt" ]; then
1761 echo "$i" >> descriptions.txt
1762 cat "$WOK/$i/description.txt" | sed 's|^$| |' >> descriptions.txt
1763 echo >> descriptions.txt
1764 fi
1765 done
1766 echo " ($(filesize $PKGS/descriptions.txt))" | dblog
1769 _ 'Creating lists from "%s"' "$WOK" | dblog
1770 cd $WOK
1771 for pkg in *; do
1772 unset_receipt
1773 . $pkg/receipt
1774 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1775 [ -s $pkg/taz/*/receipt ] && . $pkg/taz/*/receipt
1777 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ] || \
1778 [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1780 # packages.desc lets us search easily in DB
1781 cat >> $PKGS/packages.desc <<EOT
1782 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1783 EOT
1785 # packages.txt used by tazpkg and tazpkg-web also to provide
1786 # a human readable package list with version and description.
1787 cat >> $PKGS/packages.txt <<EOT
1788 $PACKAGE
1789 $VERSION$EXTRAVERSION
1790 $SHORT_DESC
1791 $PACKED_SIZE ($UNPACKED_SIZE installed)
1793 EOT
1795 # packages.info combines TazPkg separate files
1796 # and will substitute them all
1797 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1798 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1799 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
1800 cat >> $PKGS/packages.info <<EOT
1801 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
1802 EOT
1804 # packages.equiv is used by tazpkg install to check depends.
1805 for i in $PROVIDE; do
1806 DEST=''
1807 echo $i | fgrep -q : && DEST="${i#*:}:"
1808 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1809 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1810 $PKGS/packages.equiv
1811 else
1812 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1813 fi
1814 done
1816 # files.list provides a list of all packages files.
1817 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1818 $PKGS/files.list
1820 # list of duplicates
1821 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
1822 else
1823 # if receipt variable HOST_ARCH absent/empty or contains ARCH
1824 if [ -z "$HOST_ARCH" -o "${HOST_ARCH/$ARCH/}" != "$HOST_ARCH" ]; then
1825 _ ' - absent: %s (%s)' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ARCH" | dblog
1826 fi
1827 fi
1828 done
1830 # Display list size.
1831 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)" | dblog
1832 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)" | dblog
1833 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)" | dblog
1834 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)" | dblog
1836 cd $PKGS
1839 # Check package duplicates
1840 if [ -s "$PKGS/packages.toremove" ]; then
1841 newline | dblog
1842 _ 'Removing duplicates:' | dblog
1843 while read pkgsum pkgfile; do
1844 echo " - $pkgfile" | dblog
1845 sed -i "/${pkgfile%.tazpkg}/d" $PKGS/packages.list
1846 sed -i "/ $pkgfile/d" $PKGS/packages.md5
1847 [ -n "$rmpkg" ] && rm $PKGS/$pkgfile # remove packages only with --rmpkg
1848 done < $PKGS/packages.toremove
1849 newline | dblog
1850 fi
1851 rm $PKGS/packages.toremove
1854 # files.list.lzma
1855 _n 'Creating file "%s"' 'files.list.lzma' | dblog
1856 touch files.list
1857 # pkgs.slitaz.org strongly depends on list sorted by packages names
1858 lzma e files.list files.list.lzma
1859 echo " ($(filesize $PKGS/files.list.lzma))" | dblog
1861 # Pre-sorting filenames causes 10% smaller resulting lzma file
1862 _n 'Creating file "%s"' 'files-list.lzma' | dblog
1863 cat files.list | sort -k2 -o files.list.sorted
1864 lzma e files.list.sorted files-list.lzma
1865 rm -f files.list files.list.sorted
1866 echo " ($(filesize $PKGS/files-list.lzma))" | dblog
1868 [ -e files.list.md5 ] && rm files.list.md5
1869 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
1871 # packages.info.lzma
1872 PI=packages.info
1873 _n 'Creating file "%s"' 'packages.info.lzma' | dblog
1874 touch $PI
1875 lzma e $PI $PI.lzma
1876 echo " ($(filesize $PKGS/packages.info.lzma))" | dblog
1878 # Make bundle to fast recharge
1879 _n 'Creating file "%s"' 'bundle.tar.lzma' | dblog
1880 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
1881 # Make sure to get "mirrors" file
1882 until [ -e 'mirrors' ]; do
1883 wget -q http://mirror1.slitaz.org/mirrors
1884 echo -n '.' | dblog; sleep 5
1885 done
1886 # Make sure to get "extra.list" file
1887 until [ -e 'extra.list' ]; do
1888 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
1889 echo -n '.' | dblog; sleep 5
1890 done
1891 busybox tar -chaf bundle.tar.lzma \
1892 mirrors extra.list files-list.md5 packages.info descriptions.txt \
1893 packages.desc packages.md5 packages.txt packages.list packages.equiv
1894 rm ./mirrors
1895 echo " ($(filesize $PKGS/bundle.tar.lzma))" | dblog
1897 # Display some info.
1898 separator | dblog
1899 nb=$(ls $PKGS/*.tazpkg | wc -l)
1900 time=$(($(date +%s) - $time))
1901 # L10n: 's' is for seconds (cooking time)
1902 { _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline; } | dblog
1905 # Create all flavors files at once. Do we really need code to monitor
1906 # flavors changes? Lets just build them with packages lists before
1907 # syncing the mirror.
1908 [ "$2" != '--flavors' ] && exit 1
1910 if [ ! -d "$flavors" ]; then
1911 { _ 'Missing flavors folder "%s"' "$flavors"; newline; } | dblog
1912 exit 1
1913 fi
1915 [ ! -d "$live" ] && mkdir -p $live
1916 _ 'Creating flavors files in "%s"' "$live" | dblog
1917 _ 'Cook pkgdb: Creating all flavors' | log
1918 separator | dblog
1920 _ 'Recharging lists to use latest packages...' | dblog
1921 tazpkg recharge >/dev/null 2>/dev/null
1923 # We need a custom tazlito config to set working dir to /home/slitaz.
1924 if [ ! -f "$live/tazlito.conf" ]; then
1925 _ 'Creating configuration file "%s"' 'tazlito.conf' | dblog
1926 cp /etc/tazlito/tazlito.conf $live
1927 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1928 $live/tazlito.conf
1929 fi
1931 # Update Hg flavors repo and pack.
1932 if [ -d "$flavors/.hg" ]; then
1933 cd $flavors; hg pull -u
1934 fi
1936 cd $live
1937 _ 'Starting to generate flavors...' | dblog
1938 rm -f flavors.list *.flavor
1939 for i in $flavors/*; do
1940 fl=$(basename $i)
1941 _ 'Packing flavor "%s"' "$fl" | dblog
1942 tazlito pack-flavor $fl >/dev/null || exit 1
1943 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
1944 done
1945 cp -f $live/*.flavor $live/flavors.list $PKGS
1946 separator | dblog
1947 { _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline; } | dblog
1948 rm -f $command
1949 separator | dblog
1950 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" | dblog
1951 ;;
1953 *)
1954 # Just cook and generate a package.
1955 check_root
1956 time=$(date +%s)
1957 pkg="$1"
1958 [ -z "$pkg" ] && usage
1959 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1960 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
1961 receipt="$WOK/$pkg/receipt"
1962 check_pkg_in_wok
1963 newline
1965 unset inst
1966 unset_receipt
1967 . $receipt
1969 # Handle cross compilation.
1970 case "$ARCH" in
1971 arm*)
1972 if [ -z "$HOST_ARCH" ]; then
1973 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1974 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1975 _ 'cook: %s' "$error"
1976 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1977 _ 'Cook skip: %s' "$error" | log
1978 newline
1979 exit 1
1980 fi ;;
1981 esac
1983 # Some packages are not included in some arch or fail to cross compile.
1984 : ${HOST_ARCH=i486}
1985 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1986 # Handle arm{v6hf,v7,..}
1987 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1988 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1989 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1990 _ 'cook: %s' "error"
1991 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1992 _ 'Cook skip: %s' "$error" | log
1993 sed -i /^${pkg}$/d $broken
1994 newline
1995 exit 0
1996 fi
1998 # Skip blocked, 3 lines also for the Cooker.
1999 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
2000 _ 'Package "%s" is blocked' "$pkg"; newline
2001 exit 0
2002 fi
2004 try_aufs_chroot "$@"
2006 # Log and source receipt.
2007 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
2008 echo "cook:$pkg" > $command
2009 [ "$lastcooktime" ] &&
2010 echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
2011 while read cmd duration start; do
2012 [ $(($start + $duration)) -lt $(date +%s) ] &&
2013 echo "sed -i '/^$cmd $duration/d' $cooktime"
2014 done < $cooktime | sh
2016 # Display and log info if cook process stopped.
2017 # FIXME: gettext not working (in single quotes) here!
2018 trap '_ "\n\nCook stopped: control-C\n\n" | \
2019 tee -a $LOGS/$pkg.log' INT
2021 # Handle --options
2022 case "$2" in
2023 --clean|-c)
2024 action 'Cleaning "%s"' "$pkg"
2025 cd $WOK/$pkg; rm -rf install taz source
2026 status; newline
2027 exit 0 ;;
2029 --install|-i)
2030 inst='yes' ;;
2032 --getsrc|-gs)
2033 title 'Getting source for "%s"' "$pkg"
2034 get_source
2035 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
2036 exit 0 ;;
2038 --block|-b)
2039 action 'Blocking package "%s"' "$pkg"
2040 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
2041 status; newline
2042 exit 0 ;;
2044 --unblock|-ub)
2045 action 'Unblocking package "%s"' "$pkg"
2046 sed -i "/^${pkg}$/"d $blocked
2047 status; newline
2048 exit 0 ;;
2050 --pack)
2051 if [ -d $WOK/$pkg/taz ]; then
2052 rm -rf $WOK/$pkg/taz
2053 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
2054 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
2055 clean_log
2056 else
2057 _ 'Need to build "%s"' "$pkg"
2058 exit 0
2059 fi
2060 exit 0 ;;
2062 --cdeps)
2063 if [ ! -d $WOK/$pkg/taz ]; then
2064 _ 'Need to build "%s"' "$pkg"
2065 exit 0
2066 fi
2068 title 'Checking depends'
2069 lddlist='/tmp/lddlist'; touch $lddlist
2070 missing='/var/cache/missing.file'
2072 # find all deps using ldd
2073 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
2074 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
2075 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
2076 done #"
2078 # remove exe/so duplicates
2079 sort -u $lddlist > $lddlist.sorted
2081 # search packages
2082 for exefile in $(cat $lddlist.sorted); do
2083 search_file $exefile
2084 echo "$found" >> $lddlist.pkgs
2085 echo -n '.'
2086 done
2087 echo
2089 # remove packages duplicates
2090 sort -u $lddlist.pkgs > $lddlist.final
2091 sort -u $missing > $missing.final
2092 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
2093 exit 0 ;;
2094 esac
2096 # Rotate log
2097 for i in $(seq 9 -1 1); do
2098 j=$(($i - 1))
2099 [ -e $LOGS/$pkg.log.$j ] &&
2100 mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2101 done
2102 mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2104 # Check if wanted is built now so we have separate log files.
2105 for wanted in $WANTED ; do
2106 if grep -q "^$wanted$" $blocked; then
2107 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
2108 newline
2109 rm -f $command
2110 exit 1
2111 fi
2112 if grep -q "^$wanted$" $broken; then
2113 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
2114 newline
2115 rm -f $command
2116 exit 1
2117 fi
2118 if [ ! -d "$WOK/$wanted/install" ]; then
2119 cook "$wanted" || exit 1
2120 fi
2121 done
2123 # Cook and pack or exit on error and log everything.
2124 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
2125 remove_deps | tee -a $LOGS/$pkg.log
2126 cookit_quality
2127 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2128 clean_log
2130 # Exit if any error in packing.
2131 lerror=$(_n 'ERROR')
2132 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2133 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2134 debug_info | tee -a $LOGS/$pkg.log
2135 rm -f $command
2136 exit 1
2137 fi
2139 # Create an XML feed
2140 gen_rss
2142 # Time and summary
2143 time=$(($(date +%s) - $time))
2144 summary | tee -a $LOGS/$pkg.log
2145 newline
2147 # We may want to install/update (outside aufs jail !).
2148 [ -s /aufs-umount.sh ] ||
2149 install_package
2151 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2152 # You want automation: use the Cooker Build Bot.
2153 rm -f $command ;;
2154 esac
2156 exit 0