cookutils view cook @ rev 1136
lighttpd/cooker.css, lighttpd/cooker.js, lighttpd/index.cgi: add syntax highlighting for *.lua files; modules/pack: add default CAT for lib<package>
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Wed Jan 30 23:26:44 2019 +0200 (2019-01-30) |
parents | a5e73bdcc218 |
children | db1cfeb9ac36 |
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 [ -f "$PKGS/$pkgname" ] || continue
369 size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
370 files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/files.list)
371 printf "%2d : %7s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
372 pkgi=$((pkgi + 1))
373 done
374 separator
375 }
378 # Display debugging error info.
380 debug_info() {
381 title 'Debug information %s.' "$1"
382 # L10n: specify your format of date and time (to help: man date)
383 # L10n: not bad one is '+%x %R'
384 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
385 if [ -n "$time" ]; then
386 times="$(($(date +%s) - $time))"
387 _ 'Wasted time : %s' "$(disp_time "$times")"
388 fi
389 for error in \
390 ERROR 'No package' "cp: can't" "can't open" "can't cd" \
391 'error:' 'fatal error:' 'undefined reference to' \
392 'Unable to connect to' 'link: cannot find the library' \
393 'CMake Error' ': No such file or directory' \
394 'Could not read symbols: File in wrong format'
395 do
396 # format "line number:line content"
397 fgrep -n "$error" $LOGS/$pkg.log
398 done > $LOGS/$pkg.log.debug_info 2>&1
399 # sort by line number, remove duplicates
400 sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
401 rm -f $LOGS/$pkg.log.debug_info
402 footer
403 }
406 # A bit smarter function than the classic `cp` command
408 scopy() {
409 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
410 cp -a "$1" "$2" # copy generic files
411 else
412 cp -al "$1" "$2" # copy hardlinks
413 fi
414 }
417 # Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
418 # We use standard paths, so some packages need to copy these files with the
419 # receipt and genpkg_rules.
420 # This function executes inside the packaging process, before compressor call.
422 copy_generic_files() {
423 # Proceed only for "main" package (for v2), and for any packages (v1)
424 [ "$pkg" == "$PACKAGE" ] || return 0
426 # $LOCALE is set in cook.conf
427 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
428 if [ -d "$install/usr/share/locale" ]; then
429 mkdir -p "$fs/usr/share/locale"
430 for i in $LOCALE; do
431 if [ -d "$install/usr/share/locale/$i" ]; then
432 cp -r $install/usr/share/locale/$i $fs/usr/share/locale
433 fi
434 done
435 fi
436 fi
438 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
439 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
440 if [ -d "$install/usr/share/pixmaps" ]; then
441 mkdir -p "$fs/usr/share/pixmaps"
442 for i in png xpm; do
443 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
444 cp -r $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
445 done
446 fi
447 fi
449 # Desktop entry (.desktop).
450 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
451 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
452 if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
453 mkdir -p "$fs/usr/share"
454 cp -r $install/usr/share/applications $fs/usr/share
455 fi
456 fi
457 }
460 # Copy pixmaps, desktop files and licenses from $stuff to $install.
461 # This function executes after the main compile_rules() is done.
463 copy_generic_stuff() {
464 # Custom or homemade PNG pixmap can be in stuff.
465 if [ -f "$stuff/$PACKAGE.png" ]; then
466 mkdir -p $install/usr/share/pixmaps
467 cp $stuff/$PACKAGE.png $install/usr/share/pixmaps
468 fi
470 # Homemade desktop file(s) can be in stuff.
471 if [ -d "$stuff/applications" ]; then
472 mkdir -p $install/usr/share
473 cp -r $stuff/applications $install/usr/share
474 fi
475 if [ -f "$stuff/$PACKAGE.desktop" ]; then
476 mkdir -p $install/usr/share/applications
477 cp $stuff/$PACKAGE.desktop $install/usr/share/applications
478 fi
480 # Add custom licenses
481 if [ -d "$stuff/licenses" ]; then
482 mkdir -p $install/usr/share/licenses
483 cp -r $stuff/licenses $install/usr/share/licenses/$PACKAGE
484 fi
485 }
488 # Update installed.cook.diff
490 update_installed_cook_diff() {
491 # If a cook failed deps are removed.
492 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
493 cd $CACHE
494 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
495 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
496 deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
497 }
500 # Remove installed deps.
502 remove_deps() {
503 # Now remove installed build deps.
504 diff='/tmp/installed.cook.diff'
505 [ -s "$diff" ] || return
507 deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
508 nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
509 newline
510 _n 'Build dependencies to remove:'; echo " $nb"
511 [ -n "$root" ] && echo "root=\"$root\""
513 _n 'Removing:'
514 for dep in $deps; do
515 echo -n " $dep"
516 # Do not waste time uninstalling the packages if we are inside
517 # aufs chroot - unmounting chroot will "uninstall" all packages.
518 [ -s /aufs-umount.sh ] ||
519 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
520 done
522 newline; newline
523 # Keep the last diff for debug and info.
524 mv -f $diff $CACHE/installed.diff
525 }
528 # Automatically patch the sources.
530 patchit() {
531 [ -f "$stuff/patches/series" ] || return
532 # Empty lines and comments (started with "#") are ignored
533 # Up to three fields (no spaces inside allowed) separated by "|":
534 # 1. patch options like "-p0" (optional);
535 # 2. patch file name or URL (mandatory);
536 # 3. patch checksum in form "sha1=..." or other *sum (optional).
538 local done="$pkgdir/.patch.done" var1 var2 var3
539 local patchname patchopts patchfile patchsum patchsum_type patchsum_sum
540 IFS=$'\n'
541 while read i; do
542 patchname=$(echo ${i%%#*} | cut -d' ' -f1) # allow comments (anything after the # or space)
543 [ -n "$patchname" ] || continue # skip empty lines
545 var1=$(echo "$patchname||" | cut -d'|' -f1) # options or name
546 var2=$(echo "$patchname||" | cut -d'|' -f2) # name or checksum or empty
547 var3=$(echo "$patchname||" | cut -d'|' -f3) # checksum or empty
549 if [ -n "$var3" ]; then
550 patchopts="$var1"; patchname="$var2"; patchsum="$var3"
551 elif [ -n "$var2" ]; then
552 case $var2 in
553 *=*) patchopts='-Np1'; patchname="$var1"; patchsum="$var2";;
554 *) patchopts="$var1"; patchname="$var2"; patchsum='';;
555 esac
556 else
557 patchopts='-Np1'; patchname="$var1"; patchsum=''
558 fi
560 case $patchname in
561 ftp://*|http://*|https://*)
562 patchfile="$SRC/$(basename $patchname)"
563 [ -e "$patchfile" ] || wget -q -T 60 -O $patchfile $patchname ||
564 die 'ERROR: %s' "can't get $patchname"
565 ;;
566 *)
567 patchfile="$stuff/patches/$patchname"
568 ;;
569 esac
571 if [ -n "$patchsum" ]; then
572 patchsum_type=${patchsum%=*}
573 patchsum_sum=${patchsum#*=}
574 echo "$patchsum_sum $patchfile" | ${patchsum_type}sum -cs ||
575 die 'ERROR: %s' "wrong ${patchsum_type}sum for $patchfile"
576 else
577 case $patchfile in
578 $SRC/*) echo "warning: no checksum for external patch!";;
579 esac
580 fi
582 touch $done
583 grep -q "^${patchname}$" $done && continue # already applied (useful with `cook --continue`)
585 newline
586 _ 'Applying patch %s' "$patchname"
587 patch $patchopts -i $patchfile | sed 's|^| |'
589 echo $patchname >> $done
590 done < $stuff/patches/series
591 newline
592 unset IFS
593 }
596 # Check source tarball integrity.
598 check_integrity() {
599 for i in sha1 sha3 sha256 sha512 md5; do
600 I=$(echo $i | tr 'a-z' 'A-Z')
601 eval sum=\$TARBALL_$I
602 if [ -n "$sum" ]; then
603 newline
604 _ 'Checking %ssum of source tarball...' "$i"
605 echo "$sum $SRC/$TARBALL" | ${i}sum -c || exit 1
606 fi
607 done
608 newline
609 }
612 # Misc fix functions
614 fix() {
615 case $1 in
616 # https://bugzilla.gnome.org/show_bug.cgi?id=655517
617 # https://wiki.gentoo.org/wiki/Project:Quality_Assurance/As-needed
618 ld)
619 export LDFLAGS="$LDFLAGS -Wl,-Os,--as-needed"
620 ;;
621 libtool)
622 if [ -e 'libtool' ]; then
623 sed -i 's| -shared | -Wl,-Os,--as-needed\0|g' libtool
624 echo "fix.libtool" >> $pkgdir/.patch.done
625 else
626 echo "fix libtool: warning: libtool absent, nothing to fix."
627 fi
628 ;;
629 math)
630 # fix C++ math issue introduced in Glibc 2.26:
631 # error: '__builtin_isnan' is not a member of 'std'
632 # if (std::isnan(N)) {
633 # ^
634 find $src -type f -exec sed -i '
635 s|std::signbit|__builtin_signbit|g;
636 s|std::isnan|__builtin_isnan|g;
637 s|std::isinf|__builtin_isinf_sign|g;
638 s|std::isfinite|__builtin_isfinite|g;
639 s|std::isnormal|__builtin_isnormal|g
640 ' '{}' \;
641 ;;
642 symlinks)
643 # make absolute symlinks relative
644 echo "fix symlinks"
645 local ifs="$IFS" link target
646 IFS=$'\n'
647 # step 1: fast job, prefix all the absolute symlinks with "$install"
648 for link in $(find $install -type l); do
649 target="$(readlink $link)"
650 case "$target" in
651 /*) ln -sfv "$install$target" "$link";;
652 esac
653 done
654 IFS="$ifs"
655 # step 2: fine tuning, make symlinks relative
656 tazpkg -gi --quiet --local --cookmode symlinks
657 symlinks -cr $install
658 ;;
659 gem)
660 # some useful operations while Ruby gems cooking
661 _gems="$(ruby -e'puts Gem.default_dir')"
663 # remove unwanted empty folders
664 rmdir --ignore-fail-on-non-empty \
665 $install/$_gems/build_info/ \
666 $install/$_gems/cache/ \
667 $install/$_gems/doc/ \
668 $install/$_gems/extensions/
670 # move files to docdir
671 docdir=$install/usr/share/doc/$PACKAGE-$VERSION
672 for i in $(ls -ap $install/$_gems/gems/${PACKAGE#*-}-$VERSION/ | sed '
673 /\/$/d; /^\./d; /gemspec$/d; /Rakefile*/d; /Gemfile*/d; /Makefile/d;
674 /\.c$/d; /\.h$/d; /\.o$/d; /\.rb$/d; /\.so$/d; /\.yml$/d;
675 /Manifest/d; /\.inc$/d; /depend/d;
676 '); do
677 mkdir -p $docdir # docdir will not be created when nothing to move
678 mv $install/$_gems/gems/${PACKAGE#*-}-$VERSION/$i $docdir
679 done
680 if [ -d $install/$_gems/gems/${PACKAGE#*-}-$VERSION/doc/ ]; then
681 mkdir -p $docdir
682 mv $install/$_gems/gems/${PACKAGE#*-}-$VERSION/doc/ $docdir
683 fi
685 if [ -d $docdir ]; then
686 # move man pages
687 unset man_to_copy
688 for i in $(seq 1 8); do
689 for j in $(find $docdir -type f -name "*.$i" | sed '/LGPL-2\.1/d'); do
690 man_to_copy="$man_to_copy $j"
691 done
692 done
693 if [ -n "$man_to_copy" ]; then
694 cook_pick_manpages $man_to_copy
695 rm $man_to_copy
696 fi
698 # convert rdoc to markdown (thanks https://gist.github.com/teeparham/8a99e308884e1c32735a)
699 for i in $(find $docdir -type f -name '*.rdoc'); do
700 fix utf-8
701 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
702 done
703 fi
705 # move man pages (from the different place)
706 rubyman=$install/$_gems/gems/${PACKAGE#*-}-$VERSION/man
707 if [ -d $rubyman ]; then
708 unset man_to_copy
709 for i in $(seq 1 8); do
710 for j in $(find $rubyman -type f -name "*.$i" | sed '/LGPL-2\.1/d'); do
711 man_to_copy="$man_to_copy $j"
712 done
713 done
714 if [ -n "$man_to_copy" ]; then
715 cook_pick_manpages $man_to_copy
716 fi
717 rm -r $rubyman
718 fi
719 ;;
720 utf-8)
721 # Install UTF-8 locale
722 tazpkg -gi --quiet --local --cookmode locale-en-base
723 mkdir -p /usr/lib/locale
724 localedef -i 'en_US' -c -f 'UTF-8' /usr/lib/locale/en_US.UTF-8
725 ;;
726 esac
727 }
730 # Typical function used in compile_rules() to make perl modules packages
732 cook_perl() {
733 if [ -e "Makefile.PL" ]; then
734 # Up to 3 optional parameters supported
735 PERL_MM_USE_DEFAULT=1 perl Makefile.PL INSTALLDIRS=vendor $1 &&
736 make $2 &&
737 make $3 PERL_MM_USE_DEFAULT=1 DESTDIR=$install install &&
738 chmod -R u+w $install
739 elif [ -e "Build.PL" ]; then
740 echo "Not implemented yet"
741 return 1
742 else
743 echo "Unable to cook Perl module"
744 return 1
745 fi
746 }
749 # Store timestamps, log jobs length
751 timestamp() {
752 local ts_file="$WOK/$pkg/.ts"
753 local curr_ts=$(date '+%s')
754 case $1 in
755 init)
756 rm $ts_file 2>/dev/null
757 echo $curr_ts > $prev_ts
758 ;;
759 job*)
760 # calculate time from the last timestamp
761 echo "$1='$(( $curr_ts - $(cat $prev_ts) ))'" >> $ts_file
762 echo $curr_ts > $prev_ts
763 ;;
764 sets)
765 echo "sets='$2'" >> $ts_file
766 ;;
767 esac
768 }
771 # Store time statsistics to the cache
773 store_timestats() {
774 # see doc/timestats.txt for file format
775 temp=$(mktemp)
776 {
777 for i in $(seq 1 30); do echo "job$i=0"; done
778 cat $WOK/$pkg/.ts
779 echo -n 'total=$(( 0'
780 for i in $(seq 1 30); do echo -n " + job$i"; done
781 echo ' ))'
782 } > $temp
783 . $temp
784 {
785 echo -n "$pkg $sets "
786 for i in $(seq 1 30); do echo -n "$((job$i)) "; done
787 echo "$total"
788 } >> /home/slitaz/cache/timestats
789 rm $temp $WOK/$pkg/.ts # clean
790 }
793 # Internal function to cook specified SET
795 cook_set() {
796 # Switch to the specified source set
797 set_paths
798 local suffix=''
799 [ -n "$SET" ] && suffix="-$SET"
800 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
801 export install="$WOK/$pkg/install$suffix"
802 export DESTDIR="$install"
804 if [ -n "$SETS" ]; then
805 if [ -n "$SET" ]; then
806 title "Switching to the set '$SET'"
807 else
808 title "Switching to the default set"
809 fi
810 echo "src : $src"
811 echo "install: $install"
812 fi
813 [ -d "$src" ] && cd $src # packages without sources exists
814 echo
816 [ -d "$install" ] && rm -r $install
817 #mkdir -p $install
819 compile_rules $@ || { broken; exit 1; }
821 # Stay compatible with _pkg
822 [ -d "$src/_pkg" ] && mv $src/_pkg $install
824 copy_generic_stuff
826 timestamp job$job_counter # compiling (set '$SET')
828 # Actions to do after compiling the package
829 # Skip all for split packages (already done in main package)
830 if [ -z "$WANTED" ]; then
831 footer
832 export COOKOPTS ARCH install
833 @@PREFIX@@/libexec/cookutils/compressor install
834 timestamp job$(($job_counter + 1)) # compressing (set '$SET')
835 fi
837 # Activate "instant-pack" mode
838 if [ "${COOKOPTS/instant-pack/}" != "$COOKOPTS" ]; then
839 echo " $SPLIT " | fgrep -q " $PACKAGE " || SPLIT="$PACKAGE $SPLIT"
840 export PACKAGE
841 # determine the list of the packages belongs to the current SET...
842 echo -n $SPLIT \
843 | awk -vset="$SET" '
844 BEGIN { RS = " "; FS = ":"; }
845 { if ($2 == set) print $1; }' \
846 | xargs -n1 @@PREFIX@@/libexec/cookutils/pack # ... and then pack them
847 fi
849 job_counter=$(($job_counter + 2))
850 }
853 # The main cook function.
855 cookit() {
856 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
857 _ 'ERROR: Broken setup. Abort.'
858 return
859 fi
861 title 'Cook: %s' "$PACKAGE $VERSION"
862 set_paths
863 timestamp init # the very start
865 # Handle cross-tools.
866 [ "$BUILD_SYSTEM" != "$HOST_SYSTEM" ] &&
867 case "$ARCH" in
868 arm*|x86_64)
869 # CROSS_COMPILE is used by at least Busybox and the kernel to set
870 # the cross-tools prefix. Sysroot is the root of our target arch
871 sysroot="$CROSS_TREE/sysroot"
872 tools="$CROSS_TREE/tools"
873 # Set root path when cross compiling. ARM tested but not x86_64
874 # When cross compiling we must install build deps in $sysroot.
875 arch="-$ARCH"
876 root="$sysroot"
877 _ '%s sysroot: %s' "$ARCH" "$sysroot"
878 _ 'Adding "%s" to PATH' "$tools/bin"
879 export PATH="$PATH:$tools/bin"
880 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
881 export CROSS_COMPILE="$HOST_SYSTEM-"
882 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
883 if [ "$ARCH" == 'x86_64' ]; then
884 export CC="$HOST_SYSTEM-gcc -m64"
885 export CXX="$HOST_SYSTEM-g++ -m64"
886 else
887 export CC="$HOST_SYSTEM-gcc"
888 export CXX="$HOST_SYSTEM-g++"
889 fi
890 export AR="$HOST_SYSTEM-ar"
891 export AS="$HOST_SYSTEM-as"
892 export RANLIB="$HOST_SYSTEM-ranlib"
893 export LD="$HOST_SYSTEM-ld"
894 export STRIP="$HOST_SYSTEM-strip"
895 export LIBTOOL="$HOST_SYSTEM-libtool"
896 ;;
897 esac
899 @@PREFIX@@/libexec/cookutils/precheck $receipt || exit 1 # former receipt_quality()
901 cd $pkgdir
902 if [ -z "$continue" ]; then
903 rm -rf source 2>/dev/null
904 rm .patch.done 2>/dev/null
905 fi
906 rm -rf install taz 2>/dev/null
908 # Disable -pipe if less than 512 MB free RAM.
909 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
910 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
911 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
912 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
913 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
914 fi
915 unset free
917 # Export flags and path to be used by make and receipt.
918 DESTDIR="$pkgdir/install"
919 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
920 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C \
921 LDFLAGS
923 timestamp job1 # pre-checks
925 # BUILD_DEPENDS may vary depending on the ARCH
926 case "$ARCH" in
927 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
928 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
929 esac
931 # Check for build deps and handle implicit depends of *-dev packages
932 # (ex: libusb-dev :: libusb).
933 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
934 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
936 # Get the list of installed packages
937 cd $root$INSTALLED; ls > $CACHE/installed.list
939 for action in check install; do
940 for dep in $BUILD_DEPENDS; do
941 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
942 for i in $dep $implicit; do
943 # Skip if package already installed
944 [ -f "$root$INSTALLED/$i/receipt" ] && continue
946 case $action in
947 check)
948 # Search for local package or local provided-package
949 name=$(awk -F$'\t' -vpkg="$i" '{
950 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
951 }' "$PKGS/packages-$ARCH.info")
952 if [ -z "$name" ]; then
953 # Search for package in mirror
954 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
955 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
956 fi
957 ;;
958 install)
959 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
960 ;;
961 esac
962 done
963 done
964 done
966 update_installed_cook_diff
968 timestamp job2 # installing bdeps
970 # Get source tarball and make sure we have source dir named:
971 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
972 # tarball if it exists.
973 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
974 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
975 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
976 LZMA_SRC=''
977 else
978 get_source || { broken; exit 1; }
979 fi
980 fi
981 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
982 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
983 if ! extract_source ; then
984 get_source
985 extract_source || { broken; exit 1; }
986 fi
987 if [ -n "$LZMA_SRC" ]; then
988 cd $pkgdir/source
989 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
990 mv tmp tmp-1; mkdir tmp
991 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
992 fi
993 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
994 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
995 fi
996 fi
998 cd $pkgdir/source/tmp
999 # Some archives are not well done and don't extract to one dir (ex lzma).
1000 files=$(ls | wc -l)
1001 [ "$files" -eq 1 -a -d "$(ls)" ] &&
1002 mv * ../$PACKAGE-$VERSION
1003 [ "$files" -eq 1 -a -f "$(ls)" ] &&
1004 mkdir -p ../$PACKAGE-$VERSION &&
1005 mv * ../$PACKAGE-$VERSION/$TARBALL
1006 [ "$files" -gt 1 ] &&
1007 mkdir -p ../$PACKAGE-$VERSION &&
1008 mv * ../$PACKAGE-$VERSION
1009 cd ..; rm -rf tmp
1010 fi
1012 # Check md5sum (or similar) for sources tarball
1013 check_integrity
1015 # Libtool shared libs path hack.
1016 case "$ARCH" in
1017 arm*) cross libhack ;;
1018 esac
1020 timestamp job3 # get/unpack src tarball
1022 # Compiling all the sets
1023 if grep -q ^compile_rules $receipt; then
1024 _ 'Executing: %s' 'compile_rules'
1025 echo "CFLAGS : $CFLAGS"
1026 echo "CXXLAGS : $CXXFLAGS"
1027 echo "CPPFLAGS : $CPPFLAGS"
1028 echo "LDFLAGS : $LDFLAGS"
1029 [ -d "$src" ] && cd $src
1030 patchit
1032 timestamp job4 # patching
1034 # Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
1035 # Keep natural order of the sets, don't sort them alphabetically
1036 SETS=$(echo -n $SPLIT \
1037 | awk '
1038 BEGIN { RS = " "; FS = ":"; }
1039 {
1040 if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; }
1041 }' \
1042 | sed 's| $||')
1043 # Prepare specified source sets using patched sources
1044 [ -n "$SETS" -a -d "$src" ] &&
1045 for set in $SETS; do
1046 echo "Preparing set $set" # debug
1047 cp -a $src $src-$set
1048 done
1050 timestamp job5 # preparing sets
1051 timestamp sets "$SETS"
1053 job_counter='6'
1055 SET='' cook_set # first run for empty SET
1057 # Allow to change SETS after the first run, follow the changes
1058 SETS=$(. $receipt; echo -n $SPLIT \
1059 | awk '
1060 BEGIN { RS = " "; FS = ":"; }
1061 {
1062 if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; }
1063 }' \
1064 | sed 's| $||')
1065 for SET in $SETS; do
1066 cook_set
1067 done
1068 else
1069 mkdir -p $install # allow receipts without `compile_rules()`
1070 fi
1071 footer
1073 timestamp job # reset counter
1075 # Execute testsuite.
1076 if grep -q ^testsuite $receipt; then
1077 title 'Running testsuite'
1078 testsuite $@ || { broken; exit 1; }
1079 footer
1080 fi
1082 timestamp job26 # test suite
1084 update_installed_cook_diff force
1085 }
1088 # Cook quality assurance.
1090 cookit_quality() {
1091 while true; do
1092 [ ! -d "$WOK/$pkg/install" -a -z "$WANTED" ] || break
1093 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
1094 [ "$trials" == 'yes' ] || break
1095 title "Interactive mode"
1096 # TODO: allow commands:
1097 # q - quit; v - edit receipt here using vi;
1098 # s - search for package containing package;
1099 # <package name> - install package; [Enter] - retry
1100 _ 'You may install the packages here and/or edit the receipt there.'
1101 newline
1102 while true; do
1103 _n 'Install the package? [name/N] '; read answer
1104 [ -n "$answer" ] || break
1105 tazpkg -gi $answer --root=$root --local --quiet --cookmode
1106 done
1107 newline
1108 _n 'Try again? [Y/n] '; read answer
1109 [ "$answer" == 'n' ] && break
1110 # here you may append log if you want (">>" instead of last ">")
1111 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1112 done
1114 [ "${COOKOPTS/skip-log-errors/}" != "$COOKOPTS" ] && return 0
1116 # ERROR can be echoed any time in cookit()
1117 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
1118 grep -Eq "(^ERROR|undefined reference to)" ; then
1119 debug_info "cookit_quality" | tee -a $LOGS/$pkg.log
1120 put_status $pkg Failed
1121 # rm -f $command
1122 # broken; exit 1
1123 fi
1124 }
1127 # Return all the names of packages bundled in this receipt
1129 all_names() {
1130 # Get package names from $SPLIT variable
1131 local split=$(echo -n $SPLIT \
1132 | awk '
1133 BEGIN { RS = " "; FS = ":"; }
1134 { print $1; }' \
1135 | tr '\n' ' ')
1136 local split_space=" $split "
1137 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
1138 # For receipts v1: $SPLIT may present in the $WANTED package,
1139 # but split packages have their own receipts
1140 echo $PACKAGE
1141 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
1142 # $PACKAGE included somewhere in $SPLIT (probably in the end).
1143 # We should build packages in the order defined in the $SPLIT.
1144 echo $split
1145 else
1146 # We'll build the $PACKAGE, then all defined in the $SPLIT.
1147 echo $PACKAGE $split
1148 fi
1149 }
1152 # v2: pack all packages using compiled files
1154 packall() {
1155 set_paths
1156 [ -e $pkgdir/.arch ] && rm $pkgdir/.arch
1158 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1159 for i in $(all_names); do
1160 unset TAGS DEPENDS CAT CONFIG_FILES PROVIDE SUGGESTED DATABASE_FILES TAZPANEL_DAEMON
1161 export PACKAGE; @@PREFIX@@/libexec/cookutils/pack $i
1162 done
1163 else
1164 export PACKAGE; @@PREFIX@@/libexec/cookutils/pack $PACKAGE
1165 fi
1166 }
1169 # Reverse "cat" command: prints input lines in the reverse order
1171 tac() {
1172 sed '1!G;h;$!d' $1
1173 }
1176 # Install package: update the chroot with freshly rebuilt package: keep env up-to-date.
1178 install_package() {
1179 set_paths
1180 case "$ARCH" in
1181 arm*) root="$CROSS_TREE/sysroot";;
1182 esac
1184 # Process all the package names built by this receipt (defined in $SPLIT)
1185 for i in $(PACKAGE="$pkg" all_names); do
1186 if [ -d "$root$INSTALLED/$i" ]; then
1187 pkg_file=$(awk -F$'\t' -vpkg="$i" -varch="$ARCH" '{
1188 if ($1 == pkg) {
1189 pkgarch = ($11 == "0") ? "any" : arch;
1190 printf("%s-%s-%s.tazpkg", $1, $2, pkgarch);
1191 exit
1192 }
1193 }' $PKGS/packages-$ARCH.info)
1194 if [ -e "$PKGS/$pkg_file" ]; then
1195 _ 'Updating %s chroot environment...' "$ARCH"
1196 _ 'Updating chroot: %s' "${pkg_file%.tazpkg}" | log
1197 tazpkg -i "$PKGS/$pkg_file" --forced --root=$root
1198 fi
1199 fi
1200 done
1201 }
1204 # remove chroot jail
1206 umount_aufs() {
1207 tac ${1}rw/aufs-umount.sh | sh
1208 rm -rf ${1}rw
1209 umount ${1}root
1210 rmdir ${1}r*
1211 }
1214 # Launch the cook command into a chroot jail protected by aufs.
1215 # The current filesystems are used read-only and updates are
1216 # stored in a separate branch.
1218 try_aufs_chroot() {
1220 base="/dev/shm/aufsmnt$$"
1222 # Can we setup the chroot? Is it already done?
1223 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1224 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1225 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1226 grep -q ^aufs /proc/modules || modprobe aufs 2>/dev/null || return
1227 mkdir ${base}root ${base}rw || return
1229 _ 'Setup aufs chroot...'
1231 # Sanity check
1232 for i in / /proc /sys /dev /dev/shm /home; do
1233 case " $AUFS_MOUNTS " in
1234 *\ $i\ *) ;;
1235 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1236 esac
1237 done
1238 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1239 mkdir -p ${base}root$mnt # for `mount -o bind`
1240 mount -o bind $mnt ${base}root$mnt # use `-o bind` instead of `--bind`
1241 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1242 _ 'Aufs mount failure'
1243 umount ${base}root
1244 rm -rf ${base}r*
1245 return
1246 fi
1247 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1248 done
1249 trap "umount_aufs ${base}" INT
1251 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1252 status=$?
1254 _ 'Leaving aufs chroot...'
1255 umount_aufs $base
1256 # Install package outside the aufs jail
1257 install_package
1258 exit $status
1259 }
1262 # Encode predefined XML entities
1264 xml_ent() {
1265 sed -e 's|&|\&|g; s|<|\<|g; s|>|\>|g; s|"|\"|g' -e "s|'|\'|g"
1266 }
1269 # Create a XML feed for freshly built packages.
1271 gen_rss() {
1272 if [ -e "$WOK/$PACKAGE/.icon.png" ]; then
1273 icon="$COOKER_URL$PACKAGE/browse/.icon.png"
1274 else
1275 icon="http://cook.slitaz.org/tazpkg.png"
1276 fi
1278 cat > $FEEDS/$pkg.xml <<EOT
1279 <item>
1280 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1281 <link>$COOKER_URL${PACKAGE//+/%2B}</link>
1282 <guid isPermaLink="false">$PACKAGE-$VERSION$EXTRAVERSION</guid>
1283 <pubDate>$(date '+%a, %d %b %Y %X GMT')</pubDate>
1284 <description><![CDATA[
1285 <table>
1286 <tr>
1287 <td vertical-align="top"><img src="$icon" alt=""/></td>
1288 <td>$(echo -n "$SHORT_DESC" | xml_ent)</td>
1289 </tr>
1290 </table>
1291 ]]></description>
1292 </item>
1293 EOT
1294 }
1297 # Truncate stdout log file to $1 Mb.
1299 loglimit() {
1300 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1301 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1302 else
1303 tee /dev/stderr
1304 fi
1305 }
1308 #
1309 # Receipt functions to ease packaging
1310 #
1312 get_dev_files() {
1313 action 'Getting standard devel files...'
1314 mkdir -p $fs/usr/lib
1315 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1316 cp -a $install/usr/lib/*a $fs/usr/lib
1317 cp -a $install/usr/include $fs/usr
1318 status
1319 }
1322 # Function to use in compile_rules() to copy man page from $src to $install
1324 cook_pick_manpages() {
1325 local name section
1326 action 'Copying man pages...'
1328 for i in $@; do
1329 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1330 section=${name##*/}; section=${section##*.}
1331 mkdir -p $install/usr/share/man/man$section
1332 scopy $i $install/usr/share/man/man$section
1333 done
1334 status
1335 }
1338 # Function to use in compile_rules() to copy documentation from $src to $install
1340 cook_pick_docs() {
1341 local docdir="$install/usr/share/doc/$PACKAGE-$VERSION"
1342 action 'Copying documentation...'
1343 mkdir -p $docdir
1344 cp -r $@ $docdir
1345 chmod -R a+r $docdir
1346 status
1347 }
1350 # Update split.db once for receipt
1352 update_split_db() {
1353 local db="$cache/split.db"
1354 touch $db
1355 sed -i "/^$pkg\t/d" $db
1356 echo -e "$pkg\t$(all_names)" >> $db
1357 }
1360 # Recreate whole split.db from scratch
1362 recreate_split_db() {
1363 # Clean
1364 local db="$cache/split.db"
1366 cd $WOK
1367 for pkg in *; do
1368 [ -f "$WOK/$pkg/receipt" ] || continue
1369 unset PACKAGE SPLIT
1370 . $WOK/$pkg/receipt
1371 echo -e "$PACKAGE\t$(all_names)"
1372 done > $db
1373 }
1376 # Recreate whole maint.db from scratch
1378 recreate_maint_db() {
1379 # Clean
1380 local db="$cache/maint.db"
1382 cd $WOK
1383 for pkg in *; do
1384 [ -f "$WOK/$pkg/receipt" ] || continue
1385 unset PACKAGE MAINTAINER
1386 . $WOK/$pkg/receipt
1387 MAINTAINER=$(echo $MAINTAINER | sed 's|.*<||; s|>.*||')
1388 echo -e "$MAINTAINER\t$PACKAGE"
1389 done | sort > $db
1390 }
1393 # Put the status to the activity log
1395 put_status() {
1396 # $1: package, $2: status, one of 'Done', 'Failed'
1397 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1398 if [ "$2" == 'Done' ]; then
1399 # overstrike all previous 'Failed' to indicate package is OK now
1400 sed -i "/>$1<\/a>/ s|\[ Failed \]|[ -Failed ]|" $activity
1401 fi
1402 }
1407 #
1408 # Commands
1409 #
1411 # cook <package> --deps
1412 [ -n "$deps" ] && {
1413 @@PREFIX@@/libexec/cookutils/deps $1
1414 exit 0
1415 }
1417 # cook <package> --clean
1418 # cook <package> -c
1419 [ -n "$clean" -o "$2" == '-c' ] && {
1420 action 'Cleaning "%s"' "$1"
1421 cd $WOK/$1; rm -rf install taz source
1422 status; newline
1423 touch $activity # update $activity -> something changed -> update webstat
1424 exit 0
1425 }
1427 # cook <package> --getsrc
1428 # cook <package> -gs
1429 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1430 pkg="$1"
1431 title 'Getting source for "%s"' "$pkg"
1432 receipt="$WOK/$pkg/receipt"
1433 check_pkg_in_wok
1434 unset_receipt
1435 . $receipt
1436 get_source
1437 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1438 exit 0
1439 }
1441 # cook <package> --block
1442 # cook <package> -b
1443 [ -n "$block" -o "$2" == '-b' ] && {
1444 action 'Blocking package "%s"' "$1"
1445 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1446 status; newline
1447 touch $activity
1448 exit 0
1449 }
1451 # cook <package> --unblock
1452 # cook <package> -ub
1453 [ -n "$unblock" -o "$2" == '-ub' ] && {
1454 action 'Unblocking package "%s"' "$1"
1455 sed -i "/^$1$/d" $blocked
1456 status; newline
1457 touch $activity
1458 exit 0
1459 }
1464 case "$1" in
1465 usage|help|-u|-h)
1466 usage ;;
1468 list-wok)
1469 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1470 cd $WOK
1471 if [ "$ARCH" != 'i486' ]; then
1472 count=0
1473 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1474 do
1475 unset HOST_ARCH
1476 . ./$pkg
1477 count=$(($count + 1))
1478 colorize 34 "$PACKAGE"
1479 done
1480 else
1481 count=$(ls | wc -l)
1482 ls -1
1483 fi
1484 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1485 ;;
1487 activity)
1488 cat $activity ;;
1490 search)
1491 # Just a simple search function, we don't need more actually.
1492 query="$2"
1493 title 'Search results for "%s"' "$query"
1494 cd $WOK; ls -1 | grep "$query"
1495 footer ;;
1497 setup)
1498 # Setup a build environment
1499 check_root
1500 _ 'Cook: setup environment' | log
1501 title 'Setting up your environment'
1502 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1503 cd $SLITAZ
1504 init_db_files
1505 _ 'Checking for packages to install...'
1506 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1507 # ARCH-setup or 'cross check' should be used before: cook setup
1508 case "$ARCH" in
1509 arm*|x86_64)
1510 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1511 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1512 . /etc/slitaz/cross.conf ;;
1513 esac
1514 for pkg in $SETUP_PKGS; do
1515 if [ -n "$forced" ]; then
1516 tazpkg -gi $pkg --forced
1517 else
1518 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1519 fi
1520 done
1522 # Handle --options
1523 case "$2" in
1524 --wok) hg clone $WOK_URL wok || exit 1 ;;
1525 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1526 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1527 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1528 esac
1530 # SliTaz group and permissions
1531 if ! grep -q ^slitaz /etc/group; then
1532 _ 'Adding group "%s"' 'slitaz'
1533 addgroup slitaz
1534 fi
1535 _ 'Setting permissions for group "%s"...' 'slitaz'
1536 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1537 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1538 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1540 *-setup)
1541 # Setup for cross compiling.
1542 arch="${1%-setup}"
1543 check_root
1544 . /etc/slitaz/cook.conf
1545 for pkg in $CROSS_SETUP; do
1546 if [ -n "$forced" ]; then
1547 tazpkg -gi $pkg --forced
1548 else
1549 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1550 fi
1551 done
1553 _ 'Cook: setup %s cross environment' "$arch" | log
1554 title 'Setting up your %s cross environment' "$arch"
1555 init_db_files
1556 sed -i \
1557 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1558 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1559 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1560 /etc/slitaz/cook.conf
1561 case "$arch" in
1562 arm)
1563 flags='-O2 -march=armv6'
1564 host="$ARCH-slitaz-linux-gnueabi" ;;
1565 armv6hf)
1566 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1567 host="$ARCH-slitaz-linux-gnueabi" ;;
1568 armv7)
1569 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1570 host="$ARCH-slitaz-linux-gnueabi" ;;
1571 x86_64)
1572 flags='-O2 -mtune=generic -pipe'
1573 host="$ARCH-slitaz-linux" ;;
1574 esac
1575 sed -i \
1576 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1577 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1578 . /etc/slitaz/cook.conf
1579 sysroot="$CROSS_TREE/sysroot"
1580 tools="/cross/$arch/tools"
1581 root="$sysroot"
1582 # L10n: keep the same width of translations to get a consistent view
1583 _ 'Target arch : %s' "$ARCH"
1584 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1585 _ 'Build flags : %s' "$flags"
1586 _ 'Arch sysroot : %s' "$sysroot"
1587 _ 'Tools prefix : %s' "$tools/bin"
1588 # Tell the packages manager where to find packages.
1589 _ 'Packages DB : %s' "$root$DB"
1590 mkdir -p $root$INSTALLED
1591 cd $root$DB; rm -f *.bak
1592 for list in packages.list packages.desc packages.equiv packages.md5; do
1593 rm -f $list
1594 ln -s $SLITAZ/packages/$list $list
1595 done
1596 # We must have the cross compiled glibc-base installed or default
1597 # i486 package will be used as dep by tazpkg and then break the
1598 # cross environment
1599 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1600 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1601 fi
1602 # Show GCC version or warn if not yet compiled.
1603 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1604 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1605 else
1606 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1607 _ 'Run "%s" to cook a toolchain' 'cross compile'
1608 fi
1609 footer ;;
1611 test)
1612 # Test a cook environment.
1613 _ 'Cook test: testing the cook environment' | log
1614 [ ! -d "$WOK" ] && exit 1
1615 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1616 cook cooktest ;;
1618 new)
1619 # Create the package folder and an empty receipt.
1620 pkg="$2"
1621 [ -z "$pkg" ] && usage
1622 newline
1623 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1625 action 'Creating folder "%s"' "$WOK/$pkg"
1626 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1628 action 'Preparing the package receipt...'
1629 cp $DATA/receipt .
1630 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1631 status; newline
1633 # Interactive mode, asking and seding.
1634 case "$3" in
1635 --interactive|-x)
1636 _ 'Entering interactive mode...'
1637 separator
1638 _ 'Package : %s' "$pkg"
1640 _n 'Version : ' ; read answer
1641 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1643 _n 'Category : ' ; read answer
1644 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1646 # L10n: Short description
1647 _n 'Short desc : ' ; read answer
1648 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1650 _n 'Maintainer : ' ; read answer
1651 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1653 _n 'License : ' ; read answer
1654 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1656 _n 'Web site : ' ; read answer
1657 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1658 newline
1660 # Wget URL.
1661 _ 'Wget URL to download source tarball.'
1662 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1663 _n 'Wget url : ' ; read answer
1664 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1666 # Ask for a stuff dir.
1667 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1668 if [ "$?" -eq 0 ]; then
1669 action 'Creating the stuff directory...'
1670 mkdir $WOK/$pkg/stuff; status
1671 fi
1673 # Ask for a description file.
1674 confirm "$(_n 'Are you going to write a description? (y/N)')"
1675 if [ "$?" -eq 0 ]; then
1676 action 'Creating the "%s" file...' 'description.txt'
1677 touch $WOK/$pkg/description.txt; status
1678 fi
1680 footer "$(_ 'Receipt is ready to use.')" ;;
1681 esac ;;
1683 list)
1684 # Cook a list of packages (better use the Cooker since it will order
1685 # packages before executing cook).
1686 check_root
1687 [ -z "$2" ] && die 'No list in argument.'
1688 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1690 _ 'Starting cooking the list "%s"' "$2" | log
1692 while read pkg; do
1693 cook $pkg || broken
1694 done < $2
1695 ;;
1697 clean-wok)
1698 check_root
1699 newline; action 'Cleaning all packages files...'
1700 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1701 status; newline ;;
1703 clean-src)
1704 check_root
1705 newline; action 'Cleaning all packages sources...'
1706 rm -rf $WOK/*/source
1707 status; newline ;;
1709 uncook)
1710 cd $WOK
1711 count=0
1712 title 'Checking for uncooked packages'
1714 for i in *; do
1715 unset HOST_ARCH EXTRAVERSION
1716 [ ! -e $i/receipt ] && continue
1717 . ./$i/receipt
1718 # Source cooked pkg receipt to get EXTRAVERSION
1719 if [ -d "$WOK/$i/taz" ]; then
1720 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
1721 . ./receipt; cd $WOK
1722 fi
1723 case "$ARCH" in
1724 i486)
1725 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1726 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1727 count=$(($count + 1))
1728 colorize 34 "$i"
1729 fi ;;
1730 arm*)
1731 # Check only packages included in arch
1732 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1733 # *.tazpkg
1734 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1735 count=$(($count + 1))
1736 colorize 34 "$i"
1737 fi
1738 fi ;;
1739 esac
1740 done
1742 if [ "$count" -gt 0 ]; then
1743 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1744 else
1745 _ 'All packages are cooked :-)'
1746 newline
1747 fi
1748 ;;
1750 pkgdb)
1751 # Create suitable packages list for TazPkg and only for built packages
1752 # as well as flavors files for TazLiTo. We don't need logs since we do it
1753 # manually to ensure everything is fine before syncing the mirror.
1754 recreate_split_db
1755 recreate_maint_db
1756 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1757 ;;
1759 splitdb)
1760 # File split.db is useful for searching for split packages.
1761 recreate_split_db
1762 ;;
1764 maintdb)
1765 # File maint.db is useful for searching maintainer's packages.
1766 recreate_maint_db
1767 ;;
1769 *)
1770 # Just cook and generate a package.
1771 check_root
1772 time=$(date +%s)
1773 pkg="$1"
1774 [ -z "$pkg" ] && usage
1776 # Search last successful cook time in all logs from newer to older
1777 for i in '' $(seq 0 9 | sed 's|^|.|'); do
1778 [ -f "$LOGS/$pkg.log$i" ] || break
1779 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1780 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
1781 [ -n "$lastcooktime" ] && break
1782 done
1784 receipt="$WOK/$pkg/receipt"
1785 check_pkg_in_wok
1786 newline
1788 unset inst
1789 unset_receipt
1790 . $receipt
1792 # Handle cross compilation.
1793 case "$ARCH" in
1794 arm*)
1795 if [ -z "$HOST_ARCH" ]; then
1796 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1797 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1798 _ 'cook: %s' "$error"
1799 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1800 _ 'Cook skip: %s' "$error" | log
1801 newline
1802 broken; exit 1
1803 fi ;;
1804 esac
1806 # Some packages are not included in some arch or fail to cross compile.
1807 : ${HOST_ARCH=$ARCH}
1808 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1809 # Handle arm{v6hf,v7,..}
1810 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1811 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1812 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1813 _ 'cook: %s' "error"
1814 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1815 _ 'Cook skip: %s' "$error" | log
1816 sed -i "/^${pkg}$/d" $broken
1817 newline
1818 exit 0
1819 fi
1821 # Remove package from broken list before cooking
1822 sed -i "/^${pkg}$/d" $broken
1824 # Skip blocked, 3 lines also for the Cooker.
1825 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1826 die 'Package "%s" is blocked' "$pkg"
1828 try_aufs_chroot "$@"
1830 # Log and source receipt.
1831 echo "cook:$pkg" > $command
1833 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1835 while read cmd duration start; do
1836 [ $(($start + $duration)) -lt $(date +%s) ] &&
1837 echo "sed -i '/^$cmd $duration/d' $cooktime"
1838 done < $cooktime | sh
1840 # Display and log info if cook process stopped.
1841 # FIXME: gettext not working (in single quotes) here!
1842 trap '_ "\n\nCook stopped: control-C\n\n" | \
1843 tee -a $LOGS/$pkg.log' INT
1845 update_split_db
1847 # Handle --options
1848 case "$2" in
1849 --pack)
1850 _ 'Packing %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1851 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
1852 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
1853 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -f $LOGS/$pkg-pack.log
1854 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
1855 @@PREFIX@@/libexec/cookutils/postcheck $pkg | tee -a $LOGS/$pkg-pack.log
1856 clean_log "$pkg-pack"
1857 time=$(($(date +%s) - $time))
1858 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
1859 gen_rss
1860 put_status $pkg Done
1861 rm -f $command
1862 exit 0 ;;
1864 --trials|-t)
1865 trials='yes' ;;
1866 esac
1868 _ 'Making %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1870 # Rotate log
1871 for i in $(seq 9 -1 1); do
1872 j=$(($i - 1))
1873 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1874 done
1875 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1877 # Check if wanted is built now so we have separate log files.
1878 for wanted in $WANTED ; do
1879 if grep -q "^$wanted$" $blocked; then
1880 broken
1881 rm -f $command
1882 die 'WANTED package "%s" is blocked' "$wanted"
1883 fi
1884 if grep -q "^$wanted$" $broken; then
1885 broken
1886 rm -f $command
1887 die 'WANTED package "%s" is broken' "$wanted"
1888 fi
1889 if [ ! -d "$WOK/$wanted/install" ]; then
1890 cook "$wanted" || { broken; exit 1; }
1891 fi
1892 done
1894 # Cook and pack or exit on error and log everything.
1895 ( ( ( (cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq) )
1896 rq=$? # the return code of `cookit $@` above command
1898 if [ $rq -eq 1 ]; then
1899 broken
1900 fi
1902 # Remove build dependencies both when `cookit` done or fail
1903 remove_deps | tee -a $LOGS/$pkg.log
1904 timestamp job27 # removing bdeps
1905 # cookit_quality
1906 timestamp job28 # checking quality
1908 # Log and stop if `cookit` fails
1909 if [ $rq -eq 1 ]; then
1910 debug_info "ret1" | tee -a $LOGS/$pkg.log
1911 @@PREFIX@@/libexec/cookutils/postcheck $pkg | tee -a $LOGS/$pkg.log
1912 put_status $pkg Failed
1913 rm -f $command
1914 broken
1915 exit 1
1916 fi
1918 # Proceed only if `cookit` return code is zero-OK
1919 # If instant-pack if specified, then packages already packed in the cookit()
1920 [ "${COOKOPTS/instant-pack/}" == "$COOKOPTS" ] &&
1921 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1922 timestamp job29 # packing
1924 @@PREFIX@@/libexec/cookutils/postcheck $pkg | tee -a $LOGS/$pkg.log
1926 clean_log
1928 # Exit if any error in packing.
1929 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
1930 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1931 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1932 debug_info "packerr" | tee -a $LOGS/$pkg.log
1933 put_status $pkg Failed
1934 rm -f $command
1935 broken; exit 1
1936 fi
1938 # Create an XML feed
1939 gen_rss
1941 # Time and summary
1942 time=$(($(date +%s) - $time))
1943 summary | tee -a $LOGS/$pkg.log
1944 newline
1946 # We may want to install/update (outside aufs jail!).
1947 [ -s /aufs-umount.sh ] || install_package
1949 put_status $pkg Done
1951 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1952 # If you want automation, use the Cooker Build Bot.
1953 rm -f $command
1954 timestamp job30 # misc. final operations
1955 store_timestats
1957 sed -n '/^Build dependencies to remove:/,/^$/p' $LOGS/$pkg.log \
1958 | sed '/^Build/d; s|Removing: ||' \
1959 | tr ' ' '\n' \
1960 | sed '/^$/d' \
1961 > $WOK/$pkg/.bdeps
1963 ;;
1964 esac
1966 exit 0