cookutils view cook @ rev 1079

Improve work with sets:
- keep natural order of the sets described in $SPLIT,
- provide new mode (COOKOPTS="instant-pack"): compile the set and then immediately pack all it's packages, so they will be available for the next set.
Allow to change $CATEGORY.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Jul 10 10:25:36 2018 +0300 (2018-07-10)
parents 1463d32f6f90
children 8683bf3e7c02
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
14 prev_ts="/home/slitaz/cache/prev_ts"; touch $prev_ts
17 # Internationalization.
19 export TEXTDOMAIN='cook'
22 #
23 # Functions
24 #
26 usage() {
27 cat <<EOT
29 $(boldify "$(_ 'Usage:')") $(_ 'cook [package|command] [list|--option]')
31 $(boldify "$(_ 'Commands:')")
32 usage|help $(_ 'Display this short usage.')
33 setup $(_ 'Setup your build environment.')
34 *-setup $(_ 'Setup a cross environment.')
35 * = {arm|armv6hf|armv7|x86_64}
36 test $(_ 'Test environment and cook a package.')
37 list-wok $(_ 'List packages in the wok.')
38 search $(_ 'Simple packages search function.')
39 new $(_ 'Create a new package with a receipt.')
40 list $(_ 'Cook a list of packages.')
41 clean-wok $(_ 'Clean-up all packages files.')
42 clean-src $(_ 'Clean-up all packages sources.')
43 uncook $(_ 'Check for uncooked packages')
44 pkgdb $(_ 'Create packages DB lists and flavors.')
46 $(boldify "$(_ 'Options:')")
47 cook <pkg>
48 --clean -c $(_ 'clean the package in the wok.')
49 --install -i $(_ 'cook and install the package.')
50 --getsrc -gs $(_ 'get the package source tarball.')
51 --block -b $(_ 'block a package so cook will skip it.')
52 --unblock -ub $(_ 'unblock a blocked package.')
53 --cdeps $(_ 'check dependencies of cooked package.')
54 --pack $(_ 'repack an already built package.')
55 --debug $(_ 'display debugging messages.')
56 --continue $(_ 'continue running compile_rules.')
57 cook new <pkg>
58 --interactive -x $(_ 'create a receipt interactively.')
59 cook setup
60 --wok $(_ 'clone the cooking wok from Hg repo.')
61 --stable $(_ 'clone the stable wok from Hg repo.')
62 --undigest $(_ 'clone the undigest wok from Hg repo.')
63 --tiny $(_ 'clone the tiny SliTaz wok from Hg repo.')
64 --forced $(_ 'force reinstall of chroot packages.')
65 cook pkgdb
66 --flavors $(_ 'create up-to-date flavors files.')
67 cook splitdb $(_ 'create up-to-date split.db file.')
69 EOT
70 exit 0
71 }
74 # We don't want these escapes in web interface.
76 clean_log() {
77 sed -i -e 's|\[70G\[ \[1;32m| |' \
78 -e 's|\[0;39m \]||' $LOGS/${1:-$pkg}.log
79 }
82 # Be sure package exists in wok.
84 check_pkg_in_wok() {
85 [ -d "$WOK/$pkg" ] || die 'Unable to find package "%s" in the wok' "$pkg"
86 }
89 # Find the package, return the receipt name where it was found
90 # for example, libpcreposix -> pcre
92 find_pkg_in_wok() {
93 awk -F$'\t' -vi="$1" '{
94 if (index(" " $2 " ", i)) {print $1; exit}
95 }' $cache/split.db
96 }
99 # Initialize files used in $CACHE
101 init_db_files() {
102 _ 'Creating directories structure in "%s"' "$SLITAZ"
103 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
104 _ 'Creating DB files in "%s"' "$CACHE"
105 touch $activity $command $broken $blocked $CACHE/webstat
106 chown www:www $cache/webstat
107 }
110 # Paths used in receipt and by cook itself.
112 set_paths() {
113 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
114 if [ -f "$WOK/linux/receipt" ]; then
115 kvers=$(. $WOK/linux/receipt; echo $VERSION)
116 kbasevers=$(echo $kvers | cut -d. -f1,2)
117 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
118 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
119 kbasevers=$(echo $kvers | cut -d. -f1,2)
120 fi
122 # Python version
123 [ -f "$WOK/python/receipt" ] && pyvers=$(. $WOK/python/receipt; echo $VERSION)
124 # Perl version for some packages needed it
125 [ -f "$WOK/perl/receipt" ] && perlvers=$(. $WOK/perl/receipt; echo $VERSION)
127 pkgdir="$WOK/$pkg"
128 . "$pkgdir/receipt"
129 basesrc="$pkgdir/source"
130 tmpsrc="$basesrc/tmp"
131 src="$basesrc/$PACKAGE-$VERSION"
132 taz="$pkgdir/taz"
133 pack="$taz/${1:-$PACKAGE}-$VERSION$EXTRAVERSION" # v2: multiple taz/* folders
134 fs="$pack/fs"
135 stuff="$pkgdir/stuff"
136 install="$pkgdir/install"
138 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
139 lzma_tarball="$pkgsrc.tar.lzma"
141 [ -n "$PATCH" -a -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
143 if [ -n "$WANTED" ]; then
144 basesrc="$WOK/$WANTED/source"
145 src="$basesrc/$WANTED-$VERSION"
146 install="$WOK/$WANTED/install"
147 wanted_stuff="$WOK/$WANTED/stuff"
148 fi
150 [ -n "$SOURCE" ] && source_stuff="$WOK/$SOURCE/stuff"
152 # Old way compatibility.
153 _pkg="$install"
154 }
157 # Create source tarball when URL is a SCM.
159 create_tarball() {
160 local tarball
161 tarball="$pkgsrc.tar.bz2"
162 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
163 _ 'Creating tarball "%s"' "$tarball"
164 if [ -n "$LZMA_SRC" ]; then
165 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
166 LZMA_SRC=''
167 else
168 tar -cjf $tarball $pkgsrc || exit 1
169 mv $tarball $SRC; rm -rf $pkgsrc
170 fi
171 TARBALL="$tarball"
172 }
175 # Get package source. For SCM we are in cache so clone here and create a
176 # tarball here.
178 get_source() {
179 local url
180 url=${WGET_URL#*|}
181 set_paths
182 pwd=$(pwd)
183 case "$WGET_URL" in
184 http://*|ftp://*|https://*)
185 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
186 wget -T 60 -c -O $SRC/$TARBALL $WGET_URL ||
187 wget -T 60 -c -O $SRC/$TARBALL $url ||
188 die 'ERROR: %s' "wget $WGET_URL"
189 ;;
191 hg*|mercurial*)
192 _ 'Getting source from %s...' 'Hg'
193 _ 'URL: %s' "$url"
194 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
195 if [ -n "$BRANCH" ]; then
196 _ 'Hg branch: %s' "$BRANCH"
197 hg clone $url --rev $BRANCH $pkgsrc ||
198 die 'ERROR: %s' "hg clone $url --rev $BRANCH"
199 else
200 hg clone $url $pkgsrc || die 'ERROR: %s' "hg clone $url"
201 fi
202 rm -rf $pkgsrc/.hg
203 create_tarball
204 ;;
206 git*)
207 _ 'Getting source from %s...' 'Git'
208 _ 'URL: %s' "$url"
209 cd $SRC
210 git clone $url $pkgsrc || die 'ERROR: %s' "git clone $url"
211 if [ -n "$BRANCH" ]; then
212 _ 'Git branch: %s' "$BRANCH"
213 cd $pkgsrc; git checkout $BRANCH; cd ..
214 fi
215 cd $SRC
216 create_tarball
217 ;;
219 cvs*)
220 mod=$PACKAGE
221 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
222 _ 'Getting source from %s...' 'CVS'
223 _ 'URL: %s' "$url"
224 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
225 _ 'Cloning to "%s"' "$pwd/$mod"
226 cvs -d:$url co $mod && mv $mod $pkgsrc
227 create_tarball
228 ;;
230 svn*|subversion*)
231 _ 'Getting source from %s...' 'SVN'
232 _ 'URL: %s' "$url"
233 if [ -n "$BRANCH" ]; then
234 echo t | svn co $url -r $BRANCH $pkgsrc
235 else
236 echo t | svn co $url $pkgsrc
237 fi
238 create_tarball
239 ;;
241 bzr*)
242 _ 'Getting source from %s...' 'bazaar'
243 cd $SRC
244 pkgsrc=${url#*:}
245 if [ -n "$BRANCH" ]; then
246 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
247 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
248 else
249 echo "bzr -Ossl.cert_reqs=none branch $url"
250 bzr -Ossl.cert_reqs=none branch $url
251 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
252 _ "Don't forget to add to receipt:"
253 echo -e "BRANCH=\"$BRANCH\"\n"
254 fi
255 mv $pkgsrc $pkgsrc-$BRANCH
256 pkgsrc="$pkgsrc-$BRANCH"
257 create_tarball
258 ;;
260 *)
261 broken; die 'ERROR: Unable to handle "%s"' "$WGET_URL"
262 ;;
263 esac
264 }
267 # Extract source package.
269 extract_source() {
270 if [ ! -s "$SRC/$TARBALL" ]; then
271 local url
272 url="$MIRROR_URL/sources/packages"
273 url="$url/${TARBALL:0:1}/$TARBALL"
274 _ 'Getting source from %s...' 'mirror'
275 _ 'URL: %s' "$url"
276 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
277 fi
278 _ 'Extracting source archive "%s"' "$TARBALL"
279 case "$TARBALL" in
280 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
281 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
282 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
283 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
284 *.tar) tar -xf $SRC/$TARBALL ;;
285 *.zip|*.xpi) unzip -o $SRC/$TARBALL 2>/dev/null >&2;;
286 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
287 tar -xf $SRC/$TARBALL 2>/dev/null;;
288 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
289 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
290 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
291 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
292 *) cp $SRC/$TARBALL $(pwd) ;;
293 esac
294 }
297 # Display time.
299 disp_time() {
300 local sec div min
301 sec="$1"
302 div=$(( ($1 + 30) / 60))
303 case $div in
304 0) min='';;
305 # L10n: 'm' is for minutes (approximate cooking time)
306 *) min=$(_n ' ~ %dm' "$div");;
307 esac
309 # L10n: 's' is for seconds (cooking time)
310 _ '%ds%s' "$sec" "$min"
311 }
314 # Display cooked package summary.
316 summary() {
317 local arch=''
318 case "$ARCH" in
319 arm*|x86_64) arch="-$ARCH" ;;
320 esac
322 set_paths
323 cd $WOK/$pkg
324 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
325 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
326 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
328 title 'Summary for: %s' "$PACKAGE $VERSION$EXTRAVERSION$arch"
330 # L10n: keep the same width of translations to get a consistent view
331 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
332 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
333 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
334 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
335 _ 'Cook time : %s' "$(disp_time "$time")"
336 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
337 _ 'Target arch : %s' "$ARCH"
339 separator -
340 _ ' # : Packed : Compressed : Files : Package name'
341 separator -
342 pkgi=1
343 for i in $(all_names); do
344 version=$(awk -F$'\t' -vpkg="$i" '{
345 if ($1 == pkg) {print $2; exit}
346 }' "$PKGS/packages.info")
347 fs=$(du -sh $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION | awk '{print $1}')
348 pkgname="$i-$version$EXTRAVERSION$arch.tazpkg"
349 size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
350 files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/files.list)
351 printf "%2d : %7s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
352 pkgi=$((pkgi + 1))
353 done
354 separator
355 }
358 # Display debugging error info.
360 debug_info() {
361 title 'Debug information'
362 # L10n: specify your format of date and time (to help: man date)
363 # L10n: not bad one is '+%x %R'
364 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
365 if [ -n "$time" ]; then
366 times="$(($(date +%s) - $time))"
367 _ 'Wasted time : %s' "$(disp_time "$times")"
368 fi
369 for error in \
370 ERROR 'No package' "cp: can't" "can't open" "can't cd" \
371 'error:' 'fatal error:' 'undefined reference to' \
372 'Unable to connect to' 'link: cannot find the library' \
373 'CMake Error' ': No such file or directory' \
374 'Could not read symbols: File in wrong format'
375 do
376 # format "line number:line content"
377 fgrep -n "$error" $LOGS/$pkg.log
378 done > $LOGS/$pkg.log.debug_info 2>&1
379 # sort by line number, remove duplicates
380 sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
381 rm -f $LOGS/$pkg.log.debug_info
382 footer
383 }
386 # A bit smarter function than the classic `cp` command
388 scopy() {
389 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
390 cp -a "$1" "$2" # copy generic files
391 else
392 cp -al "$1" "$2" # copy hardlinks
393 fi
394 }
397 # Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
398 # We use standard paths, so some packages need to copy these files with the
399 # receipt and genpkg_rules.
400 # This function executes inside the packaging process, before compressor call.
402 copy_generic_files() {
403 # Proceed only for "main" package (for v2), and for any packages (v1)
404 [ "$pkg" == "$PACKAGE" ] || return 0
406 # $LOCALE is set in cook.conf
407 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
408 if [ -d "$install/usr/share/locale" ]; then
409 mkdir -p "$fs/usr/share/locale"
410 for i in $LOCALE; do
411 if [ -d "$install/usr/share/locale/$i" ]; then
412 cp -r $install/usr/share/locale/$i $fs/usr/share/locale
413 fi
414 done
415 fi
416 fi
418 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
419 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
420 if [ -d "$install/usr/share/pixmaps" ]; then
421 mkdir -p "$fs/usr/share/pixmaps"
422 for i in png xpm; do
423 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
424 cp -r $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
425 done
426 fi
427 fi
429 # Desktop entry (.desktop).
430 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
431 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
432 if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
433 mkdir -p "$fs/usr/share"
434 cp -r $install/usr/share/applications $fs/usr/share
435 fi
436 fi
437 }
440 # Copy pixmaps, desktop files and licenses from $stuff to $install.
441 # This function executes after the main compile_rules() is done.
443 copy_generic_stuff() {
444 # Custom or homemade PNG pixmap can be in stuff.
445 if [ -f "$stuff/$PACKAGE.png" ]; then
446 mkdir -p $install/usr/share/pixmaps
447 cp $stuff/$PACKAGE.png $install/usr/share/pixmaps
448 fi
450 # Homemade desktop file(s) can be in stuff.
451 if [ -d "$stuff/applications" ]; then
452 mkdir -p $install/usr/share
453 cp -r $stuff/applications $install/usr/share
454 fi
455 if [ -f "$stuff/$PACKAGE.desktop" ]; then
456 mkdir -p $install/usr/share/applications
457 cp $stuff/$PACKAGE.desktop $install/usr/share/applications
458 fi
460 # Add custom licenses
461 if [ -d "$stuff/licenses" ]; then
462 mkdir -p $install/usr/share/licenses
463 cp -r $stuff/licenses $install/usr/share/licenses/$PACKAGE
464 fi
465 }
468 # Update installed.cook.diff
470 update_installed_cook_diff() {
471 # If a cook failed deps are removed.
472 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
473 cd $CACHE
474 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
475 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
476 deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
477 }
480 # Remove installed deps.
482 remove_deps() {
483 # Now remove installed build deps.
484 diff='/tmp/installed.cook.diff'
485 [ -s "$diff" ] || return
487 deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
488 nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
489 newline
490 _n 'Build dependencies to remove:'; echo " $nb"
491 [ -n "$root" ] && echo "root=\"$root\""
492 {
493 _n 'Removing:'
494 for dep in $deps; do
495 echo -n " $dep"
496 # Do not waste time uninstalling the packages if we are inside
497 # aufs chroot - unmounting chroot will "uninstall" all packages.
498 [ -s /aufs-umount.sh ] ||
499 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
500 done
501 } | busybox fold -sw80
502 newline; newline
503 # Keep the last diff for debug and info.
504 mv -f $diff $CACHE/installed.diff
505 }
508 # Automatically patch the sources.
510 patchit() {
511 [ -f "$stuff/patches/series" ] || return
513 IFS=$'\n'
514 while read i; do
515 patchname=$(echo ${i%%#*} | cut -d' ' -f1) # allow comments (anything after the # or space)
516 case $patchname in # allow patch options in form <options_no_spaces>|<file_name>
517 *\|*) patchopts="${patchname%|*}"; patchname="${patchname#*|}";;
518 *) patchopts='-Np1';;
519 esac
520 [ -n "$patchname" ] || continue # allow empty lines
521 [ -f "$src/done.$patchname" ] && continue # already applied (useful with `cook --continue`)
522 newline
523 _ 'Applying patch %s' "$patchname"
524 patch $patchopts -i $stuff/patches/$patchname | sed 's|^| |'
525 touch $src/done.$patchname
526 done < $stuff/patches/series
527 newline
528 unset IFS
529 }
532 # Check source tarball integrity.
534 check_integrity() {
535 for i in sha1 sha3 sha256 sha512 md5; do
536 I=$(echo $i | tr 'a-z' 'A-Z')
537 eval sum=\$TARBALL_$I
538 if [ -n "$sum" ]; then
539 newline
540 _ 'Checking %ssum of source tarball...' "$i"
541 echo "$sum $SRC/$TARBALL" | ${i}sum -c || exit 1
542 fi
543 done
544 newline
545 }
548 # Misc fix functions
550 fix() {
551 case $1 in
552 # https://bugzilla.gnome.org/show_bug.cgi?id=655517
553 # https://wiki.gentoo.org/wiki/Project:Quality_Assurance/As-needed
554 ld)
555 export LDFLAGS="$LDFLAGS -Wl,-Os,--as-needed"
556 ;;
557 libtool)
558 if [ -e 'libtool' ]; then
559 sed -i 's| -shared | -Wl,-Os,--as-needed\0|g' libtool
560 else
561 echo "fix libtool: warning: libtool absent, nothing to fix."
562 fi
563 ;;
564 math)
565 # fix C++ math issue introduced in Glibc 2.26:
566 # error: '__builtin_isnan' is not a member of 'std'
567 # if (std::isnan(N)) {
568 # ^
569 find $src -type f -exec sed -i '
570 s|std::signbit|__builtin_signbit|g;
571 s|std::isnan|__builtin_isnan|g;
572 s|std::isinf|__builtin_isinf_sign|g;
573 s|std::isfinite|__builtin_isfinite|g;
574 s|std::isnormal|__builtin_isnormal|g
575 ' '{}' \;
576 ;;
577 symlinks)
578 # make absolute symlinks relative
579 echo "fix symlinks"
580 local ifs="$IFS" link target
581 IFS=$'\n'
582 # step 1: fast job, prefix all the absolute symlinks with "$install"
583 for link in $(find $install -type l); do
584 target="$(readlink $link)"
585 case "$target" in
586 /*) ln -sfv "$install$target" "$link";;
587 esac
588 done
589 IFS="$ifs"
590 # step 2: fine tuning, make symlinks relative
591 tazpkg -gi --quiet --local --cookmode symlinks
592 symlinks -cr $install
593 ;;
594 esac
595 }
598 # Store timestamps, log jobs length
600 timestamp() {
601 local ts_file="$WOK/$pkg/.ts"
602 local curr_ts=$(date '+%s')
603 case $1 in
604 init)
605 rm $ts_file 2>/dev/null
606 echo $curr_ts > $prev_ts
607 ;;
608 job*)
609 # calculate time from the last timestamp
610 echo "$1='$(( $curr_ts - $(cat $prev_ts) ))'" >> $ts_file
611 echo $curr_ts > $prev_ts
612 ;;
613 sets)
614 echo "sets='$2'" >> $ts_file
615 ;;
616 esac
617 }
620 # Store time statsistics to the cache
622 store_timestats() {
623 # see doc/timestats.txt for file format
624 temp=$(mktemp)
625 {
626 for i in $(seq 1 30); do echo "job$i=0"; done
627 cat $WOK/$pkg/.ts
628 echo -n 'total=$(( 0'
629 for i in $(seq 1 30); do echo -n " + job$i"; done
630 echo ' ))'
631 } > $temp
632 . $temp
633 {
634 echo -n "$pkg $sets "
635 for i in $(seq 1 30); do echo -n "$((job$i)) "; done
636 echo "$total"
637 } >> /home/slitaz/cache/timestats
638 rm $temp $WOK/$pkg/.ts # clean
639 }
642 # Internal function to cook specified SET
644 cook_set() {
645 # Switch to the specified source set
646 set_paths
647 local suffix=''
648 [ -n "$SET" ] && suffix="-$SET"
649 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
650 export install="$WOK/$pkg/install$suffix"
651 export DESTDIR="$install"
653 if [ -n "$SETS" ]; then
654 if [ -n "$SET" ]; then
655 title "Switching to the set '$SET'"
656 else
657 title "Switching to the default set"
658 fi
659 echo "src : $src"
660 echo "install: $install"
661 fi
662 [ -d "$src" ] && cd $src # packages without sources exists
663 echo
665 [ -d "$install" ] && rm -r $install
666 #mkdir -p $install
668 compile_rules $@ || { broken; exit 1; }
670 # Stay compatible with _pkg
671 [ -d "$src/_pkg" ] && mv $src/_pkg $install
673 copy_generic_stuff
675 timestamp job$job_counter # compiling (set '$SET')
677 # Actions to do after compiling the package
678 # Skip all for split packages (already done in main package)
679 if [ -z "$WANTED" ]; then
680 footer
681 export COOKOPTS ARCH install
682 @@PREFIX@@/libexec/cookutils/compressor install
683 timestamp job$(($job_counter + 1)) # compressing (set '$SET')
684 fi
686 # Activate "instant-pack" mode
687 if [ "${COOKOPTS/instant-pack/}" != "$COOKOPTS" ]; then
688 echo " $SPLIT " | fgrep -q " $PACKAGE " || SPLIT="$PACKAGE $SPLIT"
689 # determine the list of the packages belongs to the current SET...
690 echo -n $SPLIT \
691 | awk -vset="$SET" '
692 BEGIN { RS = " "; FS = ":"; }
693 { if ($2 == set) print $1; }' \
694 | while read SET_PKG; do
695 # ... and then pack them
696 packit $SET_PKG
697 done
698 fi
700 job_counter=$(($job_counter + 2))
701 }
704 # The main cook function.
706 cookit() {
707 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
708 _ 'ERROR: Broken setup. Abort.'
709 return
710 fi
712 title 'Cook: %s' "$PACKAGE $VERSION"
713 set_paths
714 timestamp init # the very start
716 # Handle cross-tools.
717 [ "$BUILD_SYSTEM" != "$HOST_SYSTEM" ] &&
718 case "$ARCH" in
719 arm*|x86_64)
720 # CROSS_COMPILE is used by at least Busybox and the kernel to set
721 # the cross-tools prefix. Sysroot is the root of our target arch
722 sysroot="$CROSS_TREE/sysroot"
723 tools="$CROSS_TREE/tools"
724 # Set root path when cross compiling. ARM tested but not x86_64
725 # When cross compiling we must install build deps in $sysroot.
726 arch="-$ARCH"
727 root="$sysroot"
728 _ '%s sysroot: %s' "$ARCH" "$sysroot"
729 _ 'Adding "%s" to PATH' "$tools/bin"
730 export PATH="$PATH:$tools/bin"
731 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
732 export CROSS_COMPILE="$HOST_SYSTEM-"
733 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
734 if [ "$ARCH" == 'x86_64' ]; then
735 export CC="$HOST_SYSTEM-gcc -m64"
736 export CXX="$HOST_SYSTEM-g++ -m64"
737 else
738 export CC="$HOST_SYSTEM-gcc"
739 export CXX="$HOST_SYSTEM-g++"
740 fi
741 export AR="$HOST_SYSTEM-ar"
742 export AS="$HOST_SYSTEM-as"
743 export RANLIB="$HOST_SYSTEM-ranlib"
744 export LD="$HOST_SYSTEM-ld"
745 export STRIP="$HOST_SYSTEM-strip"
746 export LIBTOOL="$HOST_SYSTEM-libtool"
747 ;;
748 esac
750 @@PREFIX@@/libexec/cookutils/precheck $receipt || exit 1 # former receipt_quality()
752 cd $pkgdir
753 [ -z "$continue" ] && rm -rf source 2>/dev/null
754 rm -rf install taz 2>/dev/null
756 # Disable -pipe if less than 512 MB free RAM.
757 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
758 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
759 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
760 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
761 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
762 fi
763 unset free
765 # Export flags and path to be used by make and receipt.
766 DESTDIR="$pkgdir/install"
767 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
768 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C \
769 LDFLAGS
771 timestamp job1 # pre-checks
773 # BUILD_DEPENDS may vary depending on the ARCH
774 case "$ARCH" in
775 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
776 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
777 esac
779 # Check for build deps and handle implicit depends of *-dev packages
780 # (ex: libusb-dev :: libusb).
781 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
782 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
784 # Get the list of installed packages
785 cd $root$INSTALLED; ls > $CACHE/installed.list
787 for action in check install; do
788 for dep in $BUILD_DEPENDS; do
789 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
790 for i in $dep $implicit; do
791 # Skip if package already installed
792 [ -f "$root$INSTALLED/$i/receipt" ] && continue
794 case $action in
795 check)
796 # Search for local package or local provided-package
797 name=$(awk -F$'\t' -vpkg="$i" '{
798 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
799 }' "$PKGS/packages.info")
800 if [ -z "$name" ]; then
801 # Search for package in mirror
802 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
803 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
804 fi
805 ;;
806 install)
807 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
808 ;;
809 esac
810 done
811 done
812 done
814 update_installed_cook_diff
816 timestamp job2 # installing bdeps
818 # Get source tarball and make sure we have source dir named:
819 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
820 # tarball if it exists.
821 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
822 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
823 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
824 LZMA_SRC=''
825 else
826 get_source || { broken; exit 1; }
827 fi
828 fi
829 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
830 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
831 if ! extract_source ; then
832 get_source
833 extract_source || { broken; exit 1; }
834 fi
835 if [ -n "$LZMA_SRC" ]; then
836 cd $pkgdir/source
837 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
838 mv tmp tmp-1; mkdir tmp
839 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
840 fi
841 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
842 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
843 fi
844 fi
846 cd $pkgdir/source/tmp
847 # Some archives are not well done and don't extract to one dir (ex lzma).
848 files=$(ls | wc -l)
849 [ "$files" -eq 1 -a -d "$(ls)" ] &&
850 mv * ../$PACKAGE-$VERSION
851 [ "$files" -eq 1 -a -f "$(ls)" ] &&
852 mkdir -p ../$PACKAGE-$VERSION &&
853 mv * ../$PACKAGE-$VERSION/$TARBALL
854 [ "$files" -gt 1 ] &&
855 mkdir -p ../$PACKAGE-$VERSION &&
856 mv * ../$PACKAGE-$VERSION
857 cd ..; rm -rf tmp
858 fi
860 # Check md5sum (or similar) for sources tarball
861 check_integrity
863 # Libtool shared libs path hack.
864 case "$ARCH" in
865 arm*) cross libhack ;;
866 esac
868 timestamp job3 # get/unpack src tarball
870 # Compiling all the sets
871 if grep -q ^compile_rules $receipt; then
872 _ 'Executing: %s' 'compile_rules'
873 echo "CFLAGS : $CFLAGS"
874 echo "LDFLAGS : $LDFLAGS"
875 [ -d "$src" ] && cd $src
876 patchit
878 timestamp job4 # patching
880 # Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
881 # Keep natural order of the sets, don't sort them alphabetically
882 SETS=$(echo -n $SPLIT \
883 | awk '
884 BEGIN { RS = " "; FS = ":"; }
885 {
886 if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; }
887 }' \
888 | sed 's| $||')
889 # Prepare specified source sets using patched sources
890 [ -n "$SETS" -a -d "$src" ] &&
891 for set in $SETS; do
892 echo "Preparing set $set" # debug
893 cp -a $src $src-$set
894 done
896 timestamp job5 # preparing sets
897 timestamp sets "$SETS"
899 job_counter='6'
901 SET='' cook_set # first run for empty SET
903 # Allow to change SETS after the first run, follow the changes
904 SETS=$(. $receipt; echo -n $SPLIT \
905 | awk '
906 BEGIN { RS = " "; FS = ":"; }
907 {
908 if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; }
909 }' \
910 | sed 's| $||')
911 for SET in $SETS; do
912 cook_set
913 done
914 else
915 mkdir -p $install # allow receipts without `compile_rules()`
916 fi
917 footer
919 timestamp job # reset counter
921 # Execute testsuite.
922 if grep -q ^testsuite $receipt; then
923 title 'Running testsuite'
924 testsuite $@ || { broken; exit 1; }
925 footer
926 fi
928 timestamp job26 # test suite
930 update_installed_cook_diff force
931 }
934 # Cook quality assurance.
936 cookit_quality() {
937 while true; do
938 [ ! -d "$WOK/$pkg/install" -a -z "$WANTED" ] || break
939 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
940 [ "$trials" == 'yes' ] || break
941 title "Interactive mode"
942 # TODO: allow commands:
943 # q - quit; v - edit receipt here using vi;
944 # s - search for package containing package;
945 # <package name> - install package; [Enter] - retry
946 _ 'You may install the packages here and/or edit the receipt there.'
947 newline
948 while true; do
949 _n 'Install the package? [name/N] '; read answer
950 [ -n "$answer" ] || break
951 tazpkg -gi $answer --root=$root --local --quiet --cookmode
952 done
953 newline
954 _n 'Try again? [Y/n] '; read answer
955 [ "$answer" == 'n' ] && break
956 # here you may append log if you want (">>" instead of last ">")
957 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
958 done
960 [ "${COOKOPTS/skip-log-errors/}" != "$COOKOPTS" ] && return 0
962 # ERROR can be echoed any time in cookit()
963 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
964 grep -Eq "(^ERROR|undefined reference to)" ; then
965 debug_info | tee -a $LOGS/$pkg.log
966 put_status $pkg Failed
967 rm -f $command
968 broken; exit 1
969 fi
970 }
973 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
974 # but it doesn't handle EXTRAVERSION.
976 packit() {
977 set_paths "$1"
978 PACKAGE="${1:-$PACKAGE}"
980 # Handle cross compilation
981 case "$ARCH" in
982 arm*|x86_64) arch="-$ARCH" ;;
983 esac
985 title 'Pack: %s' "$PACKAGE $VERSION$arch"
987 # Get set name for specified package from $SPLIT variable
988 local set=$(echo -n $SPLIT \
989 | awk -vpkg="$PACKAGE" '
990 BEGIN { RS = " "; FS = ":"; }
991 { if ($1 == pkg && $2 != "") { print "-" $2; exit; } }')
992 # Change set, make filelist and folderlist for new set
993 export src="$src$set"
994 export install="$install$set"
995 export DESTDIR="$install"
997 if grep -q ^genpkg_rules $receipt; then
998 _ 'Executing: %s' 'genpkg_rules'
999 set -e; cd $pkgdir; mkdir -p $fs
1000 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
1001 $LOGS/$pkg.log
1002 else
1003 _ 'No packages rules: meta package'
1004 mkdir -p $fs
1005 fi
1007 # Check CONFIG_FILES
1008 if [ -n "$CONFIG_FILES" ]; then
1009 unset IFS
1010 for i in $CONFIG_FILES; do
1011 if [ ! -e $fs$i ]; then
1012 case $i in
1013 */) mkdir -p $fs$i ;;
1014 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
1015 esac
1016 fi
1017 done
1018 fi
1020 # First QA check to stop now if genpkg_rules failed.
1021 lerror=$(_n 'ERROR')
1022 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1023 broken; exit 1
1024 fi
1026 cd $taz
1027 action 'Copying "%s"...' 'receipt'
1028 export PACKAGE VERSION CATEGORY SHORT_DESC WEB_SITE DEPENDS PROVIDE SUGGESTED TAZPANEL_DAEMON TAGS CAT CONFIG_FILES
1029 @@PREFIX@@/libexec/cookutils/mk_pkg_receipt "$(realpath ../receipt)" > $pack/receipt
1030 chown 0.0 $pack/receipt; status
1032 unset desc
1033 [ "$pkg" == "$PACKAGE" -a -f "../description.txt" ] && desc="../description.txt"
1034 [ -f "../description.$PACKAGE.txt" ] && desc="../description.$PACKAGE.txt"
1035 if [ -n "$desc" ]; then
1036 action 'Copying "%s"...' "$(basename "$desc")"
1037 cp -f $desc $pack/description.txt; chown 0.0 $pack/description.txt; status
1038 fi
1040 copy_generic_files
1042 # Strip and stuff files.
1043 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
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 | sort -k2 > 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 archive.
1069 action 'Compressing the FS...'
1070 find fs -newer $receipt -exec touch -hr $receipt '{}' \;
1071 # find fs | cpio -o -H newc --quiet | lzma-alone e fs.cpio.lzma -si
1072 find fs | cpio -o -H newc --quiet | /bin/lzma -qzeT0 >fs.cpio.lzma
1073 mv fs ../
1074 status
1076 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
1077 2>/dev/null | awk 'END{ print $1 }')
1079 action 'Updating receipt sizes...'
1080 sed -i '/^PACKED_SIZE=/d; /^UNPACKED_SIZE=/d' receipt
1081 sed -i "s|^PACKAGE=|PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=|" receipt
1082 status
1084 # Set extra version.
1085 if [ -n "$EXTRAVERSION" ]; then
1086 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
1087 sed -i '/^EXTRAVERSION=/d' receipt
1088 sed -i "s|^VERSION=|EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=|" receipt
1089 status
1090 fi
1092 # Compress.
1093 action 'Creating full cpio archive...'
1094 find . -newer $receipt -exec touch -hr $receipt '{}' \;
1095 find . | cpio -o -H newc --quiet > ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1096 status
1098 # Restoring original package tree.
1099 mv ../fs .
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 local arch=''
1114 case "$ARCH" in
1115 arm*|x86_64) arch="-$ARCH" ;;
1116 esac
1118 local rsum rsumold='' rsum_changed old_file
1119 local pi="$PKGS/packages.info" fl="$cache/files.list"
1120 local pkg_file="$PKGS/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg"
1121 local rsum_file=$(mktemp) rsum_file_old=$(mktemp) tmpdir=$(mktemp -d)
1124 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ]; then
1125 # Exit if any error found in log file.
1126 if fgrep -q ^ERROR $LOGS/$pkg.log; then
1127 rm -f $command
1128 broken; exit 1
1129 fi
1130 fi
1133 [ -n "$CAT" ] && CATEGORY="${CAT%|*}" # allow meta-packages in v2 receipts
1135 if [ "${COOKOPTS/empty-pkg/}" == "$COOKOPTS" ]; then
1136 action 'QA: checking for empty package...'
1137 if [ ! -s "$pack/files.list" -a "$CATEGORY" != 'meta' ]; then
1138 broken
1139 rm -f $command
1140 false; status
1141 die 'ERROR: empty package'
1142 fi
1143 :; status
1144 fi
1147 # Calculate release checksum: usually it does not change on "just recook".
1148 # Release checksum is md5sum of file containing md5sums of:
1149 # a) all files, b) receipt, and c) description.txt.
1150 # Md5sum of the package file will change every time because of embedded timestamps;
1151 # release checksum based only on files content, and will change only when files change.
1152 # (Pitfall: ownership and permissions...)
1154 # Calculate rsum for new package
1155 cp $pack/md5sum $rsum_file
1156 md5sum $pack/receipt | sed 's| [^ ]*/| |' >> $rsum_file
1157 [ -e "$pack/description.txt" ] &&
1158 md5sum $pack/description.txt | sed 's| [^ ]*/| |' >> $rsum_file
1159 rsum=$(md5sum $rsum_file | awk '{print $1}')
1161 # Calculate rsum for existing previous "old" package
1162 if [ -f "$pkg_file" ]; then
1163 # don't trust database entry, check the package file
1164 cd $tmpdir
1165 cpio -F "$pkg_file" -i md5sum receipt description.txt >/dev/null 2>&1
1166 cp ./md5sum $rsum_file_old
1167 md5sum ./receipt | sed 's| [^ ]*/| |' >> $rsum_file_old
1168 [ -e "./description.txt" ] &&
1169 md5sum ./description.txt | sed 's| [^ ]*/| |' >> $rsum_file_old
1170 rsumold=$(md5sum $rsum_file_old | awk '{print $1}')
1171 cd - >/dev/null
1172 fi
1174 # Clean
1175 rm $rsum_file $rsum_file_old
1176 rm -r $tmpdir
1179 touch $pi $broken
1182 # Find and remove old package only if "release checksum" has changed
1184 if [ "$rsum" != "$rsumold" ]; then
1185 old_file=$(awk -F$'\t' -vname="$PACKAGE" -varch="$arch" '{
1186 if ($1 == name) printf("%s-%s%s.tazpkg", $1, $2, arch);
1187 }' $pi) # <name>-<version><extra_version><-arch>.tazpkg
1188 if [ -f "$PKGS/$old_file" ]; then
1189 action 'Removing old package "%s"' "$old_file"
1190 rm -f "$PKGS/$old_file"
1191 status
1192 fi
1193 # package changed, substitute old package by new one
1194 mv -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg $PKGS
1195 _ 'The release checksum has changed.'
1196 else
1197 # package not changed, remove new package
1198 rm -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1199 _ 'The release checksum has not changed.'
1200 fi
1203 sed -i "/^${pkg}$/d" $broken
1206 # Update packages database every time after successful build
1208 # packages.info (unsorted, located near to packages)
1209 unset_receipt; . $pack/receipt
1210 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1211 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1212 sed -i "/^$PACKAGE\t/d" $pi # remove old entry
1213 cat >> $pi <<EOT
1214 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $rsum $PROVIDE
1215 EOT
1217 # files.list (uncompressed, unsorted, located in $cache)
1218 touch $fl
1219 sed -i "/^$PACKAGE: /d" $fl
1220 sed "s/^/$PACKAGE: \0/" $pack/files.list >> $fl
1224 # Return all the names of packages bundled in this receipt
1226 all_names() {
1227 # Get package names from $SPLIT variable
1228 local split=$(echo -n $SPLIT \
1229 | awk '
1230 BEGIN { RS = " "; FS = ":"; }
1231 { print $1; }' \
1232 | tr '\n' ' ')
1233 local split_space=" $split "
1234 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
1235 # For receipts v1: $SPLIT may present in the $WANTED package,
1236 # but split packages have their own receipts
1237 echo $PACKAGE
1238 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
1239 # $PACKAGE included somewhere in $SPLIT (probably in the end).
1240 # We should build packages in the order defined in the $SPLIT.
1241 echo $split
1242 else
1243 # We'll build the $PACKAGE, then all defined in the $SPLIT.
1244 echo $PACKAGE $split
1245 fi
1249 # v2: pack all packages using compiled files
1251 packall() {
1252 set_paths
1253 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1254 for i in $(all_names); do
1255 unset TAGS DEPENDS CAT CONFIG_FILES PROVIDE SUGGESTED DATABASE_FILES TAZPANEL_DAEMON
1256 packit $i
1257 done
1258 else
1259 packit
1260 fi
1264 # Reverse "cat" command: prints input lines in the reverse order
1266 tac() {
1267 sed '1!G;h;$!d' $1
1271 # Update chroot with freshly rebuilt package: keep env up-to-date.
1273 update_chroot() {
1274 local PACKAGE="$pkg"
1275 for i in $(all_names); do
1276 if [ -d "$root$INSTALLED/$i" ]; then
1277 . /etc/slitaz/cook.conf
1278 . $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt
1279 _ 'Updating %s chroot environment...' "$ARCH"
1280 _ 'Updating chroot: %s' "$i ($VERSION$EXTRAVERSION$arch)" | log
1281 cd $PKGS
1282 tazpkg -i "$PKGS/$i-$VERSION$EXTRAVERSION$arch.tazpkg" --forced --root=$root
1283 fi
1284 done
1288 # Install package on --inst or update the chroot.
1290 install_package() {
1291 set_paths
1292 case "$ARCH" in
1293 arm*)
1294 arch="-$ARCH"
1295 root="$CROSS_TREE/sysroot"
1296 ;;
1297 x86_64)
1298 arch="-$ARCH"
1299 ;;
1300 esac
1301 # Install package if requested but skip install if target host doesn't
1302 # match build system or it will break the build chroot.
1303 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1304 if [ -n "$inst" -a "$build" == "$ARCH" ]; then
1305 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg" ]; then
1306 cd $PKGS
1307 tazpkg -i "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg" --forced
1308 else
1309 broken
1310 die 'Unable to install package, build has failed.'
1311 fi
1312 fi
1314 update_chroot
1318 # remove chroot jail
1320 umount_aufs() {
1321 tac ${1}rw/aufs-umount.sh | sh
1322 rm -rf ${1}rw
1323 umount ${1}root
1324 rmdir ${1}r*
1328 # Launch the cook command into a chroot jail protected by aufs.
1329 # The current filesystems are used read-only and updates are
1330 # stored in a separate branch.
1332 try_aufs_chroot() {
1334 base="/dev/shm/aufsmnt$$"
1336 # Can we setup the chroot? Is it already done?
1337 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1338 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1339 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1340 grep -q ^aufs /proc/modules || modprobe aufs 2>/dev/null || return
1341 mkdir ${base}root ${base}rw || return
1343 _ 'Setup aufs chroot...'
1345 # Sanity check
1346 for i in / /proc /sys /dev /dev/shm /home; do
1347 case " $AUFS_MOUNTS " in
1348 *\ $i\ *) ;;
1349 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1350 esac
1351 done
1352 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1353 mkdir -p ${base}root$mnt # for `mount -o bind`
1354 mount -o bind $mnt ${base}root$mnt # use `-o bind` instead of `--bind`
1355 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1356 _ 'Aufs mount failure'
1357 umount ${base}root
1358 rm -rf ${base}r*
1359 return
1360 fi
1361 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1362 done
1363 trap "umount_aufs ${base}" INT
1365 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1366 status=$?
1368 _ 'Leaving aufs chroot...'
1369 umount_aufs $base
1370 # Install package outside the aufs jail
1371 install_package
1372 exit $status
1376 # Encode predefined XML entities
1378 xml_ent() {
1379 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1383 # Create a XML feed for freshly built packages.
1385 gen_rss() {
1386 pubdate=$(date '+%a, %d %b %Y %X')
1387 cat > $FEEDS/$pkg.xml <<EOT
1388 <item>
1389 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1390 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1391 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1392 <pubDate>$pubdate</pubDate>
1393 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1394 </item>
1395 EOT
1399 # Truncate stdout log file to $1 Mb.
1401 loglimit() {
1402 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1403 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1404 else
1405 tee /dev/stderr
1406 fi
1411 # Receipt functions to ease packaging
1414 get_dev_files() {
1415 action 'Getting standard devel files...'
1416 mkdir -p $fs/usr/lib
1417 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1418 cp -a $install/usr/lib/*a $fs/usr/lib
1419 cp -a $install/usr/include $fs/usr
1420 status
1424 # Function to use in compile_rules() to copy man page from $src to $install
1426 cook_pick_manpages() {
1427 local name section
1428 action 'Copying man pages...'
1430 for i in $@; do
1431 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1432 section=${name##*/}; section=${section##*.}
1433 mkdir -p $install/usr/share/man/man$section
1434 scopy $i $install/usr/share/man/man$section
1435 done
1436 status
1440 # Function to use in compile_rules() to copy documentation from $src to $install
1442 cook_pick_docs() {
1443 local docdir="$install/usr/share/doc/$PACKAGE-$VERSION"
1444 action 'Copying documentation...'
1445 mkdir -p $docdir
1446 cp -r $@ $docdir
1447 chmod -R a+r $docdir
1448 status
1452 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1454 cook_copy_files() {
1455 action 'Copying files...'
1456 cd $install
1457 local i j
1458 IFS=$'\n'
1459 for i in $@; do
1460 for j in $(find . -name $i ! -type d); do
1461 mkdir -p $fs$(dirname ${j#.})
1462 scopy $j $fs$(dirname ${j#.})
1463 done
1464 done
1465 cd - >/dev/null
1466 status
1470 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1472 cook_copy_folders() {
1473 action 'Copying folders...'
1474 cd $install
1475 local i j
1476 IFS=$'\n'
1477 for i in $@; do
1478 for j in $(find . -name $i -type d); do
1479 mkdir -p $fs$(dirname ${j#.})
1480 cp -a $j $fs$(dirname ${j#.})
1481 done
1482 done
1483 cd - >/dev/null
1484 status
1488 # Remove from current $fs files that are already packed (for receipts v2).
1489 # Note: the order in $SPLIT is very important.
1490 # Note 2: working in the current set.
1492 remove_already_packed() {
1493 local i j
1494 # $pkg is the name of the main package; $PACKAGE is the name of the current one
1495 # $pkg may (or may not) be included in the $SPLIT
1496 neighbors=$(
1497 echo $pkg $SPLIT" " \
1498 | awk -F$'\t' -vpkg="$PACKAGE" '
1499 BEGIN { RS = " "; FS = ":"; }
1500 { set[$1] = $2; }
1501 END {
1502 current_set = set[pkg];
1503 for (i in set)
1504 { if (i != pkg && set[i] == current_set) print i; }
1506 ')
1507 IFS=$'\n'
1508 for neighbor in $neighbors; do
1509 i="$taz/$neighbor-$VERSION$EXTRAVERSION/files.list"
1510 [ -e "$i" ] || continue
1511 while read j; do
1512 [ -f $fs$j -o -h $fs$j ] || continue
1513 rm $fs$j
1514 rmdir --parents --ignore-fail-on-non-empty $fs$(dirname $j)
1515 done < $i
1516 done
1517 unset IFS
1521 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1522 # (default: 16 and 48) from $install to $fs
1524 cook_copy_icons() {
1525 local sizes=$@ i j ifs="$IFS"
1526 unset IFS
1527 action 'Copying hicolor icons...'
1528 [ -d "$fs/usr/share/icons/hicolor" ] && rm -rf "$fs/usr/share/icons/hicolor"
1529 mkdir -p $fs/usr/share/icons/hicolor
1530 for i in ${sizes:-16 48}; do
1531 j="${i}x$i"; [ "$i" == 'scalable' ] && j="$i"
1532 [ ! -e "$install/usr/share/icons/hicolor/$j" ] ||
1533 scopy $install/usr/share/icons/hicolor/$j \
1534 $fs/usr/share/icons/hicolor
1535 done
1536 status
1537 IFS="$ifs"
1541 # Common function to copy files, folders and patterns
1543 copy() {
1544 action 'Copying folders and files...'
1545 local i j k filelist=$(mktemp) folderlist=$(mktemp)
1547 IFS=$'\n'
1548 cd $install
1549 find ! -type d | sed 's|\.||' > $filelist
1550 find -type d | sed 's|\.||' > $folderlist
1552 for i in $@; do
1553 case $i in
1554 @std)
1555 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1556 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /\.pri$/d; /bin\/.*-config$/d;
1557 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1558 /\/Makefile.*/d; /\.inc$/d; /\/include\//d;
1559 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1560 /\/share\/devhelp\//d; /\/share\/locale\//d;
1561 /\/share\/bash-completion\//d; /\/etc\/bash_completion\.d\//d; /\/lib\/systemd\//d;
1562 /\/fonts\.scale$/d; /\/fonts\.dir$/d;
1563 /\/share\/appdata\//d; /\/share\/help\//d; /\/share\/metainfo\//d;
1564 /\/share\/icons\/hicolor\/[12356][1245][268]*x[12356][1245][268]*\//d; # 22, 24, 32, 64, 128, 256, 512
1565 /\.so\.dbg$/d;
1566 ' $filelist
1567 ;;
1568 @dev)
1569 # Copy "developer files"
1570 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.pc$/p; /\.pri$/p; /bin\/.*-config$/p;
1571 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1572 /\/Makefile.*/p; /\.inc$/p; /\/include\//p;
1573 /\.so\.dbg$/p;
1574 ' $filelist
1575 ;;
1576 @rm)
1577 # Quick alias
1578 remove_already_packed
1579 ;;
1580 @ico)
1581 # Quick alias
1582 cook_copy_icons >/dev/null
1583 ;;
1584 */)
1585 # Copy specified folders.
1586 i="${i%/}"
1587 find -type d -path "*/${i#/}" | sed 's|^.||'
1588 ;;
1589 *)
1590 # Copy specified files.
1591 find ! -type d -path "*/${i#/}" | sed 's|^.||'
1592 ;;
1593 esac \
1594 | sort -u \
1595 | while read j; do
1596 mkdir -p $fs$(dirname "$j")
1597 if [ -d "$install$j" ]; then
1598 cp -a "$install$j" $fs$(dirname "$j")
1599 else
1600 scopy "$install$j" $fs$(dirname "$j")
1601 fi
1602 done
1603 # Copy empty directories
1604 case $i in
1605 @std)
1606 while read j; do
1607 case $j in
1608 # skip empty man & doc folders
1609 */man/*|*/doc/*) continue;;
1610 esac
1611 [ -z "$(ls -A "$install$j")" ] || continue
1612 # directory $j is empty
1613 k="$j"
1614 # make 'ladder' from directories, from root dir to $j
1615 # /a /a/b /a/b/c etc.
1616 while :; do
1617 [ -z "$k" ] && break
1618 echo "$k"
1619 k="${k%/*}"
1620 done \
1621 | tac \
1622 | while read k; do
1623 # make dir if it does not exist
1624 if [ ! -d "$fs$k" ]; then
1625 # It's like "copy the directory without its underlying content".
1626 # keep original ownership/permissions, access:
1627 keepIFS="$IFS"; unset IFS
1628 install -d $(stat -c'-o%u -g%g -m%a' "$install$k") "$fs$k"
1629 # keep last-modified date:
1630 touch -r "$install$k" "$fs$k"
1631 IFS="$keepIFS"; unset keepIFS
1632 fi
1633 done
1634 done < $folderlist
1635 ;;
1636 esac
1637 done
1638 cd - >/dev/null
1639 unset IFS
1640 rm $filelist $folderlist
1641 status
1645 # Update split.db once for receipt
1647 update_split_db() {
1648 local db="$cache/split.db"
1649 touch $db
1650 sed -i "/^$pkg\t/d" $db
1651 echo -e "$pkg\t$(all_names)" >> $db
1655 # Recreate whole split.db from scratch
1657 recreate_split_db() {
1658 # Clean
1659 local db="$cache/split.db"
1660 touch $db
1661 > $db
1663 cd $WOK
1664 for pkg in *; do
1665 [ -f "$WOK/$pkg/receipt" ] || continue
1666 unset PACKAGE SPLIT
1667 . $WOK/$pkg/receipt
1668 echo -e "$PACKAGE\t$(all_names)" >> $db
1669 done
1673 # Put the status to the activity log
1675 put_status() {
1676 # $1: package, $2: status, one of 'Done', 'Failed'
1677 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1678 if [ "$2" == 'Done' ]; then
1679 # overstrike all previous 'Failed' to indicate package is OK now
1680 sed -i "/>$1<\/a>/ s|\[ Failed \]|[ -Failed ]|" $activity
1681 fi
1688 # Commands
1691 # cook <package> --deps
1692 [ -n "$deps" ] && {
1693 @@PREFIX@@/libexec/cookutils/deps $1
1694 exit 0
1697 # cook <package> --clean
1698 # cook <package> -c
1699 [ -n "$clean" -o "$2" == '-c' ] && {
1700 action 'Cleaning "%s"' "$1"
1701 cd $WOK/$1; rm -rf install taz source
1702 status; newline
1703 touch $activity # update $activity -> something changed -> update webstat
1704 exit 0
1707 # cook <package> --getsrc
1708 # cook <package> -gs
1709 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1710 title 'Getting source for "%s"' "$1"
1711 receipt="$WOK/$pkg/receipt"
1712 check_pkg_in_wok
1713 unset_receipt
1714 . $receipt
1715 get_source
1716 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1717 exit 0
1720 # cook <package> --block
1721 # cook <package> -b
1722 [ -n "$block" -o "$2" == '-b' ] && {
1723 action 'Blocking package "%s"' "$1"
1724 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1725 status; newline
1726 touch $activity
1727 exit 0
1730 # cook <package> --unblock
1731 # cook <package> -ub
1732 [ -n "$unblock" -o "$2" == '-ub' ] && {
1733 action 'Unblocking package "%s"' "$1"
1734 sed -i "/^$1$/d" $blocked
1735 status; newline
1736 touch $activity
1737 exit 0
1743 case "$1" in
1744 usage|help|-u|-h)
1745 usage ;;
1747 list-wok)
1748 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1749 cd $WOK
1750 if [ "$ARCH" != 'i486' ]; then
1751 count=0
1752 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1753 do
1754 unset HOST_ARCH
1755 . ./$pkg
1756 count=$(($count + 1))
1757 colorize 34 "$PACKAGE"
1758 done
1759 else
1760 count=$(ls | wc -l)
1761 ls -1
1762 fi
1763 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1764 ;;
1766 activity)
1767 cat $activity ;;
1769 search)
1770 # Just a simple search function, we don't need more actually.
1771 query="$2"
1772 title 'Search results for "%s"' "$query"
1773 cd $WOK; ls -1 | grep "$query"
1774 footer ;;
1776 setup)
1777 # Setup a build environment
1778 check_root
1779 _ 'Cook: setup environment' | log
1780 title 'Setting up your environment'
1781 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1782 cd $SLITAZ
1783 init_db_files
1784 _ 'Checking for packages to install...'
1785 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1786 # ARCH-setup or 'cross check' should be used before: cook setup
1787 case "$ARCH" in
1788 arm*|x86_64)
1789 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1790 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1791 . /etc/slitaz/cross.conf ;;
1792 esac
1793 for pkg in $SETUP_PKGS; do
1794 if [ -n "$forced" ]; then
1795 tazpkg -gi $pkg --forced
1796 else
1797 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1798 fi
1799 done
1801 # Handle --options
1802 case "$2" in
1803 --wok) hg clone $WOK_URL wok || exit 1 ;;
1804 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1805 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1806 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1807 esac
1809 # SliTaz group and permissions
1810 if ! grep -q ^slitaz /etc/group; then
1811 _ 'Adding group "%s"' 'slitaz'
1812 addgroup slitaz
1813 fi
1814 _ 'Setting permissions for group "%s"...' 'slitaz'
1815 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1816 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1817 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1819 *-setup)
1820 # Setup for cross compiling.
1821 arch="${1%-setup}"
1822 check_root
1823 . /etc/slitaz/cook.conf
1824 for pkg in $CROSS_SETUP; do
1825 if [ -n "$forced" ]; then
1826 tazpkg -gi $pkg --forced
1827 else
1828 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1829 fi
1830 done
1832 _ 'Cook: setup %s cross environment' "$arch" | log
1833 title 'Setting up your %s cross environment' "$arch"
1834 init_db_files
1835 sed -i \
1836 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1837 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1838 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1839 /etc/slitaz/cook.conf
1840 case "$arch" in
1841 arm)
1842 flags='-O2 -march=armv6'
1843 host="$ARCH-slitaz-linux-gnueabi" ;;
1844 armv6hf)
1845 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1846 host="$ARCH-slitaz-linux-gnueabi" ;;
1847 armv7)
1848 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1849 host="$ARCH-slitaz-linux-gnueabi" ;;
1850 x86_64)
1851 flags='-O2 -mtune=generic -pipe'
1852 host="$ARCH-slitaz-linux" ;;
1853 esac
1854 sed -i \
1855 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1856 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1857 . /etc/slitaz/cook.conf
1858 sysroot="$CROSS_TREE/sysroot"
1859 tools="/cross/$arch/tools"
1860 root="$sysroot"
1861 # L10n: keep the same width of translations to get a consistent view
1862 _ 'Target arch : %s' "$ARCH"
1863 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1864 _ 'Build flags : %s' "$flags"
1865 _ 'Arch sysroot : %s' "$sysroot"
1866 _ 'Tools prefix : %s' "$tools/bin"
1867 # Tell the packages manager where to find packages.
1868 _ 'Packages DB : %s' "$root$DB"
1869 mkdir -p $root$INSTALLED
1870 cd $root$DB; rm -f *.bak
1871 for list in packages.list packages.desc packages.equiv packages.md5; do
1872 rm -f $list
1873 ln -s $SLITAZ/packages/$list $list
1874 done
1875 # We must have the cross compiled glibc-base installed or default
1876 # i486 package will be used as dep by tazpkg and then break the
1877 # cross environment
1878 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1879 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1880 fi
1881 # Show GCC version or warn if not yet compiled.
1882 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1883 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1884 else
1885 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1886 _ 'Run "%s" to cook a toolchain' 'cross compile'
1887 fi
1888 footer ;;
1890 test)
1891 # Test a cook environment.
1892 _ 'Cook test: testing the cook environment' | log
1893 [ ! -d "$WOK" ] && exit 1
1894 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1895 cook cooktest ;;
1897 new)
1898 # Create the package folder and an empty receipt.
1899 pkg="$2"
1900 [ -z "$pkg" ] && usage
1901 newline
1902 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1904 action 'Creating folder "%s"' "$WOK/$pkg"
1905 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1907 action 'Preparing the package receipt...'
1908 cp $DATA/receipt .
1909 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1910 status; newline
1912 # Interactive mode, asking and seding.
1913 case "$3" in
1914 --interactive|-x)
1915 _ 'Entering interactive mode...'
1916 separator
1917 _ 'Package : %s' "$pkg"
1919 _n 'Version : ' ; read answer
1920 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1922 _n 'Category : ' ; read answer
1923 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1925 # L10n: Short description
1926 _n 'Short desc : ' ; read answer
1927 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1929 _n 'Maintainer : ' ; read answer
1930 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1932 _n 'License : ' ; read answer
1933 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1935 _n 'Web site : ' ; read answer
1936 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1937 newline
1939 # Wget URL.
1940 _ 'Wget URL to download source tarball.'
1941 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1942 _n 'Wget url : ' ; read answer
1943 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1945 # Ask for a stuff dir.
1946 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1947 if [ "$?" -eq 0 ]; then
1948 action 'Creating the stuff directory...'
1949 mkdir $WOK/$pkg/stuff; status
1950 fi
1952 # Ask for a description file.
1953 confirm "$(_n 'Are you going to write a description? (y/N)')"
1954 if [ "$?" -eq 0 ]; then
1955 action 'Creating the "%s" file...' 'description.txt'
1956 touch $WOK/$pkg/description.txt; status
1957 fi
1959 footer "$(_ 'Receipt is ready to use.')" ;;
1960 esac ;;
1962 list)
1963 # Cook a list of packages (better use the Cooker since it will order
1964 # packages before executing cook).
1965 check_root
1966 [ -z "$2" ] && die 'No list in argument.'
1967 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1969 _ 'Starting cooking the list "%s"' "$2" | log
1971 while read pkg; do
1972 cook $pkg || broken
1973 done < $2
1974 ;;
1976 clean-wok)
1977 check_root
1978 newline; action 'Cleaning all packages files...'
1979 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1980 status; newline ;;
1982 clean-src)
1983 check_root
1984 newline; action 'Cleaning all packages sources...'
1985 rm -rf $WOK/*/source
1986 status; newline ;;
1988 uncook)
1989 cd $WOK
1990 count=0
1991 title 'Checking for uncooked packages'
1993 for i in *; do
1994 unset HOST_ARCH EXTRAVERSION
1995 [ ! -e $i/receipt ] && continue
1996 . ./$i/receipt
1997 # Source cooked pkg receipt to get EXTRAVERSION
1998 if [ -d "$WOK/$i/taz" ]; then
1999 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
2000 . ./receipt; cd $WOK
2001 fi
2002 case "$ARCH" in
2003 i486)
2004 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
2005 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
2006 count=$(($count + 1))
2007 colorize 34 "$i"
2008 fi ;;
2009 arm*)
2010 # Check only packages included in arch
2011 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
2012 # *.tazpkg
2013 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
2014 count=$(($count + 1))
2015 colorize 34 "$i"
2016 fi
2017 fi ;;
2018 esac
2019 done
2021 if [ "$count" -gt 0 ]; then
2022 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
2023 else
2024 _ 'All packages are cooked :-)'
2025 newline
2026 fi
2027 ;;
2029 pkgdb)
2030 # Create suitable packages list for TazPkg and only for built packages
2031 # as well as flavors files for TazLiTo. We don't need logs since we do it
2032 # manually to ensure everything is fine before syncing the mirror.
2033 recreate_split_db
2034 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
2035 ;;
2037 splitdb)
2038 # File split.db is useful for searching for split packages.
2039 recreate_split_db
2040 ;;
2042 *)
2043 # Just cook and generate a package.
2044 check_root
2045 time=$(date +%s)
2046 pkg="$1"
2047 [ -z "$pkg" ] && usage
2049 # Search last successful cook time in all logs from newer to older
2050 for i in '' $(seq 0 9 | sed 's|^|.|'); do
2051 [ -f "$LOGS/$pkg.log$i" ] || break
2052 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
2053 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
2054 [ -n "$lastcooktime" ] && break
2055 done
2057 receipt="$WOK/$pkg/receipt"
2058 check_pkg_in_wok
2059 newline
2061 unset inst
2062 unset_receipt
2063 . $receipt
2065 # Handle cross compilation.
2066 case "$ARCH" in
2067 arm*)
2068 if [ -z "$HOST_ARCH" ]; then
2069 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
2070 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
2071 _ 'cook: %s' "$error"
2072 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2073 _ 'Cook skip: %s' "$error" | log
2074 newline
2075 broken; exit 1
2076 fi ;;
2077 esac
2079 # Some packages are not included in some arch or fail to cross compile.
2080 : ${HOST_ARCH=$ARCH}
2081 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
2082 # Handle arm{v6hf,v7,..}
2083 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
2084 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
2085 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
2086 _ 'cook: %s' "error"
2087 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2088 _ 'Cook skip: %s' "$error" | log
2089 sed -i "/^${pkg}$/d" $broken
2090 newline
2091 exit 0
2092 fi
2094 # Skip blocked, 3 lines also for the Cooker.
2095 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
2096 die 'Package "%s" is blocked' "$pkg"
2098 try_aufs_chroot "$@"
2100 # Log and source receipt.
2101 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
2102 echo "cook:$pkg" > $command
2104 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
2106 while read cmd duration start; do
2107 [ $(($start + $duration)) -lt $(date +%s) ] &&
2108 echo "sed -i '/^$cmd $duration/d' $cooktime"
2109 done < $cooktime | sh
2111 # Display and log info if cook process stopped.
2112 # FIXME: gettext not working (in single quotes) here!
2113 trap '_ "\n\nCook stopped: control-C\n\n" | \
2114 tee -a $LOGS/$pkg.log' INT
2116 update_split_db
2118 # Handle --options
2119 case "$2" in
2120 --install|-i)
2121 inst='yes' ;;
2123 --pack)
2124 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
2125 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
2126 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -f $LOGS/$pkg-pack.log
2127 sed -i '$ s|$| (packing)|' $activity
2128 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
2129 clean_log "$pkg-pack"
2130 time=$(($(date +%s) - $time))
2131 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
2132 put_status $pkg Done
2133 rm -f $command
2134 exit 0 ;;
2136 --trials|-t)
2137 trials='yes' ;;
2138 esac
2140 # Rotate log
2141 for i in $(seq 9 -1 1); do
2142 j=$(($i - 1))
2143 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2144 done
2145 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2147 # Check if wanted is built now so we have separate log files.
2148 for wanted in $WANTED ; do
2149 if grep -q "^$wanted$" $blocked; then
2150 broken
2151 rm -f $command
2152 die 'WANTED package "%s" is blocked' "$wanted"
2153 fi
2154 if grep -q "^$wanted$" $broken; then
2155 broken
2156 rm -f $command
2157 die 'WANTED package "%s" is broken' "$wanted"
2158 fi
2159 if [ ! -d "$WOK/$wanted/install" ]; then
2160 cook "$wanted" || { broken; exit 1; }
2161 fi
2162 done
2164 # Cook and pack or exit on error and log everything.
2165 ((((cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq))
2166 rq=$? # the return code of `cookit $@` above command
2168 # Remove build dependencies both when `cookit` done or fail
2169 remove_deps | tee -a $LOGS/$pkg.log
2170 timestamp job27 # removing bdeps
2171 cookit_quality
2172 timestamp job28 # checking quality
2174 # Log and stop if `cookit` fails
2175 if [ $rq -eq 1 ]; then
2176 debug_info | tee -a $LOGS/$pkg.log
2177 put_status $pkg Failed
2178 rm -f $command
2179 broken; exit 1
2180 fi
2182 # Proceed only if `cookit` return code is zero-OK
2183 # If instant-pack if specified, then packages already packed in the cookit()
2184 [ "${COOKOPTS/instant-pack/}" == "$COOKOPTS" ] &&
2185 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2186 timestamp job29 # packing
2188 clean_log
2190 # Exit if any error in packing.
2191 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
2192 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2193 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2194 debug_info | tee -a $LOGS/$pkg.log
2195 put_status $pkg Failed
2196 rm -f $command
2197 broken; exit 1
2198 fi
2200 # Create an XML feed
2201 gen_rss
2203 # Time and summary
2204 time=$(($(date +%s) - $time))
2205 summary | tee -a $LOGS/$pkg.log
2206 newline
2208 # We may want to install/update (outside aufs jail!).
2209 [ -s /aufs-umount.sh ] || install_package
2211 put_status $pkg Done
2213 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2214 # If you want automation, use the Cooker Build Bot.
2215 rm -f $command
2216 timestamp job30 # misc. final operations
2217 store_timestats
2219 sed -n '/^Build dependencies to remove:/,/^$/p' $LOGS/$pkg.log \
2220 | sed '/^Build/d; s|Removing: ||' \
2221 | tr ' ' '\n' \
2222 | sed '/^$/d' \
2223 > $WOK/$pkg/.bdeps
2225 ;;
2226 esac
2228 exit 0