cookutils view cook @ rev 1130

cook: warn if checksum not defined for external patch
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Jan 07 11:24:09 2019 +0200 (2019-01-07)
parents e0fb0c452bf1
children a5e73bdcc218
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 --getsrc -gs $(_ 'get the package source tarball.')
50 --block -b $(_ 'block a package so cook will skip it.')
51 --unblock -ub $(_ 'unblock a blocked package.')
52 --cdeps $(_ 'check dependencies of cooked package.')
53 --pack $(_ 'repack an already built package.')
54 --debug $(_ 'display debugging messages.')
55 --continue $(_ 'continue running compile_rules.')
56 cook new <pkg>
57 --interactive -x $(_ 'create a receipt interactively.')
58 cook setup
59 --wok $(_ 'clone the cooking wok from Hg repo.')
60 --stable $(_ 'clone the stable wok from Hg repo.')
61 --undigest $(_ 'clone the undigest wok from Hg repo.')
62 --tiny $(_ 'clone the tiny SliTaz wok from Hg repo.')
63 --forced $(_ 'force reinstall of chroot packages.')
64 cook pkgdb
65 --flavors $(_ 'create up-to-date flavors files.')
66 cook splitdb $(_ 'create up-to-date split.db file.')
68 EOT
69 exit 0
70 }
73 # We don't want these escapes in web interface.
75 clean_log() {
76 sed -i -e 's|\[70G\[ \[1;32m| |' \
77 -e 's|\[0;39m \]||' $LOGS/${1:-$pkg}.log
78 }
81 # Be sure package exists in wok.
83 check_pkg_in_wok() {
84 [ -d "$WOK/$pkg" ] || die 'Unable to find package "%s" in the wok' "$pkg"
85 }
88 # Find the package, return the receipt name where it was found
89 # for example, libpcreposix -> pcre
91 find_pkg_in_wok() {
92 awk -F$'\t' -vi=" $1 " '{
93 if (index(" " $2 " ", i)) {print $1; exit}
94 }' $cache/split.db
95 }
98 # Initialize files used in $CACHE
100 init_db_files() {
101 _ 'Creating directories structure in "%s"' "$SLITAZ"
102 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
103 _ 'Creating DB files in "%s"' "$CACHE"
104 touch $activity $command $broken $blocked $CACHE/webstat
105 chown www:www $cache/webstat
106 }
109 # Paths used in receipt and by cook itself.
111 set_paths() {
112 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
113 if [ -f "$WOK/linux/receipt" ]; then
114 kvers=$(. $WOK/linux/receipt; echo $VERSION)
115 kbasevers=$(echo $kvers | cut -d. -f1,2)
116 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
117 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
118 kbasevers=$(echo $kvers | cut -d. -f1,2)
119 fi
121 # Python version
122 [ -f "$WOK/python/receipt" ] && pyvers=$(. $WOK/python/receipt; echo $VERSION)
123 # Perl version for some packages needed it
124 [ -f "$WOK/perl/receipt" ] && perlvers=$(. $WOK/perl/receipt; echo $VERSION)
126 pkgdir="$WOK/$pkg"
127 . "$pkgdir/receipt"
128 basesrc="$pkgdir/source"
129 tmpsrc="$basesrc/tmp"
130 src="$basesrc/$PACKAGE-$VERSION"
131 taz="$pkgdir/taz"
132 pack="$taz/${1:-$PACKAGE}-$VERSION$EXTRAVERSION" # v2: multiple taz/* folders
133 fs="$pack/fs"
134 stuff="$pkgdir/stuff"
135 install="$pkgdir/install"
137 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
138 lzma_tarball="$pkgsrc.tar.lzma"
140 [ -n "$PATCH" -a -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
142 if [ -n "$WANTED" ]; then
143 basesrc="$WOK/$WANTED/source"
144 src="$basesrc/$WANTED-$VERSION"
145 install="$WOK/$WANTED/install"
146 wanted_stuff="$WOK/$WANTED/stuff"
147 fi
149 [ -n "$SOURCE" ] && source_stuff="$WOK/$SOURCE/stuff"
151 # Old way compatibility.
152 _pkg="$install"
153 }
156 # Create source tarball when URL is a SCM.
158 create_tarball() {
159 local tarball
160 tarball="$pkgsrc.tar.bz2"
161 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
162 _ 'Creating tarball "%s"' "$tarball"
163 if [ -n "$LZMA_SRC" ]; then
164 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
165 LZMA_SRC=''
166 else
167 tar -cjf $tarball $pkgsrc || exit 1
168 mv $tarball $SRC; rm -rf $pkgsrc
169 fi
170 TARBALL="$tarball"
171 }
174 # Get package source. For SCM we are in cache so clone here and create a
175 # tarball here.
177 get_source() {
178 local url
179 url=${WGET_URL#*|}
180 set_paths
181 pwd=$(pwd)
182 case "$WGET_URL" in
183 http://*|ftp://*|https://*)
184 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
185 wget -T 60 -c -O $SRC/$TARBALL $WGET_URL ||
186 wget -T 60 -c -O $SRC/$TARBALL $url ||
187 die 'ERROR: %s' "wget $WGET_URL"
188 ;;
190 hg*|mercurial*)
191 _ 'Getting source from %s...' 'Hg'
192 _ 'URL: %s' "$url"
193 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
194 if [ -n "$BRANCH" ]; then
195 _ 'Hg branch: %s' "$BRANCH"
196 hg clone $url --rev $BRANCH $pkgsrc ||
197 die 'ERROR: %s' "hg clone $url --rev $BRANCH"
198 else
199 hg clone $url $pkgsrc || die 'ERROR: %s' "hg clone $url"
200 fi
201 rm -rf $pkgsrc/.hg
202 create_tarball
203 ;;
205 git*)
206 _ 'Getting source from %s...' 'Git'
207 _ 'URL: %s' "$url"
208 cd $SRC
209 git clone $url $pkgsrc || die 'ERROR: %s' "git clone $url"
210 if [ -n "$BRANCH" ]; then
211 _ 'Git branch: %s' "$BRANCH"
212 cd $pkgsrc; git checkout $BRANCH; cd ..
213 fi
214 cd $SRC
215 create_tarball
216 ;;
218 cvs*)
219 mod=$PACKAGE
220 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
221 _ 'Getting source from %s...' 'CVS'
222 _ 'URL: %s' "$url"
223 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
224 _ 'Cloning to "%s"' "$pwd/$mod"
225 cvs -d:$url co $mod && mv $mod $pkgsrc
226 create_tarball
227 ;;
229 svn*|subversion*)
230 _ 'Getting source from %s...' 'SVN'
231 _ 'URL: %s' "$url"
232 if [ -n "$BRANCH" ]; then
233 echo t | svn co $url -r $BRANCH $pkgsrc
234 else
235 echo t | svn co $url $pkgsrc
236 fi
237 create_tarball
238 ;;
240 bzr*)
241 _ 'Getting source from %s...' 'bazaar'
242 cd $SRC
243 pkgsrc=${url#*:}
244 if [ -n "$BRANCH" ]; then
245 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
246 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
247 else
248 echo "bzr -Ossl.cert_reqs=none branch $url"
249 bzr -Ossl.cert_reqs=none branch $url
250 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
251 _ "Don't forget to add to receipt:"
252 echo -e "BRANCH=\"$BRANCH\"\n"
253 fi
254 mv $pkgsrc $pkgsrc-$BRANCH
255 pkgsrc="$pkgsrc-$BRANCH"
256 create_tarball
257 ;;
259 *)
260 broken; die 'ERROR: Unable to handle "%s"' "$WGET_URL"
261 ;;
262 esac
263 }
266 # Extract source package.
268 extract_source() {
269 if [ ! -s "$SRC/$TARBALL" ]; then
270 local url
271 url="$MIRROR_URL/sources/packages"
272 url="$url/${TARBALL:0:1}/$TARBALL"
273 _ 'Getting source from %s...' 'mirror'
274 _ 'URL: %s' "$url"
275 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
276 fi
277 _ 'Extracting source archive "%s"' "$TARBALL"
278 case "$TARBALL" in
279 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
280 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
281 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
282 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
283 *.tar) tar -xf $SRC/$TARBALL ;;
284 *.zip|*.xpi) unzip -o $SRC/$TARBALL 2>/dev/null >&2;;
285 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
286 tar -xf $SRC/$TARBALL 2>/dev/null;;
287 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
288 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
289 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
290 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
291 *) cp $SRC/$TARBALL $(pwd) ;;
292 esac
293 }
296 # Display time.
298 disp_time_old() {
299 local sec div min
300 sec="$1"
301 div=$(( ($1 + 30) / 60))
302 case $div in
303 0) min='';;
304 # L10n: 'm' is for minutes (approximate cooking time)
305 *) min=$(_n ' ~ %dm' "$div");;
306 esac
308 # L10n: 's' is for seconds (cooking time)
309 _ '%ds%s' "$sec" "$min"
310 }
313 # Display time.
315 disp_time() {
316 local sec="$1" day hour min out=''
318 day=$(( sec / 86400 )); sec=$(( sec % 86400 ))
319 hour=$(( sec / 3600 )); sec=$(( sec % 3600 ))
320 min=$(( sec / 60 )); sec=$(( sec % 60 ))
322 [ $day -gt 0 ] && out="${day}d "
323 [ -n "$out" -o $hour -gt 0 ] && out="$out$(printf '%02dh ' $hour)"
324 [ -n "$out" -o $min -gt 0 ] && out="$out$(printf '%02dm ' $min)"
325 [ -n "$out" ] && out=" ~ $out$(printf '%02ds' $sec)"
327 echo "${1}s$out"
328 }
331 # Display cooked package summary.
333 summary() {
334 # local arch=''
335 # case "$ARCH" in
336 # arm*|x86_64) arch="-$ARCH" ;;
337 # esac
339 set_paths
340 cd $WOK/$pkg
341 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
342 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
343 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
345 title 'Summary for: %s' "$PACKAGE $VERSION$EXTRAVERSION"
347 # L10n: keep the same width of translations to get a consistent view
348 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
349 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
350 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
351 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
352 _ 'Cook time : %s' "$(disp_time "$time")"
353 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
354 _ 'Target arch : %s' "$(cut -d$'\t' -f2 $pkgdir/.arch | sort -u | tr '\n' ' ' | sed 's| $||; s| |, |g')"
356 separator -
357 _ ' # : Packed : Compressed : Files : Package name'
358 separator -
359 pkgi=1
360 for i in $(all_names); do
361 version=$(awk -F$'\t' -vpkg="$i" '{
362 if ($1 == pkg) {print $2; exit}
363 }' "$PKGS/packages-$ARCH.info")
364 [ -n "$version" ] || continue
365 fs=$(du -sh $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION | awk '{print $1}')
366 arch=$(awk -F$'\t' -vi="$i" '{if ($1 == i) print $2}' $pkgdir/.arch)
367 pkgname="$i-$version-$arch.tazpkg"
368 size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
369 files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/files.list)
370 printf "%2d : %7s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
371 pkgi=$((pkgi + 1))
372 done
373 separator
374 }
377 # Display debugging error info.
379 debug_info() {
380 title 'Debug information %s.' "$1"
381 # L10n: specify your format of date and time (to help: man date)
382 # L10n: not bad one is '+%x %R'
383 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
384 if [ -n "$time" ]; then
385 times="$(($(date +%s) - $time))"
386 _ 'Wasted time : %s' "$(disp_time "$times")"
387 fi
388 for error in \
389 ERROR 'No package' "cp: can't" "can't open" "can't cd" \
390 'error:' 'fatal error:' 'undefined reference to' \
391 'Unable to connect to' 'link: cannot find the library' \
392 'CMake Error' ': No such file or directory' \
393 'Could not read symbols: File in wrong format'
394 do
395 # format "line number:line content"
396 fgrep -n "$error" $LOGS/$pkg.log
397 done > $LOGS/$pkg.log.debug_info 2>&1
398 # sort by line number, remove duplicates
399 sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
400 rm -f $LOGS/$pkg.log.debug_info
401 footer
402 }
405 # A bit smarter function than the classic `cp` command
407 scopy() {
408 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
409 cp -a "$1" "$2" # copy generic files
410 else
411 cp -al "$1" "$2" # copy hardlinks
412 fi
413 }
416 # Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
417 # We use standard paths, so some packages need to copy these files with the
418 # receipt and genpkg_rules.
419 # This function executes inside the packaging process, before compressor call.
421 copy_generic_files() {
422 # Proceed only for "main" package (for v2), and for any packages (v1)
423 [ "$pkg" == "$PACKAGE" ] || return 0
425 # $LOCALE is set in cook.conf
426 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
427 if [ -d "$install/usr/share/locale" ]; then
428 mkdir -p "$fs/usr/share/locale"
429 for i in $LOCALE; do
430 if [ -d "$install/usr/share/locale/$i" ]; then
431 cp -r $install/usr/share/locale/$i $fs/usr/share/locale
432 fi
433 done
434 fi
435 fi
437 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
438 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
439 if [ -d "$install/usr/share/pixmaps" ]; then
440 mkdir -p "$fs/usr/share/pixmaps"
441 for i in png xpm; do
442 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
443 cp -r $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
444 done
445 fi
446 fi
448 # Desktop entry (.desktop).
449 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
450 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
451 if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
452 mkdir -p "$fs/usr/share"
453 cp -r $install/usr/share/applications $fs/usr/share
454 fi
455 fi
456 }
459 # Copy pixmaps, desktop files and licenses from $stuff to $install.
460 # This function executes after the main compile_rules() is done.
462 copy_generic_stuff() {
463 # Custom or homemade PNG pixmap can be in stuff.
464 if [ -f "$stuff/$PACKAGE.png" ]; then
465 mkdir -p $install/usr/share/pixmaps
466 cp $stuff/$PACKAGE.png $install/usr/share/pixmaps
467 fi
469 # Homemade desktop file(s) can be in stuff.
470 if [ -d "$stuff/applications" ]; then
471 mkdir -p $install/usr/share
472 cp -r $stuff/applications $install/usr/share
473 fi
474 if [ -f "$stuff/$PACKAGE.desktop" ]; then
475 mkdir -p $install/usr/share/applications
476 cp $stuff/$PACKAGE.desktop $install/usr/share/applications
477 fi
479 # Add custom licenses
480 if [ -d "$stuff/licenses" ]; then
481 mkdir -p $install/usr/share/licenses
482 cp -r $stuff/licenses $install/usr/share/licenses/$PACKAGE
483 fi
484 }
487 # Update installed.cook.diff
489 update_installed_cook_diff() {
490 # If a cook failed deps are removed.
491 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
492 cd $CACHE
493 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
494 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
495 deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
496 }
499 # Remove installed deps.
501 remove_deps() {
502 # Now remove installed build deps.
503 diff='/tmp/installed.cook.diff'
504 [ -s "$diff" ] || return
506 deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
507 nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
508 newline
509 _n 'Build dependencies to remove:'; echo " $nb"
510 [ -n "$root" ] && echo "root=\"$root\""
512 _n 'Removing:'
513 for dep in $deps; do
514 echo -n " $dep"
515 # Do not waste time uninstalling the packages if we are inside
516 # aufs chroot - unmounting chroot will "uninstall" all packages.
517 [ -s /aufs-umount.sh ] ||
518 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
519 done
521 newline; newline
522 # Keep the last diff for debug and info.
523 mv -f $diff $CACHE/installed.diff
524 }
527 # Automatically patch the sources.
529 patchit() {
530 [ -f "$stuff/patches/series" ] || return
531 # Empty lines and comments (started with "#") are ignored
532 # Up to three fields (no spaces inside allowed) separated by "|":
533 # 1. patch options like "-p0" (optional);
534 # 2. patch file name or URL (mandatory);
535 # 3. patch checksum in form "sha1=..." or other *sum (optional).
537 local done="$pkgdir/.patch.done" var1 var2 var3
538 local patchname patchopts patchfile patchsum patchsum_type patchsum_sum
539 IFS=$'\n'
540 while read i; do
541 patchname=$(echo ${i%%#*} | cut -d' ' -f1) # allow comments (anything after the # or space)
542 [ -n "$patchname" ] || continue # skip empty lines
544 var1=$(echo "$patchname||" | cut -d'|' -f1) # options or name
545 var2=$(echo "$patchname||" | cut -d'|' -f2) # name or checksum or empty
546 var3=$(echo "$patchname||" | cut -d'|' -f3) # checksum or empty
548 if [ -n "$var3" ]; then
549 patchopts="$var1"; patchname="$var2"; patchsum="$var3"
550 elif [ -n "$var2" ]; then
551 case $var2 in
552 *=*) patchopts='-Np1'; patchname="$var1"; patchsum="$var2";;
553 *) patchopts="$var1"; patchname="$var2"; patchsum='';;
554 esac
555 else
556 patchopts='-Np1'; patchname="$var1"; patchsum=''
557 fi
559 case $patchname in
560 ftp://*|http://*|https://*)
561 patchfile="$SRC/$(basename $patchname)"
562 [ -e "$patchfile" ] || wget -q -T 60 -O $patchfile $patchname ||
563 die 'ERROR: %s' "can't get $patchname"
564 ;;
565 *)
566 patchfile="$stuff/patches/$patchname"
567 ;;
568 esac
570 if [ -n "$patchsum" ]; then
571 patchsum_type=${patchsum%=*}
572 patchsum_sum=${patchsum#*=}
573 echo "$patchsum_sum $patchfile" | ${patchsum_type}sum -cs ||
574 die 'ERROR: %s' "wrong ${patchsum_type}sum for $patchfile"
575 else
576 case $patchfile in
577 $SRC/*) echo "warning: no checksum for external patch!";;
578 esac
579 fi
581 touch $done
582 grep -q "^${patchname}$" $done && continue # already applied (useful with `cook --continue`)
584 newline
585 _ 'Applying patch %s' "$patchname"
586 patch $patchopts -i $patchfile | sed 's|^| |'
588 echo $patchname >> $done
589 done < $stuff/patches/series
590 newline
591 unset IFS
592 }
595 # Check source tarball integrity.
597 check_integrity() {
598 for i in sha1 sha3 sha256 sha512 md5; do
599 I=$(echo $i | tr 'a-z' 'A-Z')
600 eval sum=\$TARBALL_$I
601 if [ -n "$sum" ]; then
602 newline
603 _ 'Checking %ssum of source tarball...' "$i"
604 echo "$sum $SRC/$TARBALL" | ${i}sum -c || exit 1
605 fi
606 done
607 newline
608 }
611 # Misc fix functions
613 fix() {
614 case $1 in
615 # https://bugzilla.gnome.org/show_bug.cgi?id=655517
616 # https://wiki.gentoo.org/wiki/Project:Quality_Assurance/As-needed
617 ld)
618 export LDFLAGS="$LDFLAGS -Wl,-Os,--as-needed"
619 ;;
620 libtool)
621 if [ -e 'libtool' ]; then
622 sed -i 's| -shared | -Wl,-Os,--as-needed\0|g' libtool
623 echo "fix.libtool" >> $pkgdir/.patch.done
624 else
625 echo "fix libtool: warning: libtool absent, nothing to fix."
626 fi
627 ;;
628 math)
629 # fix C++ math issue introduced in Glibc 2.26:
630 # error: '__builtin_isnan' is not a member of 'std'
631 # if (std::isnan(N)) {
632 # ^
633 find $src -type f -exec sed -i '
634 s|std::signbit|__builtin_signbit|g;
635 s|std::isnan|__builtin_isnan|g;
636 s|std::isinf|__builtin_isinf_sign|g;
637 s|std::isfinite|__builtin_isfinite|g;
638 s|std::isnormal|__builtin_isnormal|g
639 ' '{}' \;
640 ;;
641 symlinks)
642 # make absolute symlinks relative
643 echo "fix symlinks"
644 local ifs="$IFS" link target
645 IFS=$'\n'
646 # step 1: fast job, prefix all the absolute symlinks with "$install"
647 for link in $(find $install -type l); do
648 target="$(readlink $link)"
649 case "$target" in
650 /*) ln -sfv "$install$target" "$link";;
651 esac
652 done
653 IFS="$ifs"
654 # step 2: fine tuning, make symlinks relative
655 tazpkg -gi --quiet --local --cookmode symlinks
656 symlinks -cr $install
657 ;;
658 gem)
659 # some useful operations while Ruby gems cooking
660 _gems="$(ruby -e'puts Gem.default_dir')"
662 # remove unwanted empty folders
663 rmdir --ignore-fail-on-non-empty \
664 $install/$_gems/build_info/ \
665 $install/$_gems/cache/ \
666 $install/$_gems/doc/ \
667 $install/$_gems/extensions/
669 # move files to docdir
670 docdir=$install/usr/share/doc/$PACKAGE-$VERSION
671 for i in $(ls -ap $install/$_gems/gems/${PACKAGE#*-}-$VERSION/ | sed '
672 /\/$/d; /^\./d; /gemspec$/d; /Rakefile*/d; /Gemfile*/d; /Makefile/d;
673 /\.c$/d; /\.h$/d; /\.o$/d; /\.rb$/d; /\.so$/d; /\.yml$/d;
674 /Manifest/d; /\.inc$/d; /depend/d;
675 '); do
676 mkdir -p $docdir # docdir will not be created when nothing to move
677 mv $install/$_gems/gems/${PACKAGE#*-}-$VERSION/$i $docdir
678 done
679 if [ -d $install/$_gems/gems/${PACKAGE#*-}-$VERSION/doc/ ]; then
680 mkdir -p $docdir
681 mv $install/$_gems/gems/${PACKAGE#*-}-$VERSION/doc/ $docdir
682 fi
684 if [ -d $docdir ]; then
685 # move man pages
686 unset man_to_copy
687 for i in $(seq 1 8); do
688 for j in $(find $docdir -type f -name "*.$i" | sed '/LGPL-2\.1/d'); do
689 man_to_copy="$man_to_copy $j"
690 done
691 done
692 if [ -n "$man_to_copy" ]; then
693 cook_pick_manpages $man_to_copy
694 rm $man_to_copy
695 fi
697 # convert rdoc to markdown (thanks https://gist.github.com/teeparham/8a99e308884e1c32735a)
698 for i in $(find $docdir -type f -name '*.rdoc'); do
699 fix utf-8
700 LC_ALL=en_US.UTF-8 ruby -r rdoc -e 'puts RDoc::Markup::ToMarkdown.new.convert File.read(ARGV[0] || "'$i'")' >$i.md && rm $i || rm $i.md
701 done
702 fi
704 # move man pages (from the different place)
705 rubyman=$install/$_gems/gems/${PACKAGE#*-}-$VERSION/man
706 if [ -d $rubyman ]; then
707 unset man_to_copy
708 for i in $(seq 1 8); do
709 for j in $(find $rubyman -type f -name "*.$i" | sed '/LGPL-2\.1/d'); do
710 man_to_copy="$man_to_copy $j"
711 done
712 done
713 if [ -n "$man_to_copy" ]; then
714 cook_pick_manpages $man_to_copy
715 fi
716 rm -r $rubyman
717 fi
718 ;;
719 utf-8)
720 # Install UTF-8 locale
721 tazpkg -gi --quiet --local --cookmode locale-en-base
722 mkdir -p /usr/lib/locale
723 localedef -i 'en_US' -c -f 'UTF-8' /usr/lib/locale/en_US.UTF-8
724 ;;
725 esac
726 }
729 # Typical function used in compile_rules() to make perl modules packages
731 cook_perl() {
732 if [ -e "Makefile.PL" ]; then
733 # Up to 3 optional parameters supported
734 PERL_MM_USE_DEFAULT=1 perl Makefile.PL INSTALLDIRS=vendor $1 &&
735 make $2 &&
736 make $3 PERL_MM_USE_DEFAULT=1 DESTDIR=$install install &&
737 chmod -R u+w $install
738 elif [ -e "Build.PL" ]; then
739 echo "Not implemented yet"
740 return 1
741 else
742 echo "Unable to cook Perl module"
743 return 1
744 fi
745 }
748 # Store timestamps, log jobs length
750 timestamp() {
751 local ts_file="$WOK/$pkg/.ts"
752 local curr_ts=$(date '+%s')
753 case $1 in
754 init)
755 rm $ts_file 2>/dev/null
756 echo $curr_ts > $prev_ts
757 ;;
758 job*)
759 # calculate time from the last timestamp
760 echo "$1='$(( $curr_ts - $(cat $prev_ts) ))'" >> $ts_file
761 echo $curr_ts > $prev_ts
762 ;;
763 sets)
764 echo "sets='$2'" >> $ts_file
765 ;;
766 esac
767 }
770 # Store time statsistics to the cache
772 store_timestats() {
773 # see doc/timestats.txt for file format
774 temp=$(mktemp)
775 {
776 for i in $(seq 1 30); do echo "job$i=0"; done
777 cat $WOK/$pkg/.ts
778 echo -n 'total=$(( 0'
779 for i in $(seq 1 30); do echo -n " + job$i"; done
780 echo ' ))'
781 } > $temp
782 . $temp
783 {
784 echo -n "$pkg $sets "
785 for i in $(seq 1 30); do echo -n "$((job$i)) "; done
786 echo "$total"
787 } >> /home/slitaz/cache/timestats
788 rm $temp $WOK/$pkg/.ts # clean
789 }
792 # Internal function to cook specified SET
794 cook_set() {
795 # Switch to the specified source set
796 set_paths
797 local suffix=''
798 [ -n "$SET" ] && suffix="-$SET"
799 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
800 export install="$WOK/$pkg/install$suffix"
801 export DESTDIR="$install"
803 if [ -n "$SETS" ]; then
804 if [ -n "$SET" ]; then
805 title "Switching to the set '$SET'"
806 else
807 title "Switching to the default set"
808 fi
809 echo "src : $src"
810 echo "install: $install"
811 fi
812 [ -d "$src" ] && cd $src # packages without sources exists
813 echo
815 [ -d "$install" ] && rm -r $install
816 #mkdir -p $install
818 compile_rules $@ || { broken; exit 1; }
820 # Stay compatible with _pkg
821 [ -d "$src/_pkg" ] && mv $src/_pkg $install
823 copy_generic_stuff
825 timestamp job$job_counter # compiling (set '$SET')
827 # Actions to do after compiling the package
828 # Skip all for split packages (already done in main package)
829 if [ -z "$WANTED" ]; then
830 footer
831 export COOKOPTS ARCH install
832 @@PREFIX@@/libexec/cookutils/compressor install
833 timestamp job$(($job_counter + 1)) # compressing (set '$SET')
834 fi
836 # Activate "instant-pack" mode
837 if [ "${COOKOPTS/instant-pack/}" != "$COOKOPTS" ]; then
838 echo " $SPLIT " | fgrep -q " $PACKAGE " || SPLIT="$PACKAGE $SPLIT"
839 export PACKAGE
840 # determine the list of the packages belongs to the current SET...
841 echo -n $SPLIT \
842 | awk -vset="$SET" '
843 BEGIN { RS = " "; FS = ":"; }
844 { if ($2 == set) print $1; }' \
845 | xargs -n1 @@PREFIX@@/libexec/cookutils/pack # ... and then pack them
846 fi
848 job_counter=$(($job_counter + 2))
849 }
852 # The main cook function.
854 cookit() {
855 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
856 _ 'ERROR: Broken setup. Abort.'
857 return
858 fi
860 title 'Cook: %s' "$PACKAGE $VERSION"
861 set_paths
862 timestamp init # the very start
864 # Handle cross-tools.
865 [ "$BUILD_SYSTEM" != "$HOST_SYSTEM" ] &&
866 case "$ARCH" in
867 arm*|x86_64)
868 # CROSS_COMPILE is used by at least Busybox and the kernel to set
869 # the cross-tools prefix. Sysroot is the root of our target arch
870 sysroot="$CROSS_TREE/sysroot"
871 tools="$CROSS_TREE/tools"
872 # Set root path when cross compiling. ARM tested but not x86_64
873 # When cross compiling we must install build deps in $sysroot.
874 arch="-$ARCH"
875 root="$sysroot"
876 _ '%s sysroot: %s' "$ARCH" "$sysroot"
877 _ 'Adding "%s" to PATH' "$tools/bin"
878 export PATH="$PATH:$tools/bin"
879 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
880 export CROSS_COMPILE="$HOST_SYSTEM-"
881 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
882 if [ "$ARCH" == 'x86_64' ]; then
883 export CC="$HOST_SYSTEM-gcc -m64"
884 export CXX="$HOST_SYSTEM-g++ -m64"
885 else
886 export CC="$HOST_SYSTEM-gcc"
887 export CXX="$HOST_SYSTEM-g++"
888 fi
889 export AR="$HOST_SYSTEM-ar"
890 export AS="$HOST_SYSTEM-as"
891 export RANLIB="$HOST_SYSTEM-ranlib"
892 export LD="$HOST_SYSTEM-ld"
893 export STRIP="$HOST_SYSTEM-strip"
894 export LIBTOOL="$HOST_SYSTEM-libtool"
895 ;;
896 esac
898 @@PREFIX@@/libexec/cookutils/precheck $receipt || exit 1 # former receipt_quality()
900 cd $pkgdir
901 if [ -z "$continue" ]; then
902 rm -rf source 2>/dev/null
903 rm .patch.done 2>/dev/null
904 fi
905 rm -rf install taz 2>/dev/null
907 # Disable -pipe if less than 512 MB free RAM.
908 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
909 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
910 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
911 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
912 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
913 fi
914 unset free
916 # Export flags and path to be used by make and receipt.
917 DESTDIR="$pkgdir/install"
918 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
919 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C \
920 LDFLAGS
922 timestamp job1 # pre-checks
924 # BUILD_DEPENDS may vary depending on the ARCH
925 case "$ARCH" in
926 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
927 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
928 esac
930 # Check for build deps and handle implicit depends of *-dev packages
931 # (ex: libusb-dev :: libusb).
932 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
933 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
935 # Get the list of installed packages
936 cd $root$INSTALLED; ls > $CACHE/installed.list
938 for action in check install; do
939 for dep in $BUILD_DEPENDS; do
940 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
941 for i in $dep $implicit; do
942 # Skip if package already installed
943 [ -f "$root$INSTALLED/$i/receipt" ] && continue
945 case $action in
946 check)
947 # Search for local package or local provided-package
948 name=$(awk -F$'\t' -vpkg="$i" '{
949 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
950 }' "$PKGS/packages-$ARCH.info")
951 if [ -z "$name" ]; then
952 # Search for package in mirror
953 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
954 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
955 fi
956 ;;
957 install)
958 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
959 ;;
960 esac
961 done
962 done
963 done
965 update_installed_cook_diff
967 timestamp job2 # installing bdeps
969 # Get source tarball and make sure we have source dir named:
970 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
971 # tarball if it exists.
972 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
973 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
974 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
975 LZMA_SRC=''
976 else
977 get_source || { broken; exit 1; }
978 fi
979 fi
980 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
981 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
982 if ! extract_source ; then
983 get_source
984 extract_source || { broken; exit 1; }
985 fi
986 if [ -n "$LZMA_SRC" ]; then
987 cd $pkgdir/source
988 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
989 mv tmp tmp-1; mkdir tmp
990 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
991 fi
992 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
993 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
994 fi
995 fi
997 cd $pkgdir/source/tmp
998 # Some archives are not well done and don't extract to one dir (ex lzma).
999 files=$(ls | wc -l)
1000 [ "$files" -eq 1 -a -d "$(ls)" ] &&
1001 mv * ../$PACKAGE-$VERSION
1002 [ "$files" -eq 1 -a -f "$(ls)" ] &&
1003 mkdir -p ../$PACKAGE-$VERSION &&
1004 mv * ../$PACKAGE-$VERSION/$TARBALL
1005 [ "$files" -gt 1 ] &&
1006 mkdir -p ../$PACKAGE-$VERSION &&
1007 mv * ../$PACKAGE-$VERSION
1008 cd ..; rm -rf tmp
1009 fi
1011 # Check md5sum (or similar) for sources tarball
1012 check_integrity
1014 # Libtool shared libs path hack.
1015 case "$ARCH" in
1016 arm*) cross libhack ;;
1017 esac
1019 timestamp job3 # get/unpack src tarball
1021 # Compiling all the sets
1022 if grep -q ^compile_rules $receipt; then
1023 _ 'Executing: %s' 'compile_rules'
1024 echo "CFLAGS : $CFLAGS"
1025 echo "CXXLAGS : $CXXFLAGS"
1026 echo "CPPFLAGS : $CPPFLAGS"
1027 echo "LDFLAGS : $LDFLAGS"
1028 [ -d "$src" ] && cd $src
1029 patchit
1031 timestamp job4 # patching
1033 # Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
1034 # Keep natural order of the sets, don't sort them alphabetically
1035 SETS=$(echo -n $SPLIT \
1036 | awk '
1037 BEGIN { RS = " "; FS = ":"; }
1039 if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; }
1040 }' \
1041 | sed 's| $||')
1042 # Prepare specified source sets using patched sources
1043 [ -n "$SETS" -a -d "$src" ] &&
1044 for set in $SETS; do
1045 echo "Preparing set $set" # debug
1046 cp -a $src $src-$set
1047 done
1049 timestamp job5 # preparing sets
1050 timestamp sets "$SETS"
1052 job_counter='6'
1054 SET='' cook_set # first run for empty SET
1056 # Allow to change SETS after the first run, follow the changes
1057 SETS=$(. $receipt; echo -n $SPLIT \
1058 | awk '
1059 BEGIN { RS = " "; FS = ":"; }
1061 if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; }
1062 }' \
1063 | sed 's| $||')
1064 for SET in $SETS; do
1065 cook_set
1066 done
1067 else
1068 mkdir -p $install # allow receipts without `compile_rules()`
1069 fi
1070 footer
1072 timestamp job # reset counter
1074 # Execute testsuite.
1075 if grep -q ^testsuite $receipt; then
1076 title 'Running testsuite'
1077 testsuite $@ || { broken; exit 1; }
1078 footer
1079 fi
1081 timestamp job26 # test suite
1083 update_installed_cook_diff force
1087 # Cook quality assurance.
1089 cookit_quality() {
1090 while true; do
1091 [ ! -d "$WOK/$pkg/install" -a -z "$WANTED" ] || break
1092 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
1093 [ "$trials" == 'yes' ] || break
1094 title "Interactive mode"
1095 # TODO: allow commands:
1096 # q - quit; v - edit receipt here using vi;
1097 # s - search for package containing package;
1098 # <package name> - install package; [Enter] - retry
1099 _ 'You may install the packages here and/or edit the receipt there.'
1100 newline
1101 while true; do
1102 _n 'Install the package? [name/N] '; read answer
1103 [ -n "$answer" ] || break
1104 tazpkg -gi $answer --root=$root --local --quiet --cookmode
1105 done
1106 newline
1107 _n 'Try again? [Y/n] '; read answer
1108 [ "$answer" == 'n' ] && break
1109 # here you may append log if you want (">>" instead of last ">")
1110 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1111 done
1113 [ "${COOKOPTS/skip-log-errors/}" != "$COOKOPTS" ] && return 0
1115 # ERROR can be echoed any time in cookit()
1116 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
1117 grep -Eq "(^ERROR|undefined reference to)" ; then
1118 debug_info "cookit_quality" | tee -a $LOGS/$pkg.log
1119 put_status $pkg Failed
1120 # rm -f $command
1121 # broken; exit 1
1122 fi
1126 # Return all the names of packages bundled in this receipt
1128 all_names() {
1129 # Get package names from $SPLIT variable
1130 local split=$(echo -n $SPLIT \
1131 | awk '
1132 BEGIN { RS = " "; FS = ":"; }
1133 { print $1; }' \
1134 | tr '\n' ' ')
1135 local split_space=" $split "
1136 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
1137 # For receipts v1: $SPLIT may present in the $WANTED package,
1138 # but split packages have their own receipts
1139 echo $PACKAGE
1140 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
1141 # $PACKAGE included somewhere in $SPLIT (probably in the end).
1142 # We should build packages in the order defined in the $SPLIT.
1143 echo $split
1144 else
1145 # We'll build the $PACKAGE, then all defined in the $SPLIT.
1146 echo $PACKAGE $split
1147 fi
1151 # v2: pack all packages using compiled files
1153 packall() {
1154 set_paths
1155 [ -e $pkgdir/.arch ] && rm $pkgdir/.arch
1157 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1158 for i in $(all_names); do
1159 unset TAGS DEPENDS CAT CONFIG_FILES PROVIDE SUGGESTED DATABASE_FILES TAZPANEL_DAEMON
1160 export PACKAGE; @@PREFIX@@/libexec/cookutils/pack $i
1161 done
1162 else
1163 export PACKAGE; @@PREFIX@@/libexec/cookutils/pack $PACKAGE
1164 fi
1168 # Reverse "cat" command: prints input lines in the reverse order
1170 tac() {
1171 sed '1!G;h;$!d' $1
1175 # Install package: update the chroot with freshly rebuilt package: keep env up-to-date.
1177 install_package() {
1178 set_paths
1179 case "$ARCH" in
1180 arm*) root="$CROSS_TREE/sysroot";;
1181 esac
1183 # Process all the package names built by this receipt (defined in $SPLIT)
1184 for i in $(PACKAGE="$pkg" all_names); do
1185 if [ -d "$root$INSTALLED/$i" ]; then
1186 pkg_file=$(awk -F$'\t' -vpkg="$i" -varch="$ARCH" '{
1187 if ($1 == pkg) {
1188 pkgarch = ($11 == "0") ? "any" : arch;
1189 printf("%s-%s-%s.tazpkg", $1, $2, pkgarch);
1190 exit
1192 }' $PKGS/packages-$ARCH.info)
1193 if [ -e "$PKGS/$pkg_file" ]; then
1194 _ 'Updating %s chroot environment...' "$ARCH"
1195 _ 'Updating chroot: %s' "${pkg_file%.tazpkg}" | log
1196 tazpkg -i "$PKGS/$pkg_file" --forced --root=$root
1197 fi
1198 fi
1199 done
1203 # remove chroot jail
1205 umount_aufs() {
1206 tac ${1}rw/aufs-umount.sh | sh
1207 rm -rf ${1}rw
1208 umount ${1}root
1209 rmdir ${1}r*
1213 # Launch the cook command into a chroot jail protected by aufs.
1214 # The current filesystems are used read-only and updates are
1215 # stored in a separate branch.
1217 try_aufs_chroot() {
1219 base="/dev/shm/aufsmnt$$"
1221 # Can we setup the chroot? Is it already done?
1222 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1223 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1224 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1225 grep -q ^aufs /proc/modules || modprobe aufs 2>/dev/null || return
1226 mkdir ${base}root ${base}rw || return
1228 _ 'Setup aufs chroot...'
1230 # Sanity check
1231 for i in / /proc /sys /dev /dev/shm /home; do
1232 case " $AUFS_MOUNTS " in
1233 *\ $i\ *) ;;
1234 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1235 esac
1236 done
1237 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1238 mkdir -p ${base}root$mnt # for `mount -o bind`
1239 mount -o bind $mnt ${base}root$mnt # use `-o bind` instead of `--bind`
1240 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1241 _ 'Aufs mount failure'
1242 umount ${base}root
1243 rm -rf ${base}r*
1244 return
1245 fi
1246 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1247 done
1248 trap "umount_aufs ${base}" INT
1250 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1251 status=$?
1253 _ 'Leaving aufs chroot...'
1254 umount_aufs $base
1255 # Install package outside the aufs jail
1256 install_package
1257 exit $status
1261 # Encode predefined XML entities
1263 xml_ent() {
1264 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1268 # Create a XML feed for freshly built packages.
1270 gen_rss() {
1271 if [ -e "$WOK/$PACKAGE/.icon.png" ]; then
1272 icon="$COOKER_URL$PACKAGE/browse/.icon.png"
1273 else
1274 icon="http://cook.slitaz.org/tazpkg.png"
1275 fi
1277 cat > $FEEDS/$pkg.xml <<EOT
1278 <item>
1279 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1280 <link>$COOKER_URL${PACKAGE//+/%2B}</link>
1281 <guid isPermaLink="false">$PACKAGE-$VERSION$EXTRAVERSION</guid>
1282 <pubDate>$(date '+%a, %d %b %Y %X GMT')</pubDate>
1283 <description><![CDATA[
1284 <table>
1285 <tr>
1286 <td vertical-align="top"><img src="$icon" alt=""/></td>
1287 <td>$(echo -n "$SHORT_DESC" | xml_ent)</td>
1288 </tr>
1289 </table>
1290 ]]></description>
1291 </item>
1292 EOT
1296 # Truncate stdout log file to $1 Mb.
1298 loglimit() {
1299 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1300 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1301 else
1302 tee /dev/stderr
1303 fi
1308 # Receipt functions to ease packaging
1311 get_dev_files() {
1312 action 'Getting standard devel files...'
1313 mkdir -p $fs/usr/lib
1314 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1315 cp -a $install/usr/lib/*a $fs/usr/lib
1316 cp -a $install/usr/include $fs/usr
1317 status
1321 # Function to use in compile_rules() to copy man page from $src to $install
1323 cook_pick_manpages() {
1324 local name section
1325 action 'Copying man pages...'
1327 for i in $@; do
1328 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1329 section=${name##*/}; section=${section##*.}
1330 mkdir -p $install/usr/share/man/man$section
1331 scopy $i $install/usr/share/man/man$section
1332 done
1333 status
1337 # Function to use in compile_rules() to copy documentation from $src to $install
1339 cook_pick_docs() {
1340 local docdir="$install/usr/share/doc/$PACKAGE-$VERSION"
1341 action 'Copying documentation...'
1342 mkdir -p $docdir
1343 cp -r $@ $docdir
1344 chmod -R a+r $docdir
1345 status
1349 # Update split.db once for receipt
1351 update_split_db() {
1352 local db="$cache/split.db"
1353 touch $db
1354 sed -i "/^$pkg\t/d" $db
1355 echo -e "$pkg\t$(all_names)" >> $db
1359 # Recreate whole split.db from scratch
1361 recreate_split_db() {
1362 # Clean
1363 local db="$cache/split.db"
1365 cd $WOK
1366 for pkg in *; do
1367 [ -f "$WOK/$pkg/receipt" ] || continue
1368 unset PACKAGE SPLIT
1369 . $WOK/$pkg/receipt
1370 echo -e "$PACKAGE\t$(all_names)"
1371 done > $db
1375 # Recreate whole maint.db from scratch
1377 recreate_maint_db() {
1378 # Clean
1379 local db="$cache/maint.db"
1381 cd $WOK
1382 for pkg in *; do
1383 [ -f "$WOK/$pkg/receipt" ] || continue
1384 unset PACKAGE MAINTAINER
1385 . $WOK/$pkg/receipt
1386 MAINTAINER=$(echo $MAINTAINER | sed 's|.*<||; s|>.*||')
1387 echo -e "$MAINTAINER\t$PACKAGE"
1388 done | sort > $db
1392 # Put the status to the activity log
1394 put_status() {
1395 # $1: package, $2: status, one of 'Done', 'Failed'
1396 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1397 if [ "$2" == 'Done' ]; then
1398 # overstrike all previous 'Failed' to indicate package is OK now
1399 sed -i "/>$1<\/a>/ s|\[ Failed \]|[ -Failed ]|" $activity
1400 fi
1407 # Commands
1410 # cook <package> --deps
1411 [ -n "$deps" ] && {
1412 @@PREFIX@@/libexec/cookutils/deps $1
1413 exit 0
1416 # cook <package> --clean
1417 # cook <package> -c
1418 [ -n "$clean" -o "$2" == '-c' ] && {
1419 action 'Cleaning "%s"' "$1"
1420 cd $WOK/$1; rm -rf install taz source
1421 status; newline
1422 touch $activity # update $activity -> something changed -> update webstat
1423 exit 0
1426 # cook <package> --getsrc
1427 # cook <package> -gs
1428 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1429 pkg="$1"
1430 title 'Getting source for "%s"' "$pkg"
1431 receipt="$WOK/$pkg/receipt"
1432 check_pkg_in_wok
1433 unset_receipt
1434 . $receipt
1435 get_source
1436 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1437 exit 0
1440 # cook <package> --block
1441 # cook <package> -b
1442 [ -n "$block" -o "$2" == '-b' ] && {
1443 action 'Blocking package "%s"' "$1"
1444 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1445 status; newline
1446 touch $activity
1447 exit 0
1450 # cook <package> --unblock
1451 # cook <package> -ub
1452 [ -n "$unblock" -o "$2" == '-ub' ] && {
1453 action 'Unblocking package "%s"' "$1"
1454 sed -i "/^$1$/d" $blocked
1455 status; newline
1456 touch $activity
1457 exit 0
1463 case "$1" in
1464 usage|help|-u|-h)
1465 usage ;;
1467 list-wok)
1468 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1469 cd $WOK
1470 if [ "$ARCH" != 'i486' ]; then
1471 count=0
1472 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1473 do
1474 unset HOST_ARCH
1475 . ./$pkg
1476 count=$(($count + 1))
1477 colorize 34 "$PACKAGE"
1478 done
1479 else
1480 count=$(ls | wc -l)
1481 ls -1
1482 fi
1483 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1484 ;;
1486 activity)
1487 cat $activity ;;
1489 search)
1490 # Just a simple search function, we don't need more actually.
1491 query="$2"
1492 title 'Search results for "%s"' "$query"
1493 cd $WOK; ls -1 | grep "$query"
1494 footer ;;
1496 setup)
1497 # Setup a build environment
1498 check_root
1499 _ 'Cook: setup environment' | log
1500 title 'Setting up your environment'
1501 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1502 cd $SLITAZ
1503 init_db_files
1504 _ 'Checking for packages to install...'
1505 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1506 # ARCH-setup or 'cross check' should be used before: cook setup
1507 case "$ARCH" in
1508 arm*|x86_64)
1509 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1510 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1511 . /etc/slitaz/cross.conf ;;
1512 esac
1513 for pkg in $SETUP_PKGS; do
1514 if [ -n "$forced" ]; then
1515 tazpkg -gi $pkg --forced
1516 else
1517 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1518 fi
1519 done
1521 # Handle --options
1522 case "$2" in
1523 --wok) hg clone $WOK_URL wok || exit 1 ;;
1524 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1525 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1526 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1527 esac
1529 # SliTaz group and permissions
1530 if ! grep -q ^slitaz /etc/group; then
1531 _ 'Adding group "%s"' 'slitaz'
1532 addgroup slitaz
1533 fi
1534 _ 'Setting permissions for group "%s"...' 'slitaz'
1535 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1536 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1537 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1539 *-setup)
1540 # Setup for cross compiling.
1541 arch="${1%-setup}"
1542 check_root
1543 . /etc/slitaz/cook.conf
1544 for pkg in $CROSS_SETUP; do
1545 if [ -n "$forced" ]; then
1546 tazpkg -gi $pkg --forced
1547 else
1548 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1549 fi
1550 done
1552 _ 'Cook: setup %s cross environment' "$arch" | log
1553 title 'Setting up your %s cross environment' "$arch"
1554 init_db_files
1555 sed -i \
1556 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1557 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1558 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1559 /etc/slitaz/cook.conf
1560 case "$arch" in
1561 arm)
1562 flags='-O2 -march=armv6'
1563 host="$ARCH-slitaz-linux-gnueabi" ;;
1564 armv6hf)
1565 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1566 host="$ARCH-slitaz-linux-gnueabi" ;;
1567 armv7)
1568 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1569 host="$ARCH-slitaz-linux-gnueabi" ;;
1570 x86_64)
1571 flags='-O2 -mtune=generic -pipe'
1572 host="$ARCH-slitaz-linux" ;;
1573 esac
1574 sed -i \
1575 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1576 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1577 . /etc/slitaz/cook.conf
1578 sysroot="$CROSS_TREE/sysroot"
1579 tools="/cross/$arch/tools"
1580 root="$sysroot"
1581 # L10n: keep the same width of translations to get a consistent view
1582 _ 'Target arch : %s' "$ARCH"
1583 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1584 _ 'Build flags : %s' "$flags"
1585 _ 'Arch sysroot : %s' "$sysroot"
1586 _ 'Tools prefix : %s' "$tools/bin"
1587 # Tell the packages manager where to find packages.
1588 _ 'Packages DB : %s' "$root$DB"
1589 mkdir -p $root$INSTALLED
1590 cd $root$DB; rm -f *.bak
1591 for list in packages.list packages.desc packages.equiv packages.md5; do
1592 rm -f $list
1593 ln -s $SLITAZ/packages/$list $list
1594 done
1595 # We must have the cross compiled glibc-base installed or default
1596 # i486 package will be used as dep by tazpkg and then break the
1597 # cross environment
1598 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1599 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1600 fi
1601 # Show GCC version or warn if not yet compiled.
1602 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1603 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1604 else
1605 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1606 _ 'Run "%s" to cook a toolchain' 'cross compile'
1607 fi
1608 footer ;;
1610 test)
1611 # Test a cook environment.
1612 _ 'Cook test: testing the cook environment' | log
1613 [ ! -d "$WOK" ] && exit 1
1614 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1615 cook cooktest ;;
1617 new)
1618 # Create the package folder and an empty receipt.
1619 pkg="$2"
1620 [ -z "$pkg" ] && usage
1621 newline
1622 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1624 action 'Creating folder "%s"' "$WOK/$pkg"
1625 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1627 action 'Preparing the package receipt...'
1628 cp $DATA/receipt .
1629 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1630 status; newline
1632 # Interactive mode, asking and seding.
1633 case "$3" in
1634 --interactive|-x)
1635 _ 'Entering interactive mode...'
1636 separator
1637 _ 'Package : %s' "$pkg"
1639 _n 'Version : ' ; read answer
1640 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1642 _n 'Category : ' ; read answer
1643 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1645 # L10n: Short description
1646 _n 'Short desc : ' ; read answer
1647 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1649 _n 'Maintainer : ' ; read answer
1650 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1652 _n 'License : ' ; read answer
1653 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1655 _n 'Web site : ' ; read answer
1656 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1657 newline
1659 # Wget URL.
1660 _ 'Wget URL to download source tarball.'
1661 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1662 _n 'Wget url : ' ; read answer
1663 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1665 # Ask for a stuff dir.
1666 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1667 if [ "$?" -eq 0 ]; then
1668 action 'Creating the stuff directory...'
1669 mkdir $WOK/$pkg/stuff; status
1670 fi
1672 # Ask for a description file.
1673 confirm "$(_n 'Are you going to write a description? (y/N)')"
1674 if [ "$?" -eq 0 ]; then
1675 action 'Creating the "%s" file...' 'description.txt'
1676 touch $WOK/$pkg/description.txt; status
1677 fi
1679 footer "$(_ 'Receipt is ready to use.')" ;;
1680 esac ;;
1682 list)
1683 # Cook a list of packages (better use the Cooker since it will order
1684 # packages before executing cook).
1685 check_root
1686 [ -z "$2" ] && die 'No list in argument.'
1687 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1689 _ 'Starting cooking the list "%s"' "$2" | log
1691 while read pkg; do
1692 cook $pkg || broken
1693 done < $2
1694 ;;
1696 clean-wok)
1697 check_root
1698 newline; action 'Cleaning all packages files...'
1699 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1700 status; newline ;;
1702 clean-src)
1703 check_root
1704 newline; action 'Cleaning all packages sources...'
1705 rm -rf $WOK/*/source
1706 status; newline ;;
1708 uncook)
1709 cd $WOK
1710 count=0
1711 title 'Checking for uncooked packages'
1713 for i in *; do
1714 unset HOST_ARCH EXTRAVERSION
1715 [ ! -e $i/receipt ] && continue
1716 . ./$i/receipt
1717 # Source cooked pkg receipt to get EXTRAVERSION
1718 if [ -d "$WOK/$i/taz" ]; then
1719 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
1720 . ./receipt; cd $WOK
1721 fi
1722 case "$ARCH" in
1723 i486)
1724 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1725 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1726 count=$(($count + 1))
1727 colorize 34 "$i"
1728 fi ;;
1729 arm*)
1730 # Check only packages included in arch
1731 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1732 # *.tazpkg
1733 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1734 count=$(($count + 1))
1735 colorize 34 "$i"
1736 fi
1737 fi ;;
1738 esac
1739 done
1741 if [ "$count" -gt 0 ]; then
1742 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1743 else
1744 _ 'All packages are cooked :-)'
1745 newline
1746 fi
1747 ;;
1749 pkgdb)
1750 # Create suitable packages list for TazPkg and only for built packages
1751 # as well as flavors files for TazLiTo. We don't need logs since we do it
1752 # manually to ensure everything is fine before syncing the mirror.
1753 recreate_split_db
1754 recreate_maint_db
1755 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1756 ;;
1758 splitdb)
1759 # File split.db is useful for searching for split packages.
1760 recreate_split_db
1761 ;;
1763 maintdb)
1764 # File maint.db is useful for searching maintainer's packages.
1765 recreate_maint_db
1766 ;;
1768 *)
1769 # Just cook and generate a package.
1770 check_root
1771 time=$(date +%s)
1772 pkg="$1"
1773 [ -z "$pkg" ] && usage
1775 # Search last successful cook time in all logs from newer to older
1776 for i in '' $(seq 0 9 | sed 's|^|.|'); do
1777 [ -f "$LOGS/$pkg.log$i" ] || break
1778 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1779 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
1780 [ -n "$lastcooktime" ] && break
1781 done
1783 receipt="$WOK/$pkg/receipt"
1784 check_pkg_in_wok
1785 newline
1787 unset inst
1788 unset_receipt
1789 . $receipt
1791 # Handle cross compilation.
1792 case "$ARCH" in
1793 arm*)
1794 if [ -z "$HOST_ARCH" ]; then
1795 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1796 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1797 _ 'cook: %s' "$error"
1798 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1799 _ 'Cook skip: %s' "$error" | log
1800 newline
1801 broken; exit 1
1802 fi ;;
1803 esac
1805 # Some packages are not included in some arch or fail to cross compile.
1806 : ${HOST_ARCH=$ARCH}
1807 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1808 # Handle arm{v6hf,v7,..}
1809 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1810 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1811 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1812 _ 'cook: %s' "error"
1813 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1814 _ 'Cook skip: %s' "$error" | log
1815 sed -i "/^${pkg}$/d" $broken
1816 newline
1817 exit 0
1818 fi
1820 # Remove package from broken list before cooking
1821 sed -i "/^${pkg}$/d" $broken
1823 # Skip blocked, 3 lines also for the Cooker.
1824 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1825 die 'Package "%s" is blocked' "$pkg"
1827 try_aufs_chroot "$@"
1829 # Log and source receipt.
1830 echo "cook:$pkg" > $command
1832 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1834 while read cmd duration start; do
1835 [ $(($start + $duration)) -lt $(date +%s) ] &&
1836 echo "sed -i '/^$cmd $duration/d' $cooktime"
1837 done < $cooktime | sh
1839 # Display and log info if cook process stopped.
1840 # FIXME: gettext not working (in single quotes) here!
1841 trap '_ "\n\nCook stopped: control-C\n\n" | \
1842 tee -a $LOGS/$pkg.log' INT
1844 update_split_db
1846 # Handle --options
1847 case "$2" in
1848 --pack)
1849 _ 'Packing %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1850 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
1851 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
1852 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -f $LOGS/$pkg-pack.log
1853 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
1854 @@PREFIX@@/libexec/cookutils/postcheck $pkg | tee -a $LOGS/$pkg.log
1855 clean_log "$pkg-pack"
1856 time=$(($(date +%s) - $time))
1857 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
1858 gen_rss
1859 put_status $pkg Done
1860 rm -f $command
1861 exit 0 ;;
1863 --trials|-t)
1864 trials='yes' ;;
1865 esac
1867 _ 'Making %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1869 # Rotate log
1870 for i in $(seq 9 -1 1); do
1871 j=$(($i - 1))
1872 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1873 done
1874 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1876 # Check if wanted is built now so we have separate log files.
1877 for wanted in $WANTED ; do
1878 if grep -q "^$wanted$" $blocked; then
1879 broken
1880 rm -f $command
1881 die 'WANTED package "%s" is blocked' "$wanted"
1882 fi
1883 if grep -q "^$wanted$" $broken; then
1884 broken
1885 rm -f $command
1886 die 'WANTED package "%s" is broken' "$wanted"
1887 fi
1888 if [ ! -d "$WOK/$wanted/install" ]; then
1889 cook "$wanted" || { broken; exit 1; }
1890 fi
1891 done
1893 # Cook and pack or exit on error and log everything.
1894 ( ( ( (cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq) )
1895 rq=$? # the return code of `cookit $@` above command
1897 if [ $rq -eq 1 ]; then
1898 broken
1899 fi
1901 # Remove build dependencies both when `cookit` done or fail
1902 remove_deps | tee -a $LOGS/$pkg.log
1903 timestamp job27 # removing bdeps
1904 # cookit_quality
1905 timestamp job28 # checking quality
1907 # Log and stop if `cookit` fails
1908 if [ $rq -eq 1 ]; then
1909 debug_info "ret1" | tee -a $LOGS/$pkg.log
1910 @@PREFIX@@/libexec/cookutils/postcheck $pkg | tee -a $LOGS/$pkg.log
1911 put_status $pkg Failed
1912 rm -f $command
1913 broken
1914 exit 1
1915 fi
1917 # Proceed only if `cookit` return code is zero-OK
1918 # If instant-pack if specified, then packages already packed in the cookit()
1919 [ "${COOKOPTS/instant-pack/}" == "$COOKOPTS" ] &&
1920 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1921 timestamp job29 # packing
1923 @@PREFIX@@/libexec/cookutils/postcheck $pkg | tee -a $LOGS/$pkg.log
1925 clean_log
1927 # Exit if any error in packing.
1928 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
1929 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1930 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1931 debug_info "packerr" | tee -a $LOGS/$pkg.log
1932 put_status $pkg Failed
1933 rm -f $command
1934 broken; exit 1
1935 fi
1937 # Create an XML feed
1938 gen_rss
1940 # Time and summary
1941 time=$(($(date +%s) - $time))
1942 summary | tee -a $LOGS/$pkg.log
1943 newline
1945 # We may want to install/update (outside aufs jail!).
1946 [ -s /aufs-umount.sh ] || install_package
1948 put_status $pkg Done
1950 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1951 # If you want automation, use the Cooker Build Bot.
1952 rm -f $command
1953 timestamp job30 # misc. final operations
1954 store_timestats
1956 sed -n '/^Build dependencies to remove:/,/^$/p' $LOGS/$pkg.log \
1957 | sed '/^Build/d; s|Removing: ||' \
1958 | tr ' ' '\n' \
1959 | sed '/^$/d' \
1960 > $WOK/$pkg/.bdeps
1962 ;;
1963 esac
1965 exit 0