cookutils view cook @ rev 1012

Separate modules/precheck from cook (next will be modules/getsrc); cook: fix bug preventing meta-packages to be included in receipt v2; lighttpd/index.cgi: show cooker state in the title (web browser show special icon if background page title has changed).
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Nov 24 14:39:52 2017 +0200 (2017-11-24)
parents 7dc9964e94a8
children 47059b5d1648
line source
1 #!/bin/sh
2 #
3 # Cook - A tool to cook and generate SliTaz packages. Read the README
4 # before adding or modifying any code in cook!
5 #
6 # Copyright (C) SliTaz GNU/Linux - GNU GPL v3
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
10 . /usr/lib/slitaz/libcook.sh
12 VERSION="3.2"
13 export output=raw
16 # Internationalization.
18 export TEXTDOMAIN='cook'
21 #
22 # Functions
23 #
25 usage() {
26 cat <<EOT
28 $(boldify "$(_ 'Usage:')") $(_ 'cook [package|command] [list|--option]')
30 $(boldify "$(_ 'Commands:')")
31 usage|help $(_ 'Display this short usage.')
32 setup $(_ 'Setup your build environment.')
33 *-setup $(_ 'Setup a cross environment.')
34 * = {arm|armv6hf|armv7|x86_64}
35 test $(_ 'Test environment and cook a package.')
36 list-wok $(_ 'List packages in the wok.')
37 search $(_ 'Simple packages search function.')
38 new $(_ 'Create a new package with a receipt.')
39 list $(_ 'Cook a list of packages.')
40 clean-wok $(_ 'Clean-up all packages files.')
41 clean-src $(_ 'Clean-up all packages sources.')
42 uncook $(_ 'Check for uncooked packages')
43 pkgdb $(_ 'Create packages DB lists and flavors.')
45 $(boldify "$(_ 'Options:')")
46 cook <pkg>
47 --clean -c $(_ 'clean the package in the wok.')
48 --install -i $(_ 'cook and install the package.')
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 # Initialize files used in $CACHE
90 init_db_files() {
91 _ 'Creating directories structure in "%s"' "$SLITAZ"
92 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
93 _ 'Creating DB files in "%s"' "$CACHE"
94 touch $activity $command $broken $blocked $CACHE/webstat
95 chown www:www $cache/webstat
96 }
99 # Paths used in receipt and by cook itself.
101 set_paths() {
102 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
103 if [ -f "$WOK/linux/receipt" ]; then
104 kvers=$(. $WOK/linux/receipt; echo $VERSION)
105 kbasevers=$(echo $kvers | cut -d. -f1,2)
106 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
107 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
108 kbasevers=$(echo $kvers | cut -d. -f1,2)
109 fi
111 # Python version
112 [ -f "$WOK/python/receipt" ] && pyvers=$(. $WOK/python/receipt; echo $VERSION)
113 # Perl version for some packages needed it
114 [ -f "$WOK/perl/receipt" ] && perlvers=$(. $WOK/perl/receipt; echo $VERSION)
116 pkgdir="$WOK/$pkg"
117 . "$pkgdir/receipt"
118 basesrc="$pkgdir/source"
119 tmpsrc="$basesrc/tmp"
120 src="$basesrc/$PACKAGE-$VERSION"
121 taz="$pkgdir/taz"
122 pack="$taz/${1:-$PACKAGE}-$VERSION$EXTRAVERSION" # v2: multiple taz/* folders
123 fs="$pack/fs"
124 stuff="$pkgdir/stuff"
125 install="$pkgdir/install"
127 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
128 lzma_tarball="$pkgsrc.tar.lzma"
130 [ -n "$PATCH" -a -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
132 if [ -n "$WANTED" ]; then
133 basesrc="$WOK/$WANTED/source"
134 src="$basesrc/$WANTED-$VERSION"
135 install="$WOK/$WANTED/install"
136 wanted_stuff="$WOK/$WANTED/stuff"
137 fi
139 [ -n "$SOURCE" ] && source_stuff="$WOK/$SOURCE/stuff"
141 # Old way compatibility.
142 _pkg="$install"
143 }
146 # Create source tarball when URL is a SCM.
148 create_tarball() {
149 local tarball
150 tarball="$pkgsrc.tar.bz2"
151 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
152 _ 'Creating tarball "%s"' "$tarball"
153 if [ -n "$LZMA_SRC" ]; then
154 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
155 LZMA_SRC=''
156 else
157 tar -cjf $tarball $pkgsrc || exit 1
158 mv $tarball $SRC; rm -rf $pkgsrc
159 fi
160 TARBALL="$tarball"
161 }
164 # Get package source. For SCM we are in cache so clone here and create a
165 # tarball here.
167 get_source() {
168 local url
169 url=${WGET_URL#*|}
170 set_paths
171 pwd=$(pwd)
172 case "$WGET_URL" in
173 http://*|ftp://*|https://*)
174 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
175 wget -T 60 -c -O $SRC/$TARBALL $WGET_URL ||
176 wget -T 60 -c -O $SRC/$TARBALL $url ||
177 die 'ERROR: %s' "wget $WGET_URL"
178 ;;
180 hg*|mercurial*)
181 _ 'Getting source from %s...' 'Hg'
182 _ 'URL: %s' "$url"
183 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
184 if [ -n "$BRANCH" ]; then
185 _ 'Hg branch: %s' "$BRANCH"
186 hg clone $url --rev $BRANCH $pkgsrc ||
187 die 'ERROR: %s' "hg clone $url --rev $BRANCH"
188 else
189 hg clone $url $pkgsrc || die 'ERROR: %s' "hg clone $url"
190 fi
191 rm -rf $pkgsrc/.hg
192 create_tarball
193 ;;
195 git*)
196 _ 'Getting source from %s...' 'Git'
197 _ 'URL: %s' "$url"
198 cd $SRC
199 git clone $url $pkgsrc || die 'ERROR: %s' "git clone $url"
200 if [ -n "$BRANCH" ]; then
201 _ 'Git branch: %s' "$BRANCH"
202 cd $pkgsrc; git checkout $BRANCH; cd ..
203 fi
204 cd $SRC
205 create_tarball
206 ;;
208 cvs*)
209 mod=$PACKAGE
210 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
211 _ 'Getting source from %s...' 'CVS'
212 _ 'URL: %s' "$url"
213 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
214 _ 'Cloning to "%s"' "$pwd/$mod"
215 cvs -d:$url co $mod && mv $mod $pkgsrc
216 create_tarball
217 ;;
219 svn*|subversion*)
220 _ 'Getting source from %s...' 'SVN'
221 _ 'URL: %s' "$url"
222 if [ -n "$BRANCH" ]; then
223 echo t | svn co $url -r $BRANCH $pkgsrc
224 else
225 echo t | svn co $url $pkgsrc
226 fi
227 create_tarball
228 ;;
230 bzr*)
231 _ 'Getting source from %s...' 'bazaar'
232 cd $SRC
233 pkgsrc=${url#*:}
234 if [ -n "$BRANCH" ]; then
235 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
236 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
237 else
238 echo "bzr -Ossl.cert_reqs=none branch $url"
239 bzr -Ossl.cert_reqs=none branch $url
240 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
241 _ "Don't forget to add to receipt:"
242 echo -e "BRANCH=\"$BRANCH\"\n"
243 fi
244 mv $pkgsrc $pkgsrc-$BRANCH
245 pkgsrc="$pkgsrc-$BRANCH"
246 create_tarball
247 ;;
249 *)
250 broken; die 'ERROR: Unable to handle "%s"' "$WGET_URL"
251 ;;
252 esac
253 }
256 # Extract source package.
258 extract_source() {
259 if [ ! -s "$SRC/$TARBALL" ]; then
260 local url
261 url="$MIRROR_URL/sources/packages"
262 url="$url/${TARBALL:0:1}/$TARBALL"
263 _ 'Getting source from %s...' 'mirror'
264 _ 'URL: %s' "$url"
265 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
266 fi
267 _ 'Extracting source archive "%s"' "$TARBALL"
268 case "$TARBALL" in
269 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
270 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
271 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
272 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
273 *.tar) tar -xf $SRC/$TARBALL ;;
274 *.zip|*.xpi) unzip -o $SRC/$TARBALL 2>/dev/null >&2;;
275 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
276 tar -xf $SRC/$TARBALL 2>/dev/null;;
277 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
278 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
279 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
280 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
281 *) cp $SRC/$TARBALL $(pwd) ;;
282 esac
283 }
286 # Display time.
288 disp_time() {
289 local sec div min
290 sec="$1"
291 div=$(( ($1 + 30) / 60))
292 case $div in
293 0) min='';;
294 # L10n: 'm' is for minutes (approximate cooking time)
295 *) min=$(_n ' ~ %dm' "$div");;
296 esac
298 # L10n: 's' is for seconds (cooking time)
299 _ '%ds%s' "$sec" "$min"
300 }
303 # Display cooked package summary.
305 summary() {
306 set_paths
307 cd $WOK/$pkg
308 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
309 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
310 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
312 _ 'Summary for: %s' "$PACKAGE $VERSION$EXTRAVERSION"
313 separator
315 # L10n: keep the same width of translations to get a consistent view
316 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
317 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
318 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
319 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
320 _ 'Cook time : %s' "$(disp_time "$time")"
321 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
322 _ 'Host arch : %s' "$ARCH"
324 separator -
325 _ ' # : Packed : Compressed : Files : Package name'
326 separator -
327 pkgi=1
328 for i in $(all_names); do
329 fs=$(du -sh $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION | awk '{print $1}')
330 pkgname="$i-$VERSION$EXTRAVERSION.tazpkg"
331 size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
332 files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/files.list)
333 printf "%2d : %7s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
334 pkgi=$((pkgi + 1))
335 done
336 separator
337 }
340 # Display debugging error info.
342 debug_info() {
343 title 'Debug information'
344 # L10n: specify your format of date and time (to help: man date)
345 # L10n: not bad one is '+%x %R'
346 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
347 if [ -n "$time" ]; then
348 times="$(($(date +%s) - $time))"
349 _ 'Wasted time : %s' "$(disp_time "$times")"
350 fi
351 for error in \
352 ERROR 'No package' "cp: can't" "can't open" "can't cd" \
353 'error:' 'fatal error:' 'undefined reference to' \
354 'Unable to connect to' 'link: cannot find the library' \
355 'CMake Error' ': No such file or directory' \
356 'Could not read symbols: File in wrong format'
357 do
358 # format "line number:line content"
359 fgrep -n "$error" $LOGS/$pkg.log
360 done > $LOGS/$pkg.log.debug_info 2>&1
361 # sort by line number, remove duplicates
362 sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
363 rm -f $LOGS/$pkg.log.debug_info
364 footer
365 }
368 # A bit smarter function than the classic `cp` command
370 scopy() {
371 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
372 cp -a "$1" "$2" # copy generic files
373 else
374 cp -al "$1" "$2" # copy hardlinks
375 fi
376 }
379 # Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
380 # We use standard paths, so some packages need to copy these files with the
381 # receipt and genpkg_rules.
382 # This function executes inside the packaging process, before compressor call.
384 copy_generic_files() {
385 # Proceed only for "main" package (for v2), and for any packages (v1)
386 [ "$pkg" == "$PACKAGE" ] || return 0
388 # $LOCALE is set in cook.conf
389 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
390 if [ -d "$install/usr/share/locale" ]; then
391 mkdir -p "$fs/usr/share/locale"
392 for i in $LOCALE; do
393 if [ -d "$install/usr/share/locale/$i" ]; then
394 cp -r $install/usr/share/locale/$i $fs/usr/share/locale
395 fi
396 done
397 fi
398 fi
400 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
401 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
402 if [ -d "$install/usr/share/pixmaps" ]; then
403 mkdir -p "$fs/usr/share/pixmaps"
404 for i in png xpm; do
405 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
406 cp -r $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
407 done
408 fi
409 fi
411 # Desktop entry (.desktop).
412 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
413 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
414 if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
415 mkdir -p "$fs/usr/share"
416 cp -r $install/usr/share/applications $fs/usr/share
417 fi
418 fi
419 }
422 # Copy pixmaps, desktop files and licenses from $stuff to $install.
423 # This function executes after the main compile_rules() is done.
425 copy_generic_stuff() {
426 # Custom or homemade PNG pixmap can be in stuff.
427 if [ -f "$stuff/$PACKAGE.png" ]; then
428 mkdir -p $install/usr/share/pixmaps
429 cp $stuff/$PACKAGE.png $install/usr/share/pixmaps
430 fi
432 # Homemade desktop file(s) can be in stuff.
433 if [ -d "$stuff/applications" ]; then
434 mkdir -p $install/usr/share
435 cp -r $stuff/applications $install/usr/share
436 fi
437 if [ -f "$stuff/$PACKAGE.desktop" ]; then
438 mkdir -p $install/usr/share/applications
439 cp $stuff/$PACKAGE.desktop $install/usr/share/applications
440 fi
442 # Add custom licenses
443 if [ -d "$stuff/licenses" ]; then
444 mkdir -p $install/usr/share/licenses
445 cp -r $stuff/licenses $install/usr/share/licenses/$PACKAGE
446 fi
447 }
450 # Update installed.cook.diff
452 update_installed_cook_diff() {
453 # If a cook failed deps are removed.
454 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
455 cd $CACHE
456 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
457 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
458 deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
459 }
462 # Remove installed deps.
464 remove_deps() {
465 # Now remove installed build deps.
466 diff='/tmp/installed.cook.diff'
467 [ -s "$diff" ] || return
469 deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
470 nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
471 newline
472 _n 'Build dependencies to remove:'; echo " $nb"
473 [ -n "$root" ] && echo "root=\"$root\""
474 {
475 _n 'Removing:'
476 for dep in $deps; do
477 echo -n " $dep"
478 # Do not waste time uninstalling the packages if we are inside
479 # aufs chroot - unmounting chroot will "uninstall" all packages.
480 [ -s /aufs-umount.sh ] ||
481 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
482 done
483 } | busybox fold -sw80
484 newline; newline
485 # Keep the last diff for debug and info.
486 mv -f $diff $CACHE/installed.diff
487 }
490 # Automatically patch the sources.
492 patchit() {
493 [ -f "$stuff/patches/series" ] || return
495 IFS=$'\n'
496 while read i; do
497 patchname=$(echo ${i%%#*} | cut -d' ' -f1) # allow comments (anything after the # or space)
498 case $patchname in # allow patch options in form <options_no_spaces>|<file_name>
499 *\|*) patchopts="${patchname%|*}"; patchname="${patchname#*|}";;
500 *) patchopts='-Np1';;
501 esac
502 [ -n "$patchname" ] || continue # allow empty lines
503 [ -f "$src/done.$patchname" ] && continue # already applied (useful with `cook --continue`)
504 newline
505 _ 'Applying patch %s' "$patchname"
506 patch $patchopts -i $stuff/patches/$patchname | sed 's|^| |'
507 touch $src/done.$patchname
508 done < $stuff/patches/series
509 newline
510 unset IFS
511 }
514 # Check source tarball integrity.
516 check_integrity() {
517 for i in sha1 sha3 sha256 sha512 md5; do
518 I=$(echo $i | tr 'a-z' 'A-Z')
519 eval sum=\$TARBALL_$I
520 if [ -n "$sum" ]; then
521 newline
522 _ 'Checking %ssum of source tarball...' "$i"
523 echo "$sum $SRC/$TARBALL" | ${i}sum -c || exit 1
524 fi
525 done
526 newline
527 }
530 # The main cook function.
532 cookit() {
533 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
534 _ 'ERROR: Broken setup. Abort.'
535 return
536 fi
538 title 'Cook: %s' "$PACKAGE $VERSION"
539 set_paths
541 # Handle cross-tools.
542 case "$ARCH" in
543 arm*|x86_64)
544 # CROSS_COMPILE is used by at least Busybox and the kernel to set
545 # the cross-tools prefix. Sysroot is the root of our target arch
546 sysroot="$CROSS_TREE/sysroot"
547 tools="$CROSS_TREE/tools"
548 # Set root path when cross compiling. ARM tested but not x86_64
549 # When cross compiling we must install build deps in $sysroot.
550 arch="-$ARCH"
551 root="$sysroot"
552 _ '%s sysroot: %s' "$ARCH" "$sysroot"
553 _ 'Adding "%s" to PATH' "$tools/bin"
554 export PATH="$PATH:$tools/bin"
555 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
556 export CROSS_COMPILE="$HOST_SYSTEM-"
557 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
558 if [ "$ARCH" == 'x86_64' ]; then
559 export CC="$HOST_SYSTEM-gcc -m64"
560 export CXX="$HOST_SYSTEM-g++ -m64"
561 else
562 export CC="$HOST_SYSTEM-gcc"
563 export CXX="$HOST_SYSTEM-g++"
564 fi
565 export AR="$HOST_SYSTEM-ar"
566 export AS="$HOST_SYSTEM-as"
567 export RANLIB="$HOST_SYSTEM-ranlib"
568 export LD="$HOST_SYSTEM-ld"
569 export STRIP="$HOST_SYSTEM-strip"
570 export LIBTOOL="$HOST_SYSTEM-libtool"
571 ;;
572 esac
574 [ -n "$QA" ] && @@PREFIX@@/libexec/cookutils/precheck $receipt # former receipt_quality()
576 cd $pkgdir
577 [ -z "$continue" ] && rm -rf source 2>/dev/null
578 rm -rf install taz 2>/dev/null
580 # Disable -pipe if less than 512 MB free RAM.
581 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
582 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
583 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
584 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
585 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
586 fi
587 unset free
589 # Export flags and path to be used by make and receipt.
590 DESTDIR="$pkgdir/install"
591 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
592 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
593 #LDFLAGS
595 # BUILD_DEPENDS may vary depending on the ARCH
596 case "$ARCH" in
597 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
598 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
599 esac
601 # Check for build deps and handle implicit depends of *-dev packages
602 # (ex: libusb-dev :: libusb).
603 # rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
604 # touch $CACHE/installed.local $CACHE/installed.web
605 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
606 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
608 # Get the list of installed packages
609 cd $root$INSTALLED; ls > $CACHE/installed.list
611 for action in check install; do
612 for dep in $BUILD_DEPENDS; do
613 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
614 for i in $dep $implicit; do
615 # Skip if package already installed
616 [ -f "$root$INSTALLED/$i/receipt" ] && continue
618 case $action in
619 check)
620 # Search for local package or local provided-package
621 name=$(awk -F$'\t' -vpkg="$i" '{
622 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
623 }' "$PKGS/packages.info")
624 if [ -z "$name" ]; then
625 # Search for package in mirror
626 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
627 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
628 fi
629 ;;
630 install)
631 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
632 ;;
633 esac
634 done
635 done
636 done
638 # # Have we a missing build dep to cook?
639 # if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
640 # _ 'Auto cook config is set: %s' "$AUTO_COOK"
641 # cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
642 # for i in $(uniq $CACHE/missing.dep); do
643 # (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
644 # tee -a $LOGS/$PACKAGE.log.$$
645 # # programmers: next two messages are exact copy from remove_deps()
646 # togrep1=$(_n 'Build dependencies to remove:')
647 # togrep2=$(_n 'Removing:')
648 # cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
649 # fgrep $togrep1 $LOGS/$i.log && \
650 # fgrep $togrep2 $LOGS/$i.log && newline) | \
651 # tee -a $LOGS/$PACKAGE.log.$$ && break
652 # done
653 # rm -f $CACHE/missing.dep
654 # mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
655 # fi
656 #
657 # # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
658 # # is enabled and cook fails we have ERROR in log, if no auto cook we have
659 # # missing dep in cached file.
660 # lerror=$(_n 'ERROR')
661 # if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
662 # [ -s "$CACHE/missing.dep" ] && nb=$(wc -l < $CACHE/missing.dep)
663 # _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
664 # broken; exit 1
665 # fi
666 #
667 # # Install local packages: package-version$arch
668 # cd $PKGS
669 # for i in $(uniq $CACHE/installed.local); do
670 # # _ 'Installing dep (pkg/local): %s' "$i"
671 # tazpkg install $i --root=$root --local --quiet --cookmode
672 # done
673 #
674 # # Install web or cached packages (if mirror is set to $PKGS we only
675 # # use local packages).
676 # for i in $(uniq $CACHE/installed.web); do
677 # # _ 'Installing dep (web/cache): %s' "$i"
678 # tazpkg get-install $i --root=$root --local --quiet --cookmode
679 # done
681 update_installed_cook_diff
683 # Get source tarball and make sure we have source dir named:
684 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
685 # tarball if it exists.
686 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
687 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
688 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
689 LZMA_SRC=''
690 else
691 get_source || { broken; exit 1; }
692 fi
693 fi
694 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
695 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
696 if ! extract_source ; then
697 get_source
698 extract_source || { broken; exit 1; }
699 fi
700 if [ -n "$LZMA_SRC" ]; then
701 cd $pkgdir/source
702 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
703 mv tmp tmp-1; mkdir tmp
704 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
705 fi
706 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
707 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
708 fi
709 fi
711 cd $pkgdir/source/tmp
712 # Some archives are not well done and don't extract to one dir (ex lzma).
713 files=$(ls | wc -l)
714 [ "$files" -eq 1 -a -d "$(ls)" ] &&
715 mv * ../$PACKAGE-$VERSION
716 [ "$files" -eq 1 -a -f "$(ls)" ] &&
717 mkdir -p ../$PACKAGE-$VERSION &&
718 mv * ../$PACKAGE-$VERSION/$TARBALL
719 [ "$files" -gt 1 ] &&
720 mkdir -p ../$PACKAGE-$VERSION &&
721 mv * ../$PACKAGE-$VERSION
722 cd ..; rm -rf tmp
723 fi
725 # Check md5sum (or similar) for sources tarball
726 check_integrity
728 # Libtool shared libs path hack.
729 case "$ARCH" in
730 arm*) cross libhack ;;
731 esac
733 # Compiling all the sets
734 if grep -q ^compile_rules $receipt; then
735 _ 'Executing: %s' 'compile_rules'
736 echo "CFLAGS : $CFLAGS"
737 #echo "LDFLAGS : $LDFLAGS"
738 [ -d "$src" ] && cd $src
739 patchit
741 # Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
742 SETS=$(echo $SPLIT \
743 | awk '
744 BEGIN { RS = " "; FS = ":"; }
745 { print $2; }' \
746 | sort -u \
747 | tr '\n' ' ')
748 SETS=${SETS% } # normalize space
749 # Prepare specified source sets using patched sources
750 [ -n "$SETS" ] &&
751 for set in $SETS; do
752 echo "Preparing set $set" # debug
753 cp -a $src $src-$set
754 done
756 for SET in '' $SETS; do
757 # Switch to the specified source set
758 set_paths
759 local suffix=''
760 [ -n "$SET" ] && suffix="-$SET"
761 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
762 export install="$WOK/$pkg/install$suffix"
763 export DESTDIR="$install"
765 if [ -n "$SETS" ]; then
766 if [ -n "$SET" ]; then
767 title "Switching to the set '$SET'"
768 else
769 title "Switching to the default set"
770 fi
771 echo "src : $src"
772 echo "install: $install"
773 fi
774 cd $src
775 echo
777 [ -d "$install" ] && rm -r $install
778 mkdir -p $install
780 compile_rules $@ || { broken; exit 1; }
782 # Stay compatible with _pkg
783 [ -d "$src/_pkg" ] && mv $src/_pkg $install
785 copy_generic_stuff
787 # Actions to do after compiling the package
788 # Skip all for split packages (already done in main package)
789 if [ -z "$WANTED" ]; then
790 footer
791 export COOKOPTS ARCH install
792 @@PREFIX@@/libexec/cookutils/compressor install
793 fi
794 done
795 fi
796 footer
798 # Execute testsuite.
799 if grep -q ^testsuite $receipt; then
800 title 'Running testsuite'
801 testsuite $@ || { broken; exit 1; }
802 footer
803 fi
805 update_installed_cook_diff force
806 }
809 # Cook quality assurance.
811 cookit_quality() {
812 while true; do
813 [ ! -d "$WOK/$pkg/install" -a -z "$WANTED" ] || break
814 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
815 [ "$trials" == 'yes' ] || break
816 title "Interactive mode"
817 # TODO: allow commands:
818 # q - quit; v - edit receipt here using vi;
819 # s - search for package containing package;
820 # <package name> - install package; [Enter] - retry
821 _ 'You may install the packages here and/or edit the receipt there.'
822 newline
823 while true; do
824 _n 'Install the package? [name/N] '; read answer
825 [ -n "$answer" ] || break
826 tazpkg -gi $answer --root=$root --local --quiet --cookmode
827 done
828 newline
829 _n 'Try again? [Y/n] '; read answer
830 [ "$answer" == 'n' ] && break
831 # here you may append log if you want (">>" instead of last ">")
832 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
833 done
835 [ "${COOKOPTS/skip-log-errors/}" != "$COOKOPTS" ] && return 0
837 # ERROR can be echoed any time in cookit()
838 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
839 grep -Eq "(^ERROR|undefined reference to)" ; then
840 debug_info | tee -a $LOGS/$pkg.log
841 put_status $pkg Failed
842 rm -f $command
843 broken; exit 1
844 fi
845 }
848 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
849 # but it doesn't handle EXTRAVERSION.
851 packit() {
852 set_paths "$1"
853 PACKAGE="${1:-$PACKAGE}"
855 # Handle cross compilation
856 case "$ARCH" in
857 arm*|x86_64) arch="-$ARCH" ;;
858 esac
860 title 'Pack: %s' "$PACKAGE $VERSION$arch"
862 if grep -q ^genpkg_rules $receipt; then
863 _ 'Executing: %s' 'genpkg_rules'
864 set -e; cd $pkgdir; mkdir -p $fs
865 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
866 $LOGS/$pkg.log
867 else
868 _ 'No packages rules: meta package'
869 mkdir -p $fs
870 fi
872 # Check CONFIG_FILES
873 if [ -n "$CONFIG_FILES" ]; then
874 unset IFS
875 for i in $CONFIG_FILES; do
876 if [ ! -e $fs$i ]; then
877 case $i in
878 */) mkdir -p $fs$i ;;
879 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
880 esac
881 fi
882 done
883 fi
885 # First QA check to stop now if genpkg_rules failed.
886 lerror=$(_n 'ERROR')
887 if fgrep -q ^$lerror $LOGS/$pkg.log; then
888 broken; exit 1
889 fi
891 cd $taz
892 action 'Copying "%s"...' 'receipt'
893 export PACKAGE DEPENDS PROVIDE SUGGESTED TAZPANEL_DAEMON TAGS CAT
894 @@PREFIX@@/libexec/cookutils/mk_pkg_receipt "$(realpath ../receipt)" > $pack/receipt
895 chown 0.0 $pack/receipt; status
897 unset desc
898 [ "$pkg" == "$PACKAGE" -a -f "../description.txt" ] && desc="../description.txt"
899 [ -f "../description.$PACKAGE.txt" ] && desc="../description.$PACKAGE.txt"
900 if [ -n "$desc" ]; then
901 action 'Copying "%s"...' "$(basename "$desc")"
902 cp -f $desc $pack/description.txt; chown 0.0 $pack/description.txt; status
903 fi
905 copy_generic_files
907 # Strip and stuff files.
908 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
910 # Create files.list with redirecting find output.
911 action 'Creating the list of files...'
912 cd $fs
913 find . -type f -print > ../files.list
914 find . -type l -print >> ../files.list
915 cd ..; sed -i 's|^.||' files.list
916 status
918 # Md5sum of files.
919 action 'Creating md5sum of files...'
920 while read file; do
921 [ -L "fs$file" ] && continue
922 [ -f "fs$file" ] || continue
923 case "$file" in
924 /lib/modules/*/modules.*|*.pyc) continue ;;
925 esac
926 md5sum "fs$file" | sed 's| fs| |'
927 done < files.list | sort -k2 > md5sum
928 status
930 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
931 2>/dev/null | awk 'END{ print $1 }')
933 # Build cpio archive.
934 action 'Compressing the FS...'
935 find fs -newer $receipt -exec touch -hr $receipt '{}' \;
936 find fs | cpio -o -H newc --quiet | lzma-alone e fs.cpio.lzma -si
937 # find fs | cpio -o -H newc --quiet | /bin/lzma -zeT0 -vv >fs.cpio.lzma
938 mv fs ../
939 status
941 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
942 2>/dev/null | awk 'END{ print $1 }')
944 action 'Updating receipt sizes...'
945 sed -i '/^PACKED_SIZE=/d; /^UNPACKED_SIZE=/d' receipt
946 sed -i "s|^PACKAGE=|PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=|" receipt
947 status
949 # Set extra version.
950 if [ -n "$EXTRAVERSION" ]; then
951 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
952 sed -i '/^EXTRAVERSION=/d' receipt
953 sed -i "s|^VERSION=|EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=|" receipt
954 status
955 fi
957 # Compress.
958 action 'Creating full cpio archive...'
959 find . -newer $receipt -exec touch -hr $receipt '{}' \;
960 find . | cpio -o -H newc --quiet > ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
961 status
963 # Restoring original package tree.
964 mv ../fs .
966 rm fs.cpio.lzma; cd ..
968 # QA and give info.
969 tazpkg=$(ls *.tazpkg)
970 packit_quality
971 footer "$(_ 'Package "%s" created' "$tazpkg")"
972 update_packages_db
973 }
976 # Calculate release checksum: usually it does not change on "just recook".
977 # Release checksum is md5sum of file containing md5sums of:
978 # a) all files, b) receipt, and c) description.txt.
979 # Md5sum of the package file will change every time because of embedded timestamps;
980 # release checksum based only on files content, and will change only when files change.
981 # (Pitfall: ownership and permissions...)
983 release_checksum() {
984 local pack=$1
985 local rsum_file=$(mktemp)
987 cp $pack/md5sum $rsum_file
988 md5sum $pack/receipt | sed 's| [^ ]*/| |' >> $rsum_file
989 [ -e "$pack/description.txt" ] &&
990 md5sum $pack/description.txt | sed 's| [^ ]*/| |' >> $rsum_file
992 local rsum=$(md5sum $rsum_file | awk '{print $1}')
993 rm $rsum_file
994 local rsumold=$(awk -F$'\t' -vpkg="$PACKAGE" '
995 {if ($1 == pkg) { print $9; exit; }}' $PKGS/packages.info)
997 [ "$rsum" == "$rsumold" ] && rsum=''
999 echo $rsum
1003 # Verify package quality and consistency.
1005 packit_quality() {
1006 #action 'QA: checking for broken link...'
1007 #link=$(find $fs/usr -type l -follow)
1008 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
1009 #status
1011 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ]; then
1012 # Exit if any error found in log file.
1013 if fgrep -q ^ERROR $LOGS/$pkg.log; then
1014 rm -f $command
1015 broken; exit 1
1016 fi
1017 fi
1019 [ -n "$CAT" ] && CATEGORY="${CAT%|*}" # allow meta-packages in v2 receipts
1021 if [ "${COOKOPTS/empty-pkg/}" == "$COOKOPTS" ]; then
1022 action 'QA: checking for empty package...'
1023 if [ ! -s "$pack/files.list" -a "$CATEGORY" != 'meta' ]; then
1024 broken
1025 rm -f $command
1026 false; status
1027 die 'ERROR: empty package'
1028 fi
1029 :; status
1030 fi
1033 # Find and remove old package(s) only if "release checksum" has changed
1034 rsum=$(release_checksum $pack)
1035 if [ -n "$rsum" ]; then
1036 old_file=$(awk -F$'\t' -vname="$PACKAGE" '{
1037 if ($1 == name) printf("%s-%s.tazpkg", $1, $2);
1038 }' $PKGS/packages.info)
1039 if [ -f "$PKGS/$old_file" ]; then
1040 action 'Removing old package "%s"' "$old_file"
1041 rm -f "$PKGS/$old_file"
1042 status
1043 fi
1044 # package changed, substitute old package by new
1045 mv -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg $PKGS
1046 else
1047 # package not changed, remove new package
1048 rm -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1049 fi
1051 sed -i "/^${pkg}$/d" $broken
1052 #action 'Removing source tree...'
1053 #rm -f $WOK/$pkg/source; status
1057 # Return all the names of packages bundled in this receipt
1059 all_names() {
1060 # Get package names from $SPLIT variable
1061 local split=$(echo $SPLIT \
1062 | awk '
1063 BEGIN { RS = " "; FS = ":"; }
1064 { print $1; }' \
1065 | tr '\n' ' ')
1066 local split_space=" $split "
1067 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
1068 # For receipts v1: $SPLIT may present in the $WANTED package,
1069 # but split packages have their own receipts
1070 echo $PACKAGE
1071 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
1072 # $PACKAGE included somewhere in $SPLIT (probably in the end).
1073 # We should build packages in the order defined in the $SPLIT.
1074 echo $split
1075 else
1076 # We'll build the $PACKAGE, then all defined in the $SPLIT.
1077 echo $PACKAGE $split
1078 fi
1082 # v2: pack all packages using compiled files
1084 packall() {
1085 set_paths
1086 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1087 for i in $(all_names); do
1088 unset TAGS DEPENDS CAT CONFIG_FILES PROVIDE SUGGESTED DATABASE_FILES TAZPANEL_DAEMON
1089 packit $i
1090 done
1091 else
1092 packit
1093 fi
1097 # Reverse "cat" command: prints input lines in the reverse order
1099 tac() {
1100 sed '1!G;h;$!d' $1
1104 # Update chroot with freshly rebuilt package: keep env up-to-date.
1106 update_chroot() {
1107 local PACKAGE="$pkg"
1108 for i in $(all_names); do
1109 if [ -d "$root$INSTALLED/$i" ]; then
1110 . /etc/slitaz/cook.conf
1111 . $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt
1112 _ 'Updating %s chroot environment...' "$ARCH"
1113 _ 'Updating chroot: %s' "$i ($VERSION$EXTRAVERSION$arch)" | log
1114 cd $PKGS
1115 tazpkg install $i-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1116 fi
1117 done
1121 # Install package on --inst or update the chroot.
1123 install_package() {
1124 set_paths
1125 case "$ARCH" in
1126 arm*|x86_64)
1127 arch="-$ARCH"
1128 root="$CROSS_TREE/sysroot" ;;
1129 esac
1130 # Install package if requested but skip install if target host doesn't
1131 # match build system or it will break the build chroot.
1132 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1133 if [ -n "$inst" -a "$build" == "$ARCH" ]; then
1134 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1135 cd $PKGS
1136 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1137 else
1138 broken
1139 die 'Unable to install package, build has failed.'
1140 fi
1141 fi
1143 update_chroot
1147 # remove chroot jail
1149 umount_aufs() {
1150 tac ${1}rw/aufs-umount.sh | sh
1151 rm -rf ${1}rw
1152 umount ${1}root
1153 rmdir ${1}r*
1157 # Launch the cook command into a chroot jail protected by aufs.
1158 # The current filesystems are used read-only and updates are
1159 # stored in a separate branch.
1161 try_aufs_chroot() {
1163 base="/dev/shm/aufsmnt$$"
1165 # Can we setup the chroot? Is it already done?
1166 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1167 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1168 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1169 grep -q ^aufs /proc/modules || modprobe aufs 2> /dev/null || return
1170 mkdir ${base}root ${base}rw || return
1172 _ 'Setup aufs chroot...'
1174 # Sanity check
1175 for i in / /proc /sys /dev/shm /home ; do
1176 case " $AUFS_MOUNTS " in
1177 *\ $i\ *) ;;
1178 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1179 esac
1180 done
1181 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1182 mount --bind $mnt ${base}root$mnt
1183 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1184 _ 'Aufs mount failure'
1185 umount ${base}root
1186 rm -rf ${base}r*
1187 return
1188 fi
1189 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1190 done
1191 trap "umount_aufs ${base}" INT
1193 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1194 status=$?
1196 _ 'Leaving aufs chroot...'
1197 umount_aufs $base
1198 # Install package outside the aufs jail
1199 install_package
1200 exit $status
1204 # Encode predefined XML entities
1206 xml_ent() {
1207 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1211 # Create a XML feed for freshly built packages.
1213 gen_rss() {
1214 pubdate=$(date '+%a, %d %b %Y %X')
1215 cat > $FEEDS/$pkg.xml <<EOT
1216 <item>
1217 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1218 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1219 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1220 <pubDate>$pubdate</pubDate>
1221 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1222 </item>
1223 EOT
1227 # Truncate stdout log file to $1 Mb.
1229 loglimit() {
1230 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1231 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1232 else
1233 tee /dev/stderr
1234 fi
1239 # Receipt functions to ease packaging
1242 get_dev_files() {
1243 action 'Getting standard devel files...'
1244 mkdir -p $fs/usr/lib
1245 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1246 cp -a $install/usr/lib/*a $fs/usr/lib
1247 cp -a $install/usr/include $fs/usr
1248 status
1252 # Function to use in compile_rules() to copy man page from $src to $install
1254 cook_pick_manpages() {
1255 local name section
1256 action 'Copying man pages...'
1258 for i in $@; do
1259 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1260 section=${name##*/}; section=${section##*.}
1261 mkdir -p $install/usr/share/man/man$section
1262 scopy $i $install/usr/share/man/man$section
1263 done
1264 status
1268 # Function to use in compile_rules() to copy documentation from $src to $install
1270 cook_pick_docs() {
1271 local docdir="$install/usr/share/doc/$PACKAGE-$VERSION"
1272 action 'Copying documentation...'
1273 mkdir -p $docdir
1274 cp -r $@ $docdir
1275 chmod -R a+r $docdir
1276 status
1280 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1282 cook_copy_files() {
1283 action 'Copying files...'
1284 cd $install
1285 local i j
1286 IFS=$'\n'
1287 for i in $@; do
1288 for j in $(find . -name $i ! -type d); do
1289 mkdir -p $fs$(dirname ${j#.})
1290 scopy $j $fs$(dirname ${j#.})
1291 done
1292 done
1293 cd - >/dev/null
1294 status
1298 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1300 cook_copy_folders() {
1301 action 'Copying folders...'
1302 cd $install
1303 local i j
1304 IFS=$'\n'
1305 for i in $@; do
1306 for j in $(find . -name $i -type d); do
1307 mkdir -p $fs$(dirname ${j#.})
1308 cp -a $j $fs$(dirname ${j#.})
1309 done
1310 done
1311 cd - >/dev/null
1312 status
1316 # Remove from current $fs files that are already packed (for receipts v2).
1317 # Note: the order in $SPLIT is very important.
1318 # Note 2: working in the current set.
1320 remove_already_packed() {
1321 local i j
1322 neighbors=$(
1323 echo $SPLIT" " \
1324 | awk -F$'\t' -vpkg="$PACKAGE" '
1325 BEGIN { RS = " "; FS = ":"; }
1326 { set[$1] = $2; }
1327 END {
1328 current_set = set[pkg];
1329 for (i in set)
1330 { if (i != pkg && set[i] == current_set) print i; }
1332 ')
1333 IFS=$'\n'
1334 for neighbor in $neighbors; do
1335 i="$taz/$neighbor-$VERSION$EXTRAVERSION/files.list"
1336 [ -e "$i" ] || continue
1337 while read j; do
1338 [ -f $fs$j -o -h $fs$j ] || continue
1339 rm $fs$j
1340 rmdir --parents --ignore-fail-on-non-empty $fs$(dirname $j)
1341 done < $i
1342 done
1343 unset IFS
1347 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1348 # (default: 16 and 48) from $install to $fs
1350 cook_copy_icons() {
1351 local sizes=$@ i j
1352 action 'Copying hicolor icons...'
1353 [ -d "$fs/usr/share/icons/hicolor" ] && rm -rf "$fs/usr/share/icons/hicolor"
1354 mkdir -p $fs/usr/share/icons/hicolor
1355 for i in ${sizes:-16 48}; do
1356 j="${i}x$i"; [ "$i" == 'scalable' ] && j="$i"
1357 [ ! -e "$install/usr/share/icons/hicolor/$j" ] ||
1358 scopy $install/usr/share/icons/hicolor/$j \
1359 $fs/usr/share/icons/hicolor
1360 done
1361 status
1365 # Common function to copy files, folders and patterns
1367 copy() {
1368 action 'Copying folders and files...'
1369 local i j k filelist=$(mktemp) folderlist=$(mktemp)
1371 # Get set name for specified package from $SPLIT variable
1372 local set=$(echo $SPLIT \
1373 | awk -vpkg="$PACKAGE" '
1374 BEGIN { RS = " "; FS = ":"; }
1375 { if ($1 == pkg && $2) { print "-" $2; exit; } }')
1376 # Change set, make filelist and folderlist for new set
1377 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$set"
1378 export install="$WOK/$pkg/install$set"
1379 export DESTDIR="$install"
1380 IFS=$'\n'
1381 cd $install
1382 find ! -type d | sed 's|\.||' > $filelist
1383 find -type d | sed 's|\.||' > $folderlist
1385 for i in $@; do
1386 case $i in
1387 @std)
1388 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1389 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /\.pri$/d; /bin\/.*-config$/d;
1390 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1391 /\/Makefile.*/d; /\.inc$/d; /\/include\//d;
1392 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1393 /\/share\/devhelp\//d; /\/share\/locale\//d;
1394 /\/share\/bash-completion\//d; /\/lib\/systemd\//d;
1395 /\/fonts\.scale$/d; /\/fonts\.dir$/d;
1396 /\/share\/appdata\//d; /\/share\/help\//d;
1397 /\/share\/icons\/hicolor\/[12356][1245][268]*x[12356][1245][268]*\//d; # 22, 24, 32, 64, 128, 256, 512
1398 ' $filelist
1399 ;;
1400 @dev)
1401 # Copy "developer files"
1402 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.la$/p; /\.pc$/p; /\.pri$/p; /bin\/.*-config$/p;
1403 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1404 /\/Makefile.*/p; /\.inc$/p; /\/include\//p;
1405 ' $filelist
1406 ;;
1407 @rm)
1408 # Quick alias
1409 remove_already_packed
1410 ;;
1411 @ico)
1412 # Quick alias
1413 cook_copy_icons >/dev/null
1414 ;;
1415 */)
1416 # Copy specified folders.
1417 i="${i%/}"
1418 find -type d -path "*/${i#/}" | sed 's|^.||'
1419 ;;
1420 *)
1421 # Copy specified files.
1422 find ! -type d -path "*/${i#/}" | sed 's|^.||'
1423 ;;
1424 esac \
1425 | sort -u \
1426 | while read j; do
1427 mkdir -p $fs$(dirname "$j")
1428 if [ -d "$install$j" ]; then
1429 cp -a "$install$j" $fs$(dirname "$j")
1430 else
1431 scopy "$install$j" $fs$(dirname "$j")
1432 fi
1433 done
1434 # Copy empty directories
1435 case $i in
1436 @std)
1437 while read j; do
1438 case $j in
1439 # always skip empty man & doc folders, because this will end up
1440 # copying all the man pages and docs to the package
1441 */man/*|*/doc/*) continue;;
1442 esac
1443 [ -z "$(ls -A "$install$j")" ] || continue
1444 # directory $j is empty
1445 k="$j"
1446 # make 'ladder' from directories, from root dir to $j
1447 # /a /a/b /a/b/c etc.
1448 while :; do
1449 [ -z "$k" ] && break
1450 echo "$k"
1451 k="${k%/*}"
1452 done \
1453 | tac \
1454 | while read k; do
1455 # copy dir with its original ownership/permissions if it does not exist
1456 [ -d "$fs$k" ] || cp -a "$install$k" "$fs$k"
1457 done
1458 done < $folderlist
1459 ;;
1460 esac
1461 done
1462 cd - >/dev/null
1463 unset IFS
1464 rm $filelist $folderlist
1465 status
1469 # Update packages database every time after successful build
1471 update_packages_db() {
1472 # packages.info (unsorted, located near to packages)
1473 local pi="$PKGS/packages.info"
1474 unset_receipt; . $pack/receipt
1475 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1477 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1479 rsum=$(release_checksum $pack)
1480 if [ -n "$rsum" ]; then
1481 _ 'The release checksum has changed.\n'
1483 sed -i "/^$PACKAGE\t/d" $pi # remove old entry
1484 cat >> $pi <<EOT
1485 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $rsum $PROVIDE
1486 EOT
1488 # files.list (uncompressed, unsorted, located in $cache)
1489 local fl="$cache/files.list"
1490 touch $fl
1491 sed -i "/^$PACKAGE: /d" $fl
1492 sed "s/^/$PACKAGE: \0/" $pack/files.list >> $fl
1493 else
1494 _ 'The release checksum has not changed.\n'
1495 fi
1499 # Update split.db once for receipt
1501 update_split_db() {
1502 local db="$cache/split.db"
1503 touch $db
1504 sed -i "/^$pkg\t/d" $db
1505 echo -e "$pkg\t$(all_names)" >> $db
1509 # Recreate whole split.db from scratch
1511 recreate_split_db() {
1512 # Clean
1513 local db="$cache/split.db"
1514 touch $db
1515 > $db
1517 cd $WOK
1518 for pkg in *; do
1519 [ -f "$WOK/$pkg/receipt" ] || continue
1520 unset PACKAGE SPLIT
1521 . $WOK/$pkg/receipt
1522 echo -e "$PACKAGE\t$(all_names)" >> $db
1523 done
1527 # Put the status to the activity log
1529 put_status() {
1530 # $1: package, $2: status, one of 'Done', 'Failed'
1531 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1538 # Commands
1541 # cook <package> --deps
1542 [ -n "$deps" ] && {
1543 @@PREFIX@@/libexec/cookutils/deps $1
1544 exit 0
1547 # cook <package> --clean
1548 # cook <package> -c
1549 [ -n "$clean" -o "$2" == '-c' ] && {
1550 action 'Cleaning "%s"' "$1"
1551 cd $WOK/$1; rm -rf install taz source
1552 status; newline
1553 touch $activity # update $activity -> something changed -> update webstat
1554 exit 0
1557 # cook <package> --getsrc
1558 # cook <package> -gs
1559 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1560 title 'Getting source for "%s"' "$1"
1561 receipt="$WOK/$pkg/receipt"
1562 check_pkg_in_wok
1563 unset_receipt
1564 . $receipt
1565 get_source
1566 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1567 exit 0
1570 # cook <package> --block
1571 # cook <package> -b
1572 [ -n "$block" -o "$2" == '-b' ] && {
1573 action 'Blocking package "%s"' "$1"
1574 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1575 status; newline
1576 touch $activity
1577 exit 0
1580 # cook <package> --unblock
1581 # cook <package> -ub
1582 [ -n "$unblock" -o "$2" == '-ub' ] && {
1583 action 'Unblocking package "%s"' "$1"
1584 sed -i "/^$1$/d" $blocked
1585 status; newline
1586 touch $activity
1587 exit 0
1593 case "$1" in
1594 usage|help|-u|-h)
1595 usage ;;
1597 list-wok)
1598 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1599 cd $WOK
1600 if [ "$ARCH" != 'i486' ]; then
1601 count=0
1602 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1603 do
1604 unset HOST_ARCH
1605 . ./$pkg
1606 count=$(($count + 1))
1607 colorize 34 "$PACKAGE"
1608 done
1609 else
1610 count=$(ls | wc -l)
1611 ls -1
1612 fi
1613 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1614 ;;
1616 activity)
1617 cat $activity ;;
1619 search)
1620 # Just a simple search function, we don't need more actually.
1621 query="$2"
1622 title 'Search results for "%s"' "$query"
1623 cd $WOK; ls -1 | grep "$query"
1624 footer ;;
1626 setup)
1627 # Setup a build environment
1628 check_root
1629 _ 'Cook: setup environment' | log
1630 title 'Setting up your environment'
1631 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1632 cd $SLITAZ
1633 init_db_files
1634 _ 'Checking for packages to install...'
1635 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1636 # ARCH-setup or 'cross check' should be used before: cook setup
1637 case "$ARCH" in
1638 arm*|x86_64)
1639 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1640 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1641 . /etc/slitaz/cross.conf ;;
1642 esac
1643 for pkg in $SETUP_PKGS; do
1644 if [ -n "$forced" ]; then
1645 tazpkg -gi $pkg --forced
1646 else
1647 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1648 fi
1649 done
1651 # Handle --options
1652 case "$2" in
1653 --wok) hg clone $WOK_URL wok || exit 1 ;;
1654 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1655 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1656 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1657 esac
1659 # SliTaz group and permissions
1660 if ! grep -q ^slitaz /etc/group; then
1661 _ 'Adding group "%s"' 'slitaz'
1662 addgroup slitaz
1663 fi
1664 _ 'Setting permissions for group "%s"...' 'slitaz'
1665 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1666 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1667 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1669 *-setup)
1670 # Setup for cross compiling.
1671 arch="${1%-setup}"
1672 check_root
1673 . /etc/slitaz/cook.conf
1674 for pkg in $CROSS_SETUP; do
1675 if [ -n "$forced" ]; then
1676 tazpkg -gi $pkg --forced
1677 else
1678 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1679 fi
1680 done
1682 _ 'Cook: setup %s cross environment' "$arch" | log
1683 title 'Setting up your %s cross environment' "$arch"
1684 init_db_files
1685 sed -i \
1686 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1687 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1688 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1689 /etc/slitaz/cook.conf
1690 case "$arch" in
1691 arm)
1692 flags='-O2 -march=armv6'
1693 host="$ARCH-slitaz-linux-gnueabi" ;;
1694 armv6hf)
1695 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1696 host="$ARCH-slitaz-linux-gnueabi" ;;
1697 armv7)
1698 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1699 host="$ARCH-slitaz-linux-gnueabi" ;;
1700 x86_64)
1701 flags='-O2 -mtune=generic -pipe'
1702 host="$ARCH-slitaz-linux" ;;
1703 esac
1704 sed -i \
1705 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1706 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1707 . /etc/slitaz/cook.conf
1708 sysroot="$CROSS_TREE/sysroot"
1709 tools="/cross/$arch/tools"
1710 root="$sysroot"
1711 # L10n: keep the same width of translations to get a consistent view
1712 _ 'Target arch : %s' "$ARCH"
1713 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1714 _ 'Build flags : %s' "$flags"
1715 _ 'Arch sysroot : %s' "$sysroot"
1716 _ 'Tools prefix : %s' "$tools/bin"
1717 # Tell the packages manager where to find packages.
1718 _ 'Packages DB : %s' "$root$DB"
1719 mkdir -p $root$INSTALLED
1720 cd $root$DB; rm -f *.bak
1721 for list in packages.list packages.desc packages.equiv packages.md5; do
1722 rm -f $list
1723 ln -s $SLITAZ/packages/$list $list
1724 done
1725 # We must have the cross compiled glibc-base installed or default
1726 # i486 package will be used as dep by tazpkg and then break the
1727 # cross environment
1728 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1729 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1730 fi
1731 # Show GCC version or warn if not yet compiled.
1732 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1733 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1734 else
1735 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1736 _ 'Run "%s" to cook a toolchain' 'cross compile'
1737 fi
1738 footer ;;
1740 test)
1741 # Test a cook environment.
1742 _ 'Cook test: testing the cook environment' | log
1743 [ ! -d "$WOK" ] && exit 1
1744 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1745 cook cooktest ;;
1747 new)
1748 # Create the package folder and an empty receipt.
1749 pkg="$2"
1750 [ -z "$pkg" ] && usage
1751 newline
1752 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1754 action 'Creating folder "%s"' "$WOK/$pkg"
1755 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1757 action 'Preparing the package receipt...'
1758 cp $DATA/receipt .
1759 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1760 status; newline
1762 # Interactive mode, asking and seding.
1763 case "$3" in
1764 --interactive|-x)
1765 _ 'Entering interactive mode...'
1766 separator
1767 _ 'Package : %s' "$pkg"
1769 _n 'Version : ' ; read answer
1770 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1772 _n 'Category : ' ; read answer
1773 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1775 # L10n: Short description
1776 _n 'Short desc : ' ; read answer
1777 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1779 _n 'Maintainer : ' ; read answer
1780 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1782 _n 'License : ' ; read answer
1783 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1785 _n 'Web site : ' ; read answer
1786 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1787 newline
1789 # Wget URL.
1790 _ 'Wget URL to download source tarball.'
1791 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1792 _n 'Wget url : ' ; read answer
1793 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1795 # Ask for a stuff dir.
1796 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1797 if [ "$?" -eq 0 ]; then
1798 action 'Creating the stuff directory...'
1799 mkdir $WOK/$pkg/stuff; status
1800 fi
1802 # Ask for a description file.
1803 confirm "$(_n 'Are you going to write a description? (y/N)')"
1804 if [ "$?" -eq 0 ]; then
1805 action 'Creating the "%s" file...' 'description.txt'
1806 touch $WOK/$pkg/description.txt; status
1807 fi
1809 footer "$(_ 'Receipt is ready to use.')" ;;
1810 esac ;;
1812 list)
1813 # Cook a list of packages (better use the Cooker since it will order
1814 # packages before executing cook).
1815 check_root
1816 [ -z "$2" ] && die 'No list in argument.'
1817 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1819 _ 'Starting cooking the list "%s"' "$2" | log
1821 while read pkg; do
1822 cook $pkg || broken
1823 done < $2
1824 ;;
1826 clean-wok)
1827 check_root
1828 newline; action 'Cleaning all packages files...'
1829 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1830 status; newline ;;
1832 clean-src)
1833 check_root
1834 newline; action 'Cleaning all packages sources...'
1835 rm -rf $WOK/*/source
1836 status; newline ;;
1838 uncook)
1839 cd $WOK
1840 count=0
1841 title 'Checking for uncooked packages'
1843 for i in *; do
1844 unset HOST_ARCH EXTRAVERSION
1845 [ ! -e $i/receipt ] && continue
1846 . ./$i/receipt
1847 # Source cooked pkg receipt to get EXTRAVERSION
1848 if [ -d "$WOK/$i/taz" ]; then
1849 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
1850 . ./receipt; cd $WOK
1851 fi
1852 case "$ARCH" in
1853 i486)
1854 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1855 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1856 count=$(($count + 1))
1857 colorize 34 "$i"
1858 fi ;;
1859 arm*)
1860 # Check only packages included in arch
1861 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1862 # *.tazpkg
1863 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1864 count=$(($count + 1))
1865 colorize 34 "$i"
1866 fi
1867 fi ;;
1868 esac
1869 done
1871 if [ "$count" -gt 0 ]; then
1872 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1873 else
1874 _ 'All packages are cooked :-)'
1875 newline
1876 fi
1877 ;;
1879 pkgdb)
1880 # Create suitable packages list for TazPkg and only for built packages
1881 # as well as flavors files for TazLiTo. We don't need logs since we do it
1882 # manually to ensure everything is fine before syncing the mirror.
1883 recreate_split_db
1884 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1885 ;;
1887 splitdb)
1888 # File split.db is useful for searching for split packages.
1889 recreate_split_db
1890 ;;
1892 *)
1893 # Just cook and generate a package.
1894 check_root
1895 time=$(date +%s)
1896 pkg="$1"
1897 [ -z "$pkg" ] && usage
1899 # Search last successful cook time in all logs from newer to older
1900 for i in '' $(seq 0 9 | sed 's|^|.|'); do
1901 [ -f "$LOGS/$pkg.log$i" ] || break
1902 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1903 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
1904 [ -n "$lastcooktime" ] && break
1905 done
1907 receipt="$WOK/$pkg/receipt"
1908 check_pkg_in_wok
1909 newline
1911 unset inst
1912 unset_receipt
1913 . $receipt
1915 # Handle cross compilation.
1916 case "$ARCH" in
1917 arm*)
1918 if [ -z "$HOST_ARCH" ]; then
1919 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1920 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1921 _ 'cook: %s' "$error"
1922 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1923 _ 'Cook skip: %s' "$error" | log
1924 newline
1925 broken; exit 1
1926 fi ;;
1927 esac
1929 # Some packages are not included in some arch or fail to cross compile.
1930 : ${HOST_ARCH=i486}
1931 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1932 # Handle arm{v6hf,v7,..}
1933 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1934 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1935 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1936 _ 'cook: %s' "error"
1937 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1938 _ 'Cook skip: %s' "$error" | log
1939 sed -i "/^${pkg}$/d" $broken
1940 newline
1941 exit 0
1942 fi
1944 # Skip blocked, 3 lines also for the Cooker.
1945 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1946 die 'Package "%s" is blocked' "$pkg"
1948 try_aufs_chroot "$@"
1950 # Log and source receipt.
1951 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1952 echo "cook:$pkg" > $command
1954 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1956 while read cmd duration start; do
1957 [ $(($start + $duration)) -lt $(date +%s) ] &&
1958 echo "sed -i '/^$cmd $duration/d' $cooktime"
1959 done < $cooktime | sh
1961 # Display and log info if cook process stopped.
1962 # FIXME: gettext not working (in single quotes) here!
1963 trap '_ "\n\nCook stopped: control-C\n\n" | \
1964 tee -a $LOGS/$pkg.log' INT
1966 update_split_db
1968 # Handle --options
1969 case "$2" in
1970 --install|-i)
1971 inst='yes' ;;
1973 --pack)
1974 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
1975 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
1976 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -rf $LOGS/$pkg-pack.log
1977 sed -i '$ s|$| (packing)|' $activity
1978 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
1979 clean_log "$pkg-pack"
1980 time=$(($(date +%s) - $time))
1981 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
1982 put_status $pkg Done
1983 rm -f $command
1984 exit 0 ;;
1986 --trials|-t)
1987 trials='yes' ;;
1988 esac
1990 # Rotate log
1991 for i in $(seq 9 -1 1); do
1992 j=$(($i - 1))
1993 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1994 done
1995 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1997 # Check if wanted is built now so we have separate log files.
1998 for wanted in $WANTED ; do
1999 if grep -q "^$wanted$" $blocked; then
2000 broken
2001 rm -f $command
2002 die 'WANTED package "%s" is blocked' "$wanted"
2003 fi
2004 if grep -q "^$wanted$" $broken; then
2005 broken
2006 rm -f $command
2007 die 'WANTED package "%s" is broken' "$wanted"
2008 fi
2009 if [ ! -d "$WOK/$wanted/install" ]; then
2010 cook "$wanted" || { broken; exit 1; }
2011 fi
2012 done
2014 # Cook and pack or exit on error and log everything.
2015 ((((cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq))
2016 rq=$? # the return code of `cookit $@` above command
2018 # Remove build dependencies both when `cookit` done or fail
2019 remove_deps | tee -a $LOGS/$pkg.log
2020 cookit_quality
2022 # Log and stop if `cookit` fails
2023 if [ $rq -eq 1 ]; then
2024 debug_info | tee -a $LOGS/$pkg.log
2025 put_status $pkg Failed
2026 rm -f $command
2027 broken; exit 1
2028 fi
2030 # Proceed only if `cookit` return code is zero-OK
2031 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2033 clean_log
2035 # Exit if any error in packing.
2036 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
2037 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2038 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2039 debug_info | tee -a $LOGS/$pkg.log
2040 put_status $pkg Failed
2041 rm -f $command
2042 broken; exit 1
2043 fi
2045 # Create an XML feed
2046 gen_rss
2048 # Time and summary
2049 time=$(($(date +%s) - $time))
2050 summary | tee -a $LOGS/$pkg.log
2051 newline
2053 # We may want to install/update (outside aufs jail!).
2054 [ -s /aufs-umount.sh ] || install_package
2056 put_status $pkg Done
2058 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2059 # If you want automation, use the Cooker Build Bot.
2060 rm -f $command
2061 ;;
2062 esac
2064 exit 0