cookutils view cook @ rev 1023

cook: fix regression in packit() made by me in commit #1020
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sun Jan 14 17:12:15 2018 +0200 (2018-01-14)
parents dc7238a11470
children be4a05be1a6f
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 # Misc fix functions
532 fix() {
533 case $1 in
534 # https://bugzilla.gnome.org/show_bug.cgi?id=655517
535 # https://wiki.gentoo.org/wiki/Project:Quality_Assurance/As-needed
536 ld)
537 export LDFLAGS="$LDFLAGS -Wl,-Os,--as-needed"
538 ;;
539 libtool)
540 if [ -e 'libtool' ]; then
541 sed -i 's| -shared | -Wl,-Os,--as-needed\0|g' libtool
542 else
543 echo "fix libtool: warning: libtool absent, nothing to fix."
544 fi
545 ;;
546 esac
547 }
550 # The main cook function.
552 cookit() {
553 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
554 _ 'ERROR: Broken setup. Abort.'
555 return
556 fi
558 title 'Cook: %s' "$PACKAGE $VERSION"
559 set_paths
561 # Handle cross-tools.
562 case "$ARCH" in
563 arm*|x86_64)
564 # CROSS_COMPILE is used by at least Busybox and the kernel to set
565 # the cross-tools prefix. Sysroot is the root of our target arch
566 sysroot="$CROSS_TREE/sysroot"
567 tools="$CROSS_TREE/tools"
568 # Set root path when cross compiling. ARM tested but not x86_64
569 # When cross compiling we must install build deps in $sysroot.
570 arch="-$ARCH"
571 root="$sysroot"
572 _ '%s sysroot: %s' "$ARCH" "$sysroot"
573 _ 'Adding "%s" to PATH' "$tools/bin"
574 export PATH="$PATH:$tools/bin"
575 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
576 export CROSS_COMPILE="$HOST_SYSTEM-"
577 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
578 if [ "$ARCH" == 'x86_64' ]; then
579 export CC="$HOST_SYSTEM-gcc -m64"
580 export CXX="$HOST_SYSTEM-g++ -m64"
581 else
582 export CC="$HOST_SYSTEM-gcc"
583 export CXX="$HOST_SYSTEM-g++"
584 fi
585 export AR="$HOST_SYSTEM-ar"
586 export AS="$HOST_SYSTEM-as"
587 export RANLIB="$HOST_SYSTEM-ranlib"
588 export LD="$HOST_SYSTEM-ld"
589 export STRIP="$HOST_SYSTEM-strip"
590 export LIBTOOL="$HOST_SYSTEM-libtool"
591 ;;
592 esac
594 @@PREFIX@@/libexec/cookutils/precheck $receipt || exit 1 # former receipt_quality()
596 cd $pkgdir
597 [ -z "$continue" ] && rm -rf source 2>/dev/null
598 rm -rf install taz 2>/dev/null
600 # Disable -pipe if less than 512 MB free RAM.
601 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
602 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
603 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
604 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
605 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
606 fi
607 unset free
609 # Export flags and path to be used by make and receipt.
610 DESTDIR="$pkgdir/install"
611 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
612 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
613 #LDFLAGS
615 # BUILD_DEPENDS may vary depending on the ARCH
616 case "$ARCH" in
617 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
618 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
619 esac
621 # Check for build deps and handle implicit depends of *-dev packages
622 # (ex: libusb-dev :: libusb).
623 # rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
624 # touch $CACHE/installed.local $CACHE/installed.web
625 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
626 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
628 # Get the list of installed packages
629 cd $root$INSTALLED; ls > $CACHE/installed.list
631 for action in check install; do
632 for dep in $BUILD_DEPENDS; do
633 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
634 for i in $dep $implicit; do
635 # Skip if package already installed
636 [ -f "$root$INSTALLED/$i/receipt" ] && continue
638 case $action in
639 check)
640 # Search for local package or local provided-package
641 name=$(awk -F$'\t' -vpkg="$i" '{
642 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
643 }' "$PKGS/packages.info")
644 if [ -z "$name" ]; then
645 # Search for package in mirror
646 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
647 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
648 fi
649 ;;
650 install)
651 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
652 ;;
653 esac
654 done
655 done
656 done
658 # # Have we a missing build dep to cook?
659 # if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
660 # _ 'Auto cook config is set: %s' "$AUTO_COOK"
661 # cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
662 # for i in $(uniq $CACHE/missing.dep); do
663 # (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
664 # tee -a $LOGS/$PACKAGE.log.$$
665 # # programmers: next two messages are exact copy from remove_deps()
666 # togrep1=$(_n 'Build dependencies to remove:')
667 # togrep2=$(_n 'Removing:')
668 # cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
669 # fgrep $togrep1 $LOGS/$i.log && \
670 # fgrep $togrep2 $LOGS/$i.log && newline) | \
671 # tee -a $LOGS/$PACKAGE.log.$$ && break
672 # done
673 # rm -f $CACHE/missing.dep
674 # mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
675 # fi
676 #
677 # # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
678 # # is enabled and cook fails we have ERROR in log, if no auto cook we have
679 # # missing dep in cached file.
680 # lerror=$(_n 'ERROR')
681 # if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
682 # [ -s "$CACHE/missing.dep" ] && nb=$(wc -l < $CACHE/missing.dep)
683 # _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
684 # broken; exit 1
685 # fi
686 #
687 # # Install local packages: package-version$arch
688 # cd $PKGS
689 # for i in $(uniq $CACHE/installed.local); do
690 # # _ 'Installing dep (pkg/local): %s' "$i"
691 # tazpkg install $i --root=$root --local --quiet --cookmode
692 # done
693 #
694 # # Install web or cached packages (if mirror is set to $PKGS we only
695 # # use local packages).
696 # for i in $(uniq $CACHE/installed.web); do
697 # # _ 'Installing dep (web/cache): %s' "$i"
698 # tazpkg get-install $i --root=$root --local --quiet --cookmode
699 # done
701 update_installed_cook_diff
703 # Get source tarball and make sure we have source dir named:
704 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
705 # tarball if it exists.
706 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
707 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
708 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
709 LZMA_SRC=''
710 else
711 get_source || { broken; exit 1; }
712 fi
713 fi
714 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
715 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
716 if ! extract_source ; then
717 get_source
718 extract_source || { broken; exit 1; }
719 fi
720 if [ -n "$LZMA_SRC" ]; then
721 cd $pkgdir/source
722 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
723 mv tmp tmp-1; mkdir tmp
724 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
725 fi
726 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
727 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
728 fi
729 fi
731 cd $pkgdir/source/tmp
732 # Some archives are not well done and don't extract to one dir (ex lzma).
733 files=$(ls | wc -l)
734 [ "$files" -eq 1 -a -d "$(ls)" ] &&
735 mv * ../$PACKAGE-$VERSION
736 [ "$files" -eq 1 -a -f "$(ls)" ] &&
737 mkdir -p ../$PACKAGE-$VERSION &&
738 mv * ../$PACKAGE-$VERSION/$TARBALL
739 [ "$files" -gt 1 ] &&
740 mkdir -p ../$PACKAGE-$VERSION &&
741 mv * ../$PACKAGE-$VERSION
742 cd ..; rm -rf tmp
743 fi
745 # Check md5sum (or similar) for sources tarball
746 check_integrity
748 # Libtool shared libs path hack.
749 case "$ARCH" in
750 arm*) cross libhack ;;
751 esac
753 # Compiling all the sets
754 if grep -q ^compile_rules $receipt; then
755 _ 'Executing: %s' 'compile_rules'
756 echo "CFLAGS : $CFLAGS"
757 #echo "LDFLAGS : $LDFLAGS"
758 [ -d "$src" ] && cd $src
759 patchit
761 # Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
762 SETS=$(echo $SPLIT \
763 | awk '
764 BEGIN { RS = " "; FS = ":"; }
765 { print $2; }' \
766 | sort -u \
767 | tr '\n' ' ')
768 SETS=${SETS% } # normalize space
769 # Prepare specified source sets using patched sources
770 [ -n "$SETS" ] &&
771 for set in $SETS; do
772 echo "Preparing set $set" # debug
773 cp -a $src $src-$set
774 done
776 for SET in '' $SETS; do
777 # Switch to the specified source set
778 set_paths
779 local suffix=''
780 [ -n "$SET" ] && suffix="-$SET"
781 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
782 export install="$WOK/$pkg/install$suffix"
783 export DESTDIR="$install"
785 if [ -n "$SETS" ]; then
786 if [ -n "$SET" ]; then
787 title "Switching to the set '$SET'"
788 else
789 title "Switching to the default set"
790 fi
791 echo "src : $src"
792 echo "install: $install"
793 fi
794 [ -d "$src" ] && cd $src # packages without sources exists
795 echo
797 [ -d "$install" ] && rm -r $install
798 #mkdir -p $install
800 compile_rules $@ || { broken; exit 1; }
802 # Stay compatible with _pkg
803 [ -d "$src/_pkg" ] && mv $src/_pkg $install
805 copy_generic_stuff
807 # Actions to do after compiling the package
808 # Skip all for split packages (already done in main package)
809 if [ -z "$WANTED" ]; then
810 footer
811 export COOKOPTS ARCH install
812 @@PREFIX@@/libexec/cookutils/compressor install
813 fi
814 done
815 else
816 mkdir -p $install # allow receipts without `compile_rules()`
817 fi
818 footer
820 # Execute testsuite.
821 if grep -q ^testsuite $receipt; then
822 title 'Running testsuite'
823 testsuite $@ || { broken; exit 1; }
824 footer
825 fi
827 update_installed_cook_diff force
828 }
831 # Cook quality assurance.
833 cookit_quality() {
834 while true; do
835 [ ! -d "$WOK/$pkg/install" -a -z "$WANTED" ] || break
836 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
837 [ "$trials" == 'yes' ] || break
838 title "Interactive mode"
839 # TODO: allow commands:
840 # q - quit; v - edit receipt here using vi;
841 # s - search for package containing package;
842 # <package name> - install package; [Enter] - retry
843 _ 'You may install the packages here and/or edit the receipt there.'
844 newline
845 while true; do
846 _n 'Install the package? [name/N] '; read answer
847 [ -n "$answer" ] || break
848 tazpkg -gi $answer --root=$root --local --quiet --cookmode
849 done
850 newline
851 _n 'Try again? [Y/n] '; read answer
852 [ "$answer" == 'n' ] && break
853 # here you may append log if you want (">>" instead of last ">")
854 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
855 done
857 [ "${COOKOPTS/skip-log-errors/}" != "$COOKOPTS" ] && return 0
859 # ERROR can be echoed any time in cookit()
860 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
861 grep -Eq "(^ERROR|undefined reference to)" ; then
862 debug_info | tee -a $LOGS/$pkg.log
863 put_status $pkg Failed
864 rm -f $command
865 broken; exit 1
866 fi
867 }
870 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
871 # but it doesn't handle EXTRAVERSION.
873 packit() {
874 set_paths "$1"
875 PACKAGE="${1:-$PACKAGE}"
877 # Handle cross compilation
878 case "$ARCH" in
879 arm*|x86_64) arch="-$ARCH" ;;
880 esac
882 title 'Pack: %s' "$PACKAGE $VERSION$arch"
884 # Get set name for specified package from $SPLIT variable
885 local set=$(echo -n $SPLIT \
886 | awk -vpkg="$PACKAGE" '
887 BEGIN { RS = " "; FS = ":"; }
888 { if ($1 == pkg && $2 != "") { print "-" $2; exit; } }')
889 # Change set, make filelist and folderlist for new set
890 export src="$src$set"
891 export install="$install$set"
892 export DESTDIR="$install"
894 if grep -q ^genpkg_rules $receipt; then
895 _ 'Executing: %s' 'genpkg_rules'
896 set -e; cd $pkgdir; mkdir -p $fs
897 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
898 $LOGS/$pkg.log
899 else
900 _ 'No packages rules: meta package'
901 mkdir -p $fs
902 fi
904 # Check CONFIG_FILES
905 if [ -n "$CONFIG_FILES" ]; then
906 unset IFS
907 for i in $CONFIG_FILES; do
908 if [ ! -e $fs$i ]; then
909 case $i in
910 */) mkdir -p $fs$i ;;
911 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
912 esac
913 fi
914 done
915 fi
917 # First QA check to stop now if genpkg_rules failed.
918 lerror=$(_n 'ERROR')
919 if fgrep -q ^$lerror $LOGS/$pkg.log; then
920 broken; exit 1
921 fi
923 cd $taz
924 action 'Copying "%s"...' 'receipt'
925 export PACKAGE DEPENDS PROVIDE SUGGESTED TAZPANEL_DAEMON TAGS CAT
926 @@PREFIX@@/libexec/cookutils/mk_pkg_receipt "$(realpath ../receipt)" > $pack/receipt
927 chown 0.0 $pack/receipt; status
929 unset desc
930 [ "$pkg" == "$PACKAGE" -a -f "../description.txt" ] && desc="../description.txt"
931 [ -f "../description.$PACKAGE.txt" ] && desc="../description.$PACKAGE.txt"
932 if [ -n "$desc" ]; then
933 action 'Copying "%s"...' "$(basename "$desc")"
934 cp -f $desc $pack/description.txt; chown 0.0 $pack/description.txt; status
935 fi
937 copy_generic_files
939 # Strip and stuff files.
940 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
942 # Create files.list with redirecting find output.
943 action 'Creating the list of files...'
944 cd $fs
945 find . -type f -print > ../files.list
946 find . -type l -print >> ../files.list
947 cd ..; sed -i 's|^.||' files.list
948 status
950 # Md5sum of files.
951 action 'Creating md5sum of files...'
952 while read file; do
953 [ -L "fs$file" ] && continue
954 [ -f "fs$file" ] || continue
955 case "$file" in
956 /lib/modules/*/modules.*|*.pyc) continue ;;
957 esac
958 md5sum "fs$file" | sed 's| fs| |'
959 done < files.list | sort -k2 > md5sum
960 status
962 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
963 2>/dev/null | awk 'END{ print $1 }')
965 # Build cpio archive.
966 action 'Compressing the FS...'
967 find fs -newer $receipt -exec touch -hr $receipt '{}' \;
968 find fs | cpio -o -H newc --quiet | lzma-alone e fs.cpio.lzma -si
969 # find fs | cpio -o -H newc --quiet | /bin/lzma -zeT0 -vv >fs.cpio.lzma
970 mv fs ../
971 status
973 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
974 2>/dev/null | awk 'END{ print $1 }')
976 action 'Updating receipt sizes...'
977 sed -i '/^PACKED_SIZE=/d; /^UNPACKED_SIZE=/d' receipt
978 sed -i "s|^PACKAGE=|PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=|" receipt
979 status
981 # Set extra version.
982 if [ -n "$EXTRAVERSION" ]; then
983 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
984 sed -i '/^EXTRAVERSION=/d' receipt
985 sed -i "s|^VERSION=|EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=|" receipt
986 status
987 fi
989 # Compress.
990 action 'Creating full cpio archive...'
991 find . -newer $receipt -exec touch -hr $receipt '{}' \;
992 find . | cpio -o -H newc --quiet > ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
993 status
995 # Restoring original package tree.
996 mv ../fs .
998 rm fs.cpio.lzma; cd ..
1000 # QA and give info.
1001 tazpkg=$(ls *.tazpkg)
1002 packit_quality
1003 footer "$(_ 'Package "%s" created' "$tazpkg")"
1007 # Verify package quality and consistency.
1009 packit_quality() {
1010 local rsum rsumold='' rsum_changed old_file
1011 local pi="$PKGS/packages.info" fl="$cache/files.list"
1012 local pkg_file="$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
1013 local rsum_file=$(mktemp) rsum_file_old=$(mktemp) tmpdir=$(mktemp -d)
1016 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ]; then
1017 # Exit if any error found in log file.
1018 if fgrep -q ^ERROR $LOGS/$pkg.log; then
1019 rm -f $command
1020 broken; exit 1
1021 fi
1022 fi
1025 [ -n "$CAT" ] && CATEGORY="${CAT%|*}" # allow meta-packages in v2 receipts
1027 if [ "${COOKOPTS/empty-pkg/}" == "$COOKOPTS" ]; then
1028 action 'QA: checking for empty package...'
1029 if [ ! -s "$pack/files.list" -a "$CATEGORY" != 'meta' ]; then
1030 broken
1031 rm -f $command
1032 false; status
1033 die 'ERROR: empty package'
1034 fi
1035 :; status
1036 fi
1039 # Calculate release checksum: usually it does not change on "just recook".
1040 # Release checksum is md5sum of file containing md5sums of:
1041 # a) all files, b) receipt, and c) description.txt.
1042 # Md5sum of the package file will change every time because of embedded timestamps;
1043 # release checksum based only on files content, and will change only when files change.
1044 # (Pitfall: ownership and permissions...)
1046 # Calculate rsum for new package
1047 cp $pack/md5sum $rsum_file
1048 md5sum $pack/receipt | sed 's| [^ ]*/| |' >> $rsum_file
1049 [ -e "$pack/description.txt" ] &&
1050 md5sum $pack/description.txt | sed 's| [^ ]*/| |' >> $rsum_file
1051 rsum=$(md5sum $rsum_file | awk '{print $1}')
1053 # Calculate rsum for existing previous "old" package
1054 if [ -f "$pkg_file" ]; then
1055 # don't trust database entry, check the package file
1056 cd $tmpdir
1057 cpio -F "$pkg_file" -i md5sum receipt description.txt >/dev/null 2>&1
1058 cp ./md5sum $rsum_file_old
1059 md5sum ./receipt | sed 's| [^ ]*/| |' >> $rsum_file_old
1060 [ -e "./description.txt" ] &&
1061 md5sum ./description.txt | sed 's| [^ ]*/| |' >> $rsum_file_old
1062 rsumold=$(md5sum $rsum_file_old | awk '{print $1}')
1063 cd - >/dev/null
1064 fi
1066 # Clean
1067 rm $rsum_file $rsum_file_old
1068 rm -r $tmpdir
1071 touch $pi $broken
1074 # Find and remove old package only if "release checksum" has changed
1076 if [ "$rsum" != "$rsumold" ]; then
1077 old_file=$(awk -F$'\t' -vname="$PACKAGE" '{
1078 if ($1 == name) printf("%s-%s.tazpkg", $1, $2);
1079 }' $pi) # <name>-<version><extra_version>.tazpkg
1080 if [ -f "$PKGS/$old_file" ]; then
1081 action 'Removing old package "%s"' "$old_file"
1082 rm -f "$PKGS/$old_file"
1083 status
1084 fi
1085 # package changed, substitute old package by new one
1086 mv -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg $PKGS
1087 _ 'The release checksum has changed.'
1088 else
1089 # package not changed, remove new package
1090 rm -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1091 _ 'The release checksum has not changed.'
1092 fi
1095 sed -i "/^${pkg}$/d" $broken
1098 # Update packages database every time after successful build
1100 # packages.info (unsorted, located near to packages)
1101 unset_receipt; . $pack/receipt
1102 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1103 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1104 sed -i "/^$PACKAGE\t/d" $pi # remove old entry
1105 cat >> $pi <<EOT
1106 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $rsum $PROVIDE
1107 EOT
1109 # files.list (uncompressed, unsorted, located in $cache)
1110 touch $fl
1111 sed -i "/^$PACKAGE: /d" $fl
1112 sed "s/^/$PACKAGE: \0/" $pack/files.list >> $fl
1116 # Return all the names of packages bundled in this receipt
1118 all_names() {
1119 # Get package names from $SPLIT variable
1120 local split=$(echo $SPLIT \
1121 | awk '
1122 BEGIN { RS = " "; FS = ":"; }
1123 { print $1; }' \
1124 | tr '\n' ' ')
1125 local split_space=" $split "
1126 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
1127 # For receipts v1: $SPLIT may present in the $WANTED package,
1128 # but split packages have their own receipts
1129 echo $PACKAGE
1130 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
1131 # $PACKAGE included somewhere in $SPLIT (probably in the end).
1132 # We should build packages in the order defined in the $SPLIT.
1133 echo $split
1134 else
1135 # We'll build the $PACKAGE, then all defined in the $SPLIT.
1136 echo $PACKAGE $split
1137 fi
1141 # v2: pack all packages using compiled files
1143 packall() {
1144 set_paths
1145 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1146 for i in $(all_names); do
1147 unset TAGS DEPENDS CAT CONFIG_FILES PROVIDE SUGGESTED DATABASE_FILES TAZPANEL_DAEMON
1148 packit $i
1149 done
1150 else
1151 packit
1152 fi
1156 # Reverse "cat" command: prints input lines in the reverse order
1158 tac() {
1159 sed '1!G;h;$!d' $1
1163 # Update chroot with freshly rebuilt package: keep env up-to-date.
1165 update_chroot() {
1166 local PACKAGE="$pkg"
1167 for i in $(all_names); do
1168 if [ -d "$root$INSTALLED/$i" ]; then
1169 . /etc/slitaz/cook.conf
1170 . $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt
1171 _ 'Updating %s chroot environment...' "$ARCH"
1172 _ 'Updating chroot: %s' "$i ($VERSION$EXTRAVERSION$arch)" | log
1173 cd $PKGS
1174 tazpkg install $i-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1175 fi
1176 done
1180 # Install package on --inst or update the chroot.
1182 install_package() {
1183 set_paths
1184 case "$ARCH" in
1185 arm*|x86_64)
1186 arch="-$ARCH"
1187 root="$CROSS_TREE/sysroot" ;;
1188 esac
1189 # Install package if requested but skip install if target host doesn't
1190 # match build system or it will break the build chroot.
1191 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1192 if [ -n "$inst" -a "$build" == "$ARCH" ]; then
1193 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1194 cd $PKGS
1195 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1196 else
1197 broken
1198 die 'Unable to install package, build has failed.'
1199 fi
1200 fi
1202 update_chroot
1206 # remove chroot jail
1208 umount_aufs() {
1209 tac ${1}rw/aufs-umount.sh | sh
1210 rm -rf ${1}rw
1211 umount ${1}root
1212 rmdir ${1}r*
1216 # Launch the cook command into a chroot jail protected by aufs.
1217 # The current filesystems are used read-only and updates are
1218 # stored in a separate branch.
1220 try_aufs_chroot() {
1222 base="/dev/shm/aufsmnt$$"
1224 # Can we setup the chroot? Is it already done?
1225 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1226 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1227 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1228 grep -q ^aufs /proc/modules || modprobe aufs 2> /dev/null || return
1229 mkdir ${base}root ${base}rw || return
1231 _ 'Setup aufs chroot...'
1233 # Sanity check
1234 for i in / /proc /sys /dev/shm /home ; do
1235 case " $AUFS_MOUNTS " in
1236 *\ $i\ *) ;;
1237 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1238 esac
1239 done
1240 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1241 mount --bind $mnt ${base}root$mnt
1242 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1243 _ 'Aufs mount failure'
1244 umount ${base}root
1245 rm -rf ${base}r*
1246 return
1247 fi
1248 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1249 done
1250 trap "umount_aufs ${base}" INT
1252 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1253 status=$?
1255 _ 'Leaving aufs chroot...'
1256 umount_aufs $base
1257 # Install package outside the aufs jail
1258 install_package
1259 exit $status
1263 # Encode predefined XML entities
1265 xml_ent() {
1266 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1270 # Create a XML feed for freshly built packages.
1272 gen_rss() {
1273 pubdate=$(date '+%a, %d %b %Y %X')
1274 cat > $FEEDS/$pkg.xml <<EOT
1275 <item>
1276 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1277 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1278 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1279 <pubDate>$pubdate</pubDate>
1280 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1281 </item>
1282 EOT
1286 # Truncate stdout log file to $1 Mb.
1288 loglimit() {
1289 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1290 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1291 else
1292 tee /dev/stderr
1293 fi
1298 # Receipt functions to ease packaging
1301 get_dev_files() {
1302 action 'Getting standard devel files...'
1303 mkdir -p $fs/usr/lib
1304 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1305 cp -a $install/usr/lib/*a $fs/usr/lib
1306 cp -a $install/usr/include $fs/usr
1307 status
1311 # Function to use in compile_rules() to copy man page from $src to $install
1313 cook_pick_manpages() {
1314 local name section
1315 action 'Copying man pages...'
1317 for i in $@; do
1318 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1319 section=${name##*/}; section=${section##*.}
1320 mkdir -p $install/usr/share/man/man$section
1321 scopy $i $install/usr/share/man/man$section
1322 done
1323 status
1327 # Function to use in compile_rules() to copy documentation from $src to $install
1329 cook_pick_docs() {
1330 local docdir="$install/usr/share/doc/$PACKAGE-$VERSION"
1331 action 'Copying documentation...'
1332 mkdir -p $docdir
1333 cp -r $@ $docdir
1334 chmod -R a+r $docdir
1335 status
1339 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1341 cook_copy_files() {
1342 action 'Copying files...'
1343 cd $install
1344 local i j
1345 IFS=$'\n'
1346 for i in $@; do
1347 for j in $(find . -name $i ! -type d); do
1348 mkdir -p $fs$(dirname ${j#.})
1349 scopy $j $fs$(dirname ${j#.})
1350 done
1351 done
1352 cd - >/dev/null
1353 status
1357 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1359 cook_copy_folders() {
1360 action 'Copying folders...'
1361 cd $install
1362 local i j
1363 IFS=$'\n'
1364 for i in $@; do
1365 for j in $(find . -name $i -type d); do
1366 mkdir -p $fs$(dirname ${j#.})
1367 cp -a $j $fs$(dirname ${j#.})
1368 done
1369 done
1370 cd - >/dev/null
1371 status
1375 # Remove from current $fs files that are already packed (for receipts v2).
1376 # Note: the order in $SPLIT is very important.
1377 # Note 2: working in the current set.
1379 remove_already_packed() {
1380 local i j
1381 # $pkg is the name of the main package; $PACKAGE is the name of the current one
1382 # $pkg may (or may not) be included in the $SPLIT
1383 neighbors=$(
1384 echo $pkg $SPLIT" " \
1385 | awk -F$'\t' -vpkg="$PACKAGE" '
1386 BEGIN { RS = " "; FS = ":"; }
1387 { set[$1] = $2; }
1388 END {
1389 current_set = set[pkg];
1390 for (i in set)
1391 { if (i != pkg && set[i] == current_set) print i; }
1393 ')
1394 IFS=$'\n'
1395 for neighbor in $neighbors; do
1396 i="$taz/$neighbor-$VERSION$EXTRAVERSION/files.list"
1397 [ -e "$i" ] || continue
1398 while read j; do
1399 [ -f $fs$j -o -h $fs$j ] || continue
1400 rm $fs$j
1401 rmdir --parents --ignore-fail-on-non-empty $fs$(dirname $j)
1402 done < $i
1403 done
1404 unset IFS
1408 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1409 # (default: 16 and 48) from $install to $fs
1411 cook_copy_icons() {
1412 local sizes=$@ i j ifs="$IFS"
1413 unset IFS
1414 action 'Copying hicolor icons...'
1415 [ -d "$fs/usr/share/icons/hicolor" ] && rm -rf "$fs/usr/share/icons/hicolor"
1416 mkdir -p $fs/usr/share/icons/hicolor
1417 for i in ${sizes:-16 48}; do
1418 j="${i}x$i"; [ "$i" == 'scalable' ] && j="$i"
1419 [ ! -e "$install/usr/share/icons/hicolor/$j" ] ||
1420 scopy $install/usr/share/icons/hicolor/$j \
1421 $fs/usr/share/icons/hicolor
1422 done
1423 status
1424 IFS="$ifs"
1428 # Common function to copy files, folders and patterns
1430 copy() {
1431 action 'Copying folders and files...'
1432 local i j k filelist=$(mktemp) folderlist=$(mktemp)
1434 IFS=$'\n'
1435 cd $install
1436 find ! -type d | sed 's|\.||' > $filelist
1437 find -type d | sed 's|\.||' > $folderlist
1439 for i in $@; do
1440 case $i in
1441 @std)
1442 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1443 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /\.pri$/d; /bin\/.*-config$/d;
1444 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1445 /\/Makefile.*/d; /\.inc$/d; /\/include\//d;
1446 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1447 /\/share\/devhelp\//d; /\/share\/locale\//d;
1448 /\/share\/bash-completion\//d; /\/lib\/systemd\//d;
1449 /\/fonts\.scale$/d; /\/fonts\.dir$/d;
1450 /\/share\/appdata\//d; /\/share\/help\//d;
1451 /\/share\/icons\/hicolor\/[12356][1245][268]*x[12356][1245][268]*\//d; # 22, 24, 32, 64, 128, 256, 512
1452 ' $filelist
1453 ;;
1454 @dev)
1455 # Copy "developer files"
1456 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.la$/p; /\.pc$/p; /\.pri$/p; /bin\/.*-config$/p;
1457 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1458 /\/Makefile.*/p; /\.inc$/p; /\/include\//p;
1459 ' $filelist
1460 ;;
1461 @rm)
1462 # Quick alias
1463 remove_already_packed
1464 ;;
1465 @ico)
1466 # Quick alias
1467 cook_copy_icons >/dev/null
1468 ;;
1469 */)
1470 # Copy specified folders.
1471 i="${i%/}"
1472 find -type d -path "*/${i#/}" | sed 's|^.||'
1473 ;;
1474 *)
1475 # Copy specified files.
1476 find ! -type d -path "*/${i#/}" | sed 's|^.||'
1477 ;;
1478 esac \
1479 | sort -u \
1480 | while read j; do
1481 mkdir -p $fs$(dirname "$j")
1482 if [ -d "$install$j" ]; then
1483 cp -a "$install$j" $fs$(dirname "$j")
1484 else
1485 scopy "$install$j" $fs$(dirname "$j")
1486 fi
1487 done
1488 # Copy empty directories
1489 case $i in
1490 @std)
1491 while read j; do
1492 case $j in
1493 # always skip empty man & doc folders, because this will end up
1494 # copying all the man pages and docs to the package
1495 */man/*|*/doc/*) continue;;
1496 esac
1497 [ -z "$(ls -A "$install$j")" ] || continue
1498 # directory $j is empty
1499 k="$j"
1500 # make 'ladder' from directories, from root dir to $j
1501 # /a /a/b /a/b/c etc.
1502 while :; do
1503 [ -z "$k" ] && break
1504 echo "$k"
1505 k="${k%/*}"
1506 done \
1507 | tac \
1508 | while read k; do
1509 # copy dir with its original ownership/permissions if it does not exist
1510 [ -d "$fs$k" ] || cp -a "$install$k" "$fs$k"
1511 done
1512 done < $folderlist
1513 ;;
1514 esac
1515 done
1516 cd - >/dev/null
1517 unset IFS
1518 rm $filelist $folderlist
1519 status
1523 # Update split.db once for receipt
1525 update_split_db() {
1526 local db="$cache/split.db"
1527 touch $db
1528 sed -i "/^$pkg\t/d" $db
1529 echo -e "$pkg\t$(all_names)" >> $db
1533 # Recreate whole split.db from scratch
1535 recreate_split_db() {
1536 # Clean
1537 local db="$cache/split.db"
1538 touch $db
1539 > $db
1541 cd $WOK
1542 for pkg in *; do
1543 [ -f "$WOK/$pkg/receipt" ] || continue
1544 unset PACKAGE SPLIT
1545 . $WOK/$pkg/receipt
1546 echo -e "$PACKAGE\t$(all_names)" >> $db
1547 done
1551 # Put the status to the activity log
1553 put_status() {
1554 # $1: package, $2: status, one of 'Done', 'Failed'
1555 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1562 # Commands
1565 # cook <package> --deps
1566 [ -n "$deps" ] && {
1567 @@PREFIX@@/libexec/cookutils/deps $1
1568 exit 0
1571 # cook <package> --clean
1572 # cook <package> -c
1573 [ -n "$clean" -o "$2" == '-c' ] && {
1574 action 'Cleaning "%s"' "$1"
1575 cd $WOK/$1; rm -rf install taz source
1576 status; newline
1577 touch $activity # update $activity -> something changed -> update webstat
1578 exit 0
1581 # cook <package> --getsrc
1582 # cook <package> -gs
1583 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1584 title 'Getting source for "%s"' "$1"
1585 receipt="$WOK/$pkg/receipt"
1586 check_pkg_in_wok
1587 unset_receipt
1588 . $receipt
1589 get_source
1590 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1591 exit 0
1594 # cook <package> --block
1595 # cook <package> -b
1596 [ -n "$block" -o "$2" == '-b' ] && {
1597 action 'Blocking package "%s"' "$1"
1598 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1599 status; newline
1600 touch $activity
1601 exit 0
1604 # cook <package> --unblock
1605 # cook <package> -ub
1606 [ -n "$unblock" -o "$2" == '-ub' ] && {
1607 action 'Unblocking package "%s"' "$1"
1608 sed -i "/^$1$/d" $blocked
1609 status; newline
1610 touch $activity
1611 exit 0
1617 case "$1" in
1618 usage|help|-u|-h)
1619 usage ;;
1621 list-wok)
1622 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1623 cd $WOK
1624 if [ "$ARCH" != 'i486' ]; then
1625 count=0
1626 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1627 do
1628 unset HOST_ARCH
1629 . ./$pkg
1630 count=$(($count + 1))
1631 colorize 34 "$PACKAGE"
1632 done
1633 else
1634 count=$(ls | wc -l)
1635 ls -1
1636 fi
1637 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1638 ;;
1640 activity)
1641 cat $activity ;;
1643 search)
1644 # Just a simple search function, we don't need more actually.
1645 query="$2"
1646 title 'Search results for "%s"' "$query"
1647 cd $WOK; ls -1 | grep "$query"
1648 footer ;;
1650 setup)
1651 # Setup a build environment
1652 check_root
1653 _ 'Cook: setup environment' | log
1654 title 'Setting up your environment'
1655 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1656 cd $SLITAZ
1657 init_db_files
1658 _ 'Checking for packages to install...'
1659 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1660 # ARCH-setup or 'cross check' should be used before: cook setup
1661 case "$ARCH" in
1662 arm*|x86_64)
1663 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1664 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1665 . /etc/slitaz/cross.conf ;;
1666 esac
1667 for pkg in $SETUP_PKGS; do
1668 if [ -n "$forced" ]; then
1669 tazpkg -gi $pkg --forced
1670 else
1671 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1672 fi
1673 done
1675 # Handle --options
1676 case "$2" in
1677 --wok) hg clone $WOK_URL wok || exit 1 ;;
1678 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1679 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1680 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1681 esac
1683 # SliTaz group and permissions
1684 if ! grep -q ^slitaz /etc/group; then
1685 _ 'Adding group "%s"' 'slitaz'
1686 addgroup slitaz
1687 fi
1688 _ 'Setting permissions for group "%s"...' 'slitaz'
1689 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1690 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1691 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1693 *-setup)
1694 # Setup for cross compiling.
1695 arch="${1%-setup}"
1696 check_root
1697 . /etc/slitaz/cook.conf
1698 for pkg in $CROSS_SETUP; do
1699 if [ -n "$forced" ]; then
1700 tazpkg -gi $pkg --forced
1701 else
1702 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1703 fi
1704 done
1706 _ 'Cook: setup %s cross environment' "$arch" | log
1707 title 'Setting up your %s cross environment' "$arch"
1708 init_db_files
1709 sed -i \
1710 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1711 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1712 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1713 /etc/slitaz/cook.conf
1714 case "$arch" in
1715 arm)
1716 flags='-O2 -march=armv6'
1717 host="$ARCH-slitaz-linux-gnueabi" ;;
1718 armv6hf)
1719 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1720 host="$ARCH-slitaz-linux-gnueabi" ;;
1721 armv7)
1722 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1723 host="$ARCH-slitaz-linux-gnueabi" ;;
1724 x86_64)
1725 flags='-O2 -mtune=generic -pipe'
1726 host="$ARCH-slitaz-linux" ;;
1727 esac
1728 sed -i \
1729 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1730 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1731 . /etc/slitaz/cook.conf
1732 sysroot="$CROSS_TREE/sysroot"
1733 tools="/cross/$arch/tools"
1734 root="$sysroot"
1735 # L10n: keep the same width of translations to get a consistent view
1736 _ 'Target arch : %s' "$ARCH"
1737 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1738 _ 'Build flags : %s' "$flags"
1739 _ 'Arch sysroot : %s' "$sysroot"
1740 _ 'Tools prefix : %s' "$tools/bin"
1741 # Tell the packages manager where to find packages.
1742 _ 'Packages DB : %s' "$root$DB"
1743 mkdir -p $root$INSTALLED
1744 cd $root$DB; rm -f *.bak
1745 for list in packages.list packages.desc packages.equiv packages.md5; do
1746 rm -f $list
1747 ln -s $SLITAZ/packages/$list $list
1748 done
1749 # We must have the cross compiled glibc-base installed or default
1750 # i486 package will be used as dep by tazpkg and then break the
1751 # cross environment
1752 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1753 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1754 fi
1755 # Show GCC version or warn if not yet compiled.
1756 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1757 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1758 else
1759 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1760 _ 'Run "%s" to cook a toolchain' 'cross compile'
1761 fi
1762 footer ;;
1764 test)
1765 # Test a cook environment.
1766 _ 'Cook test: testing the cook environment' | log
1767 [ ! -d "$WOK" ] && exit 1
1768 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1769 cook cooktest ;;
1771 new)
1772 # Create the package folder and an empty receipt.
1773 pkg="$2"
1774 [ -z "$pkg" ] && usage
1775 newline
1776 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1778 action 'Creating folder "%s"' "$WOK/$pkg"
1779 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1781 action 'Preparing the package receipt...'
1782 cp $DATA/receipt .
1783 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1784 status; newline
1786 # Interactive mode, asking and seding.
1787 case "$3" in
1788 --interactive|-x)
1789 _ 'Entering interactive mode...'
1790 separator
1791 _ 'Package : %s' "$pkg"
1793 _n 'Version : ' ; read answer
1794 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1796 _n 'Category : ' ; read answer
1797 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1799 # L10n: Short description
1800 _n 'Short desc : ' ; read answer
1801 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1803 _n 'Maintainer : ' ; read answer
1804 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1806 _n 'License : ' ; read answer
1807 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1809 _n 'Web site : ' ; read answer
1810 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1811 newline
1813 # Wget URL.
1814 _ 'Wget URL to download source tarball.'
1815 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1816 _n 'Wget url : ' ; read answer
1817 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1819 # Ask for a stuff dir.
1820 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1821 if [ "$?" -eq 0 ]; then
1822 action 'Creating the stuff directory...'
1823 mkdir $WOK/$pkg/stuff; status
1824 fi
1826 # Ask for a description file.
1827 confirm "$(_n 'Are you going to write a description? (y/N)')"
1828 if [ "$?" -eq 0 ]; then
1829 action 'Creating the "%s" file...' 'description.txt'
1830 touch $WOK/$pkg/description.txt; status
1831 fi
1833 footer "$(_ 'Receipt is ready to use.')" ;;
1834 esac ;;
1836 list)
1837 # Cook a list of packages (better use the Cooker since it will order
1838 # packages before executing cook).
1839 check_root
1840 [ -z "$2" ] && die 'No list in argument.'
1841 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1843 _ 'Starting cooking the list "%s"' "$2" | log
1845 while read pkg; do
1846 cook $pkg || broken
1847 done < $2
1848 ;;
1850 clean-wok)
1851 check_root
1852 newline; action 'Cleaning all packages files...'
1853 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1854 status; newline ;;
1856 clean-src)
1857 check_root
1858 newline; action 'Cleaning all packages sources...'
1859 rm -rf $WOK/*/source
1860 status; newline ;;
1862 uncook)
1863 cd $WOK
1864 count=0
1865 title 'Checking for uncooked packages'
1867 for i in *; do
1868 unset HOST_ARCH EXTRAVERSION
1869 [ ! -e $i/receipt ] && continue
1870 . ./$i/receipt
1871 # Source cooked pkg receipt to get EXTRAVERSION
1872 if [ -d "$WOK/$i/taz" ]; then
1873 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
1874 . ./receipt; cd $WOK
1875 fi
1876 case "$ARCH" in
1877 i486)
1878 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1879 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1880 count=$(($count + 1))
1881 colorize 34 "$i"
1882 fi ;;
1883 arm*)
1884 # Check only packages included in arch
1885 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1886 # *.tazpkg
1887 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1888 count=$(($count + 1))
1889 colorize 34 "$i"
1890 fi
1891 fi ;;
1892 esac
1893 done
1895 if [ "$count" -gt 0 ]; then
1896 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1897 else
1898 _ 'All packages are cooked :-)'
1899 newline
1900 fi
1901 ;;
1903 pkgdb)
1904 # Create suitable packages list for TazPkg and only for built packages
1905 # as well as flavors files for TazLiTo. We don't need logs since we do it
1906 # manually to ensure everything is fine before syncing the mirror.
1907 recreate_split_db
1908 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1909 ;;
1911 splitdb)
1912 # File split.db is useful for searching for split packages.
1913 recreate_split_db
1914 ;;
1916 *)
1917 # Just cook and generate a package.
1918 check_root
1919 time=$(date +%s)
1920 pkg="$1"
1921 [ -z "$pkg" ] && usage
1923 # Search last successful cook time in all logs from newer to older
1924 for i in '' $(seq 0 9 | sed 's|^|.|'); do
1925 [ -f "$LOGS/$pkg.log$i" ] || break
1926 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1927 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
1928 [ -n "$lastcooktime" ] && break
1929 done
1931 receipt="$WOK/$pkg/receipt"
1932 check_pkg_in_wok
1933 newline
1935 unset inst
1936 unset_receipt
1937 . $receipt
1939 # Handle cross compilation.
1940 case "$ARCH" in
1941 arm*)
1942 if [ -z "$HOST_ARCH" ]; then
1943 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1944 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1945 _ 'cook: %s' "$error"
1946 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1947 _ 'Cook skip: %s' "$error" | log
1948 newline
1949 broken; exit 1
1950 fi ;;
1951 esac
1953 # Some packages are not included in some arch or fail to cross compile.
1954 : ${HOST_ARCH=i486}
1955 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1956 # Handle arm{v6hf,v7,..}
1957 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1958 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1959 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1960 _ 'cook: %s' "error"
1961 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1962 _ 'Cook skip: %s' "$error" | log
1963 sed -i "/^${pkg}$/d" $broken
1964 newline
1965 exit 0
1966 fi
1968 # Skip blocked, 3 lines also for the Cooker.
1969 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1970 die 'Package "%s" is blocked' "$pkg"
1972 try_aufs_chroot "$@"
1974 # Log and source receipt.
1975 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1976 echo "cook:$pkg" > $command
1978 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1980 while read cmd duration start; do
1981 [ $(($start + $duration)) -lt $(date +%s) ] &&
1982 echo "sed -i '/^$cmd $duration/d' $cooktime"
1983 done < $cooktime | sh
1985 # Display and log info if cook process stopped.
1986 # FIXME: gettext not working (in single quotes) here!
1987 trap '_ "\n\nCook stopped: control-C\n\n" | \
1988 tee -a $LOGS/$pkg.log' INT
1990 update_split_db
1992 # Handle --options
1993 case "$2" in
1994 --install|-i)
1995 inst='yes' ;;
1997 --pack)
1998 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
1999 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
2000 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -rf $LOGS/$pkg-pack.log
2001 sed -i '$ s|$| (packing)|' $activity
2002 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
2003 clean_log "$pkg-pack"
2004 time=$(($(date +%s) - $time))
2005 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
2006 put_status $pkg Done
2007 rm -f $command
2008 exit 0 ;;
2010 --trials|-t)
2011 trials='yes' ;;
2012 esac
2014 # Rotate log
2015 for i in $(seq 9 -1 1); do
2016 j=$(($i - 1))
2017 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2018 done
2019 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2021 # Check if wanted is built now so we have separate log files.
2022 for wanted in $WANTED ; do
2023 if grep -q "^$wanted$" $blocked; then
2024 broken
2025 rm -f $command
2026 die 'WANTED package "%s" is blocked' "$wanted"
2027 fi
2028 if grep -q "^$wanted$" $broken; then
2029 broken
2030 rm -f $command
2031 die 'WANTED package "%s" is broken' "$wanted"
2032 fi
2033 if [ ! -d "$WOK/$wanted/install" ]; then
2034 cook "$wanted" || { broken; exit 1; }
2035 fi
2036 done
2038 # Cook and pack or exit on error and log everything.
2039 ((((cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq))
2040 rq=$? # the return code of `cookit $@` above command
2042 # Remove build dependencies both when `cookit` done or fail
2043 remove_deps | tee -a $LOGS/$pkg.log
2044 cookit_quality
2046 # Log and stop if `cookit` fails
2047 if [ $rq -eq 1 ]; then
2048 debug_info | tee -a $LOGS/$pkg.log
2049 put_status $pkg Failed
2050 rm -f $command
2051 broken; exit 1
2052 fi
2054 # Proceed only if `cookit` return code is zero-OK
2055 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2057 clean_log
2059 # Exit if any error in packing.
2060 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
2061 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2062 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2063 debug_info | tee -a $LOGS/$pkg.log
2064 put_status $pkg Failed
2065 rm -f $command
2066 broken; exit 1
2067 fi
2069 # Create an XML feed
2070 gen_rss
2072 # Time and summary
2073 time=$(($(date +%s) - $time))
2074 summary | tee -a $LOGS/$pkg.log
2075 newline
2077 # We may want to install/update (outside aufs jail!).
2078 [ -s /aufs-umount.sh ] || install_package
2080 put_status $pkg Done
2082 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2083 # If you want automation, use the Cooker Build Bot.
2084 rm -f $command
2085 ;;
2086 esac
2088 exit 0