cookutils view cook @ rev 1010
Major release. cook: fix remove_already_packed(), now it works inside the set; package cooking stops if cookit() return non-zero return code while processing compile_rules() from receipt; lighttpd/index.cgi: 'files' page reworked, now it knows about the sets; finally fixed bug when out-of-tree files (such as pulled into $fs NOT from $install) mistakenly displayed as "unpackaged".
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Wed Nov 22 19:51:01 2017 +0200 (2017-11-22) |
parents | 845d62611d92 |
children | 51460e8c74d7 |
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 # QA: check a receipt consistency before building.
101 receipt_quality() {
102 _ 'QA: checking package receipt...'
104 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE; do
105 unset value
106 value="$(. $receipt; eval echo \$$var)"
107 # L10n: QA is quality assurance
108 [ -n "$value" ] || die 'QA: empty variable: %s' "$var=\"\""
110 case "$var" in
111 CATEGORY)
112 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
113 if ! echo " $valid " | grep -q " $value "; then
114 _ 'QA: unknown category "%s"' "$value"
115 die 'Please, use one of: %s' "$valid"
116 fi
117 ;;
118 WEB_SITE)
119 # We don't check WGET_URL since if dl is needed it will fail.
120 # Break also if we're not online. Here error is not fatal.
121 if ifconfig | grep -A1 '^[a-z]*[0-9]' | fgrep -q 'addr:' && \
122 ! busybox wget -T 12 --spider $value 2>/dev/null; then
123 _ 'QA: unable to reach "%s"' "$value"
124 fi
125 ;;
126 esac
127 done
128 }
131 # Paths used in receipt and by cook itself.
133 set_paths() {
134 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
135 if [ -f "$WOK/linux/receipt" ]; then
136 kvers=$(. $WOK/linux/receipt; echo $VERSION)
137 kbasevers=$(echo $kvers | cut -d. -f1,2)
138 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
139 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
140 kbasevers=$(echo $kvers | cut -d. -f1,2)
141 fi
143 # Python version
144 [ -f "$WOK/python/receipt" ] && pyvers=$(. $WOK/python/receipt; echo $VERSION)
145 # Perl version for some packages needed it
146 [ -f "$WOK/perl/receipt" ] && perlvers=$(. $WOK/perl/receipt; echo $VERSION)
148 pkgdir="$WOK/$pkg"
149 . "$pkgdir/receipt"
150 basesrc="$pkgdir/source"
151 tmpsrc="$basesrc/tmp"
152 src="$basesrc/$PACKAGE-$VERSION"
153 taz="$pkgdir/taz"
154 pack="$taz/${1:-$PACKAGE}-$VERSION$EXTRAVERSION" # v2: multiple taz/* folders
155 fs="$pack/fs"
156 stuff="$pkgdir/stuff"
157 install="$pkgdir/install"
159 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
160 lzma_tarball="$pkgsrc.tar.lzma"
162 [ -n "$PATCH" -a -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
164 if [ -n "$WANTED" ]; then
165 basesrc="$WOK/$WANTED/source"
166 src="$basesrc/$WANTED-$VERSION"
167 install="$WOK/$WANTED/install"
168 wanted_stuff="$WOK/$WANTED/stuff"
169 fi
171 [ -n "$SOURCE" ] && source_stuff="$WOK/$SOURCE/stuff"
173 # Old way compatibility.
174 _pkg="$install"
175 }
178 # Create source tarball when URL is a SCM.
180 create_tarball() {
181 local tarball
182 tarball="$pkgsrc.tar.bz2"
183 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
184 _ 'Creating tarball "%s"' "$tarball"
185 if [ -n "$LZMA_SRC" ]; then
186 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
187 LZMA_SRC=''
188 else
189 tar -cjf $tarball $pkgsrc || exit 1
190 mv $tarball $SRC; rm -rf $pkgsrc
191 fi
192 TARBALL="$tarball"
193 }
196 # Get package source. For SCM we are in cache so clone here and create a
197 # tarball here.
199 get_source() {
200 local url
201 url=${WGET_URL#*|}
202 set_paths
203 pwd=$(pwd)
204 case "$WGET_URL" in
205 http://*|ftp://*|https://*)
206 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
207 wget -T 60 -c -O $SRC/$TARBALL $WGET_URL ||
208 wget -T 60 -c -O $SRC/$TARBALL $url ||
209 die 'ERROR: %s' "wget $WGET_URL"
210 ;;
212 hg*|mercurial*)
213 _ 'Getting source from %s...' 'Hg'
214 _ 'URL: %s' "$url"
215 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
216 if [ -n "$BRANCH" ]; then
217 _ 'Hg branch: %s' "$BRANCH"
218 hg clone $url --rev $BRANCH $pkgsrc ||
219 die 'ERROR: %s' "hg clone $url --rev $BRANCH"
220 else
221 hg clone $url $pkgsrc || die 'ERROR: %s' "hg clone $url"
222 fi
223 rm -rf $pkgsrc/.hg
224 create_tarball
225 ;;
227 git*)
228 _ 'Getting source from %s...' 'Git'
229 _ 'URL: %s' "$url"
230 cd $SRC
231 git clone $url $pkgsrc || die 'ERROR: %s' "git clone $url"
232 if [ -n "$BRANCH" ]; then
233 _ 'Git branch: %s' "$BRANCH"
234 cd $pkgsrc; git checkout $BRANCH; cd ..
235 fi
236 cd $SRC
237 create_tarball
238 ;;
240 cvs*)
241 mod=$PACKAGE
242 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
243 _ 'Getting source from %s...' 'CVS'
244 _ 'URL: %s' "$url"
245 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
246 _ 'Cloning to "%s"' "$pwd/$mod"
247 cvs -d:$url co $mod && mv $mod $pkgsrc
248 create_tarball
249 ;;
251 svn*|subversion*)
252 _ 'Getting source from %s...' 'SVN'
253 _ 'URL: %s' "$url"
254 if [ -n "$BRANCH" ]; then
255 echo t | svn co $url -r $BRANCH $pkgsrc
256 else
257 echo t | svn co $url $pkgsrc
258 fi
259 create_tarball
260 ;;
262 bzr*)
263 _ 'Getting source from %s...' 'bazaar'
264 cd $SRC
265 pkgsrc=${url#*:}
266 if [ -n "$BRANCH" ]; then
267 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
268 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
269 else
270 echo "bzr -Ossl.cert_reqs=none branch $url"
271 bzr -Ossl.cert_reqs=none branch $url
272 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
273 _ "Don't forget to add to receipt:"
274 echo -e "BRANCH=\"$BRANCH\"\n"
275 fi
276 mv $pkgsrc $pkgsrc-$BRANCH
277 pkgsrc="$pkgsrc-$BRANCH"
278 create_tarball
279 ;;
281 *)
282 broken; die 'ERROR: Unable to handle "%s"' "$WGET_URL"
283 ;;
284 esac
285 }
288 # Extract source package.
290 extract_source() {
291 if [ ! -s "$SRC/$TARBALL" ]; then
292 local url
293 url="$MIRROR_URL/sources/packages"
294 url="$url/${TARBALL:0:1}/$TARBALL"
295 _ 'Getting source from %s...' 'mirror'
296 _ 'URL: %s' "$url"
297 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
298 fi
299 _ 'Extracting source archive "%s"' "$TARBALL"
300 case "$TARBALL" in
301 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
302 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
303 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
304 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
305 *.tar) tar -xf $SRC/$TARBALL ;;
306 *.zip|*.xpi) unzip -o $SRC/$TARBALL 2>/dev/null >&2;;
307 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
308 tar -xf $SRC/$TARBALL 2>/dev/null;;
309 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
310 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
311 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
312 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
313 *) cp $SRC/$TARBALL $(pwd) ;;
314 esac
315 }
318 # Display time.
320 disp_time() {
321 local sec div min
322 sec="$1"
323 div=$(( ($1 + 30) / 60))
324 case $div in
325 0) min='';;
326 # L10n: 'm' is for minutes (approximate cooking time)
327 *) min=$(_n ' ~ %dm' "$div");;
328 esac
330 # L10n: 's' is for seconds (cooking time)
331 _ '%ds%s' "$sec" "$min"
332 }
335 # Display cooked package summary.
337 summary() {
338 set_paths
339 cd $WOK/$pkg
340 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
341 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
342 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
344 _ 'Summary for: %s' "$PACKAGE $VERSION$EXTRAVERSION"
345 separator
347 # L10n: keep the same width of translations to get a consistent view
348 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
349 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
350 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
351 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
352 _ 'Cook time : %s' "$(disp_time "$time")"
353 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
354 _ 'Host arch : %s' "$ARCH"
356 separator -
357 _ ' # : Packed : Compressed : Files : Package name'
358 separator -
359 pkgi=1
360 for i in $(all_names); do
361 fs=$(du -sh $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION | awk '{print $1}')
362 pkgname="$i-$VERSION$EXTRAVERSION.tazpkg"
363 size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
364 files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/files.list)
365 printf "%2d : %7s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
366 pkgi=$((pkgi + 1))
367 done
368 separator
369 }
372 # Display debugging error info.
374 debug_info() {
375 title 'Debug information'
376 # L10n: specify your format of date and time (to help: man date)
377 # L10n: not bad one is '+%x %R'
378 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
379 if [ -n "$time" ]; then
380 times="$(($(date +%s) - $time))"
381 _ 'Wasted time : %s' "$(disp_time "$times")"
382 fi
383 for error in \
384 ERROR 'No package' "cp: can't" "can't open" "can't cd" \
385 'error:' 'fatal error:' 'undefined reference to' \
386 'Unable to connect to' 'link: cannot find the library' \
387 'CMake Error' ': No such file or directory' \
388 'Could not read symbols: File in wrong format'
389 do
390 # format "line number:line content"
391 fgrep -n "$error" $LOGS/$pkg.log
392 done > $LOGS/$pkg.log.debug_info 2>&1
393 # sort by line number, remove duplicates
394 sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
395 rm -f $LOGS/$pkg.log.debug_info
396 footer
397 }
400 # A bit smarter function than the classic `cp` command
402 scopy() {
403 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
404 cp -a "$1" "$2" # copy generic files
405 else
406 cp -al "$1" "$2" # copy hardlinks
407 fi
408 }
411 # Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
412 # We use standard paths, so some packages need to copy these files with the
413 # receipt and genpkg_rules.
414 # This function executes inside the packaging process, before compressor call.
416 copy_generic_files() {
417 # Proceed only for "main" package (for v2), and for any packages (v1)
418 [ "$pkg" == "$PACKAGE" ] || return 0
420 # $LOCALE is set in cook.conf
421 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
422 if [ -d "$install/usr/share/locale" ]; then
423 mkdir -p "$fs/usr/share/locale"
424 for i in $LOCALE; do
425 if [ -d "$install/usr/share/locale/$i" ]; then
426 cp -r $install/usr/share/locale/$i $fs/usr/share/locale
427 fi
428 done
429 fi
430 fi
432 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
433 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
434 if [ -d "$install/usr/share/pixmaps" ]; then
435 mkdir -p "$fs/usr/share/pixmaps"
436 for i in png xpm; do
437 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
438 cp -r $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
439 done
440 fi
441 fi
443 # Desktop entry (.desktop).
444 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
445 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
446 if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
447 mkdir -p "$fs/usr/share"
448 cp -r $install/usr/share/applications $fs/usr/share
449 fi
450 fi
451 }
454 # Copy pixmaps, desktop files and licenses from $stuff to $install.
455 # This function executes after the main compile_rules() is done.
457 copy_generic_stuff() {
458 # Custom or homemade PNG pixmap can be in stuff.
459 if [ -f "$stuff/$PACKAGE.png" ]; then
460 mkdir -p $install/usr/share/pixmaps
461 cp $stuff/$PACKAGE.png $install/usr/share/pixmaps
462 fi
464 # Homemade desktop file(s) can be in stuff.
465 if [ -d "$stuff/applications" ]; then
466 mkdir -p $install/usr/share
467 cp -r $stuff/applications $install/usr/share
468 fi
469 if [ -f "$stuff/$PACKAGE.desktop" ]; then
470 mkdir -p $install/usr/share/applications
471 cp $stuff/$PACKAGE.desktop $install/usr/share/applications
472 fi
474 # Add custom licenses
475 if [ -d "$stuff/licenses" ]; then
476 mkdir -p $install/usr/share/licenses
477 cp -r $stuff/licenses $install/usr/share/licenses/$PACKAGE
478 fi
479 }
482 # Update installed.cook.diff
484 update_installed_cook_diff() {
485 # If a cook failed deps are removed.
486 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
487 cd $CACHE
488 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
489 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
490 deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
491 }
494 # Remove installed deps.
496 remove_deps() {
497 # Now remove installed build deps.
498 diff='/tmp/installed.cook.diff'
499 [ -s "$diff" ] || return
501 deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
502 nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
503 newline
504 _n 'Build dependencies to remove:'; echo " $nb"
505 [ -n "$root" ] && echo "root=\"$root\""
506 {
507 _n 'Removing:'
508 for dep in $deps; do
509 echo -n " $dep"
510 # Do not waste time uninstalling the packages if we are inside
511 # aufs chroot - unmounting chroot will "uninstall" all packages.
512 [ -s /aufs-umount.sh ] ||
513 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
514 done
515 } | busybox fold -sw80
516 newline; newline
517 # Keep the last diff for debug and info.
518 mv -f $diff $CACHE/installed.diff
519 }
522 # Automatically patch the sources.
524 patchit() {
525 [ -f "$stuff/patches/series" ] || return
527 IFS=$'\n'
528 while read i; do
529 patchname=$(echo ${i%%#*} | cut -d' ' -f1) # allow comments (anything after the # or space)
530 case $patchname in # allow patch options in form <options_no_spaces>|<file_name>
531 *\|*) patchopts="${patchname%|*}"; patchname="${patchname#*|}";;
532 *) patchopts='-Np1';;
533 esac
534 [ -n "$patchname" ] || continue # allow empty lines
535 [ -f "$src/done.$patchname" ] && continue # already applied (useful with `cook --continue`)
536 newline
537 _ 'Applying patch %s' "$patchname"
538 patch $patchopts -i $stuff/patches/$patchname | sed 's|^| |'
539 touch $src/done.$patchname
540 done < $stuff/patches/series
541 newline
542 unset IFS
543 }
546 # Check source tarball integrity.
548 check_integrity() {
549 for i in sha1 sha3 sha256 sha512 md5; do
550 I=$(echo $i | tr 'a-z' 'A-Z')
551 eval sum=\$TARBALL_$I
552 if [ -n "$sum" ]; then
553 newline
554 _ 'Checking %ssum of source tarball...' "$i"
555 echo "$sum $SRC/$TARBALL" | ${i}sum -c || exit 1
556 fi
557 done
558 newline
559 }
562 # The main cook function.
564 cookit() {
565 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
566 _ 'ERROR: Broken setup. Abort.'
567 return
568 fi
570 title 'Cook: %s' "$PACKAGE $VERSION"
571 set_paths
573 # Handle cross-tools.
574 case "$ARCH" in
575 arm*|x86_64)
576 # CROSS_COMPILE is used by at least Busybox and the kernel to set
577 # the cross-tools prefix. Sysroot is the root of our target arch
578 sysroot="$CROSS_TREE/sysroot"
579 tools="$CROSS_TREE/tools"
580 # Set root path when cross compiling. ARM tested but not x86_64
581 # When cross compiling we must install build deps in $sysroot.
582 arch="-$ARCH"
583 root="$sysroot"
584 _ '%s sysroot: %s' "$ARCH" "$sysroot"
585 _ 'Adding "%s" to PATH' "$tools/bin"
586 export PATH="$PATH:$tools/bin"
587 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
588 export CROSS_COMPILE="$HOST_SYSTEM-"
589 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
590 if [ "$ARCH" == 'x86_64' ]; then
591 export CC="$HOST_SYSTEM-gcc -m64"
592 export CXX="$HOST_SYSTEM-g++ -m64"
593 else
594 export CC="$HOST_SYSTEM-gcc"
595 export CXX="$HOST_SYSTEM-g++"
596 fi
597 export AR="$HOST_SYSTEM-ar"
598 export AS="$HOST_SYSTEM-as"
599 export RANLIB="$HOST_SYSTEM-ranlib"
600 export LD="$HOST_SYSTEM-ld"
601 export STRIP="$HOST_SYSTEM-strip"
602 export LIBTOOL="$HOST_SYSTEM-libtool"
603 ;;
604 esac
606 [ -n "$QA" ] && receipt_quality
608 cd $pkgdir
609 [ -z "$continue" ] && rm -rf source 2>/dev/null
610 rm -rf install taz 2>/dev/null
612 # Disable -pipe if less than 512 MB free RAM.
613 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
614 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
615 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
616 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
617 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
618 fi
619 unset free
621 # Export flags and path to be used by make and receipt.
622 DESTDIR="$pkgdir/install"
623 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
624 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
625 #LDFLAGS
627 # BUILD_DEPENDS may vary depending on the ARCH
628 case "$ARCH" in
629 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
630 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
631 esac
633 # Check for build deps and handle implicit depends of *-dev packages
634 # (ex: libusb-dev :: libusb).
635 # rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
636 # touch $CACHE/installed.local $CACHE/installed.web
637 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
638 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
640 # Get the list of installed packages
641 cd $root$INSTALLED; ls > $CACHE/installed.list
643 for action in check install; do
644 for dep in $BUILD_DEPENDS; do
645 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
646 for i in $dep $implicit; do
647 # Skip if package already installed
648 [ -f "$root$INSTALLED/$i/receipt" ] && continue
650 case $action in
651 check)
652 # Search for local package or local provided-package
653 name=$(awk -F$'\t' -vpkg="$i" '{
654 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
655 }' "$PKGS/packages.info")
656 if [ -z "$name" ]; then
657 # Search for package in mirror
658 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
659 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
660 fi
661 ;;
662 install)
663 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
664 ;;
665 esac
666 done
667 done
668 done
670 # # Have we a missing build dep to cook?
671 # if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
672 # _ 'Auto cook config is set: %s' "$AUTO_COOK"
673 # cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
674 # for i in $(uniq $CACHE/missing.dep); do
675 # (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
676 # tee -a $LOGS/$PACKAGE.log.$$
677 # # programmers: next two messages are exact copy from remove_deps()
678 # togrep1=$(_n 'Build dependencies to remove:')
679 # togrep2=$(_n 'Removing:')
680 # cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
681 # fgrep $togrep1 $LOGS/$i.log && \
682 # fgrep $togrep2 $LOGS/$i.log && newline) | \
683 # tee -a $LOGS/$PACKAGE.log.$$ && break
684 # done
685 # rm -f $CACHE/missing.dep
686 # mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
687 # fi
688 #
689 # # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
690 # # is enabled and cook fails we have ERROR in log, if no auto cook we have
691 # # missing dep in cached file.
692 # lerror=$(_n 'ERROR')
693 # if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
694 # [ -s "$CACHE/missing.dep" ] && nb=$(wc -l < $CACHE/missing.dep)
695 # _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
696 # broken; exit 1
697 # fi
698 #
699 # # Install local packages: package-version$arch
700 # cd $PKGS
701 # for i in $(uniq $CACHE/installed.local); do
702 # # _ 'Installing dep (pkg/local): %s' "$i"
703 # tazpkg install $i --root=$root --local --quiet --cookmode
704 # done
705 #
706 # # Install web or cached packages (if mirror is set to $PKGS we only
707 # # use local packages).
708 # for i in $(uniq $CACHE/installed.web); do
709 # # _ 'Installing dep (web/cache): %s' "$i"
710 # tazpkg get-install $i --root=$root --local --quiet --cookmode
711 # done
713 update_installed_cook_diff
715 # Get source tarball and make sure we have source dir named:
716 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
717 # tarball if it exists.
718 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
719 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
720 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
721 LZMA_SRC=''
722 else
723 get_source || { broken; exit 1; }
724 fi
725 fi
726 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
727 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
728 if ! extract_source ; then
729 get_source
730 extract_source || { broken; exit 1; }
731 fi
732 if [ -n "$LZMA_SRC" ]; then
733 cd $pkgdir/source
734 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
735 mv tmp tmp-1; mkdir tmp
736 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
737 fi
738 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
739 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
740 fi
741 fi
743 cd $pkgdir/source/tmp
744 # Some archives are not well done and don't extract to one dir (ex lzma).
745 files=$(ls | wc -l)
746 [ "$files" -eq 1 -a -d "$(ls)" ] &&
747 mv * ../$PACKAGE-$VERSION
748 [ "$files" -eq 1 -a -f "$(ls)" ] &&
749 mkdir -p ../$PACKAGE-$VERSION &&
750 mv * ../$PACKAGE-$VERSION/$TARBALL
751 [ "$files" -gt 1 ] &&
752 mkdir -p ../$PACKAGE-$VERSION &&
753 mv * ../$PACKAGE-$VERSION
754 cd ..; rm -rf tmp
755 fi
757 # Check md5sum (or similar) for sources tarball
758 check_integrity
760 # Libtool shared libs path hack.
761 case "$ARCH" in
762 arm*) cross libhack ;;
763 esac
765 # Compiling all the sets
766 if grep -q ^compile_rules $receipt; then
767 _ 'Executing: %s' 'compile_rules'
768 echo "CFLAGS : $CFLAGS"
769 #echo "LDFLAGS : $LDFLAGS"
770 [ -d "$src" ] && cd $src
771 patchit
773 # Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
774 SETS=$(echo $SPLIT \
775 | awk '
776 BEGIN { RS = " "; FS = ":"; }
777 { print $2; }' \
778 | sort -u \
779 | tr '\n' ' ')
780 SETS=${SETS% } # normalize space
781 # Prepare specified source sets using patched sources
782 [ -n "$SETS" ] &&
783 for set in $SETS; do
784 echo "Preparing set $set" # debug
785 cp -a $src $src-$set
786 done
788 for SET in '' $SETS; do
789 # Switch to the specified source set
790 set_paths
791 local suffix=''
792 [ -n "$SET" ] && suffix="-$SET"
793 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
794 export install="$WOK/$pkg/install$suffix"
795 export DESTDIR="$install"
797 if [ -n "$SETS" ]; then
798 if [ -n "$SET" ]; then
799 title "Switching to the set '$SET'"
800 else
801 title "Switching to the default set"
802 fi
803 echo "src : $src"
804 echo "install: $install"
805 fi
806 cd $src
807 echo
809 [ -d "$install" ] && rm -r $install
810 mkdir -p $install
812 compile_rules $@ || { broken; exit 1; }
814 # Stay compatible with _pkg
815 [ -d "$src/_pkg" ] && mv $src/_pkg $install
817 copy_generic_stuff
819 # Actions to do after compiling the package
820 # Skip all for split packages (already done in main package)
821 if [ -z "$WANTED" ]; then
822 footer
823 export COOKOPTS ARCH install
824 @@PREFIX@@/libexec/cookutils/compressor install
825 fi
826 done
827 fi
828 footer
830 # Execute testsuite.
831 if grep -q ^testsuite $receipt; then
832 title 'Running testsuite'
833 testsuite $@ || { broken; exit 1; }
834 footer
835 fi
837 update_installed_cook_diff force
838 }
841 # Cook quality assurance.
843 cookit_quality() {
844 while true; do
845 [ ! -d "$WOK/$pkg/install" -a -z "$WANTED" ] || break
846 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
847 [ "$trials" == 'yes' ] || break
848 title "Interactive mode"
849 # TODO: allow commands:
850 # q - quit; v - edit receipt here using vi;
851 # s - search for package containing package;
852 # <package name> - install package; [Enter] - retry
853 _ 'You may install the packages here and/or edit the receipt there.'
854 newline
855 while true; do
856 _n 'Install the package? [name/N] '; read answer
857 [ -n "$answer" ] || break
858 tazpkg -gi $answer --root=$root --local --quiet --cookmode
859 done
860 newline
861 _n 'Try again? [Y/n] '; read answer
862 [ "$answer" == 'n' ] && break
863 # here you may append log if you want (">>" instead of last ">")
864 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
865 done
867 [ "${COOKOPTS/skip-log-errors/}" != "$COOKOPTS" ] && return 0
869 # ERROR can be echoed any time in cookit()
870 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
871 grep -Eq "(^ERROR|undefined reference to)" ; then
872 debug_info | tee -a $LOGS/$pkg.log
873 put_status $pkg Failed
874 rm -f $command
875 broken; exit 1
876 fi
877 }
880 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
881 # but it doesn't handle EXTRAVERSION.
883 packit() {
884 set_paths "$1"
885 PACKAGE="${1:-$PACKAGE}"
887 # Handle cross compilation
888 case "$ARCH" in
889 arm*|x86_64) arch="-$ARCH" ;;
890 esac
892 title 'Pack: %s' "$PACKAGE $VERSION$arch"
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")"
1004 update_packages_db
1005 }
1008 # Calculate release checksum: usually it does not change on "just recook".
1009 # Release checksum is md5sum of file containing md5sums of:
1010 # a) all files, b) receipt, and c) description.txt.
1011 # Md5sum of the package file will change every time because of embedded timestamps;
1012 # release checksum based only on files content, and will change only when files change.
1013 # (Pitfall: ownership and permissions...)
1015 release_checksum() {
1016 local pack=$1
1017 local rsum_file=$(mktemp)
1019 cp $pack/md5sum $rsum_file
1020 md5sum $pack/receipt | sed 's| [^ ]*/| |' >> $rsum_file
1021 [ -e "$pack/description.txt" ] &&
1022 md5sum $pack/description.txt | sed 's| [^ ]*/| |' >> $rsum_file
1024 local rsum=$(md5sum $rsum_file | awk '{print $1}')
1025 rm $rsum_file
1026 local rsumold=$(awk -F$'\t' -vpkg="$PACKAGE" '
1027 {if ($1 == pkg) { print $9; exit; }}' $PKGS/packages.info)
1029 [ "$rsum" == "$rsumold" ] && rsum=''
1031 echo $rsum
1032 }
1035 # Verify package quality and consistency.
1037 packit_quality() {
1038 #action 'QA: checking for broken link...'
1039 #link=$(find $fs/usr -type l -follow)
1040 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
1041 #status
1043 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ]; then
1044 # Exit if any error found in log file.
1045 if fgrep -q ^ERROR $LOGS/$pkg.log; then
1046 rm -f $command
1047 broken; exit 1
1048 fi
1049 fi
1051 if [ "${COOKOPTS/empty-pkg/}" == "$COOKOPTS" ]; then
1052 action 'QA: checking for empty package...'
1053 if [ ! -s "$pack/files.list" -a "$CATEGORY" != 'meta' ]; then
1054 broken
1055 rm -f $command
1056 false; status
1057 die 'ERROR: empty package'
1058 fi
1059 :; status
1060 fi
1063 # Find and remove old package(s) only if "release checksum" has changed
1064 rsum=$(release_checksum $pack)
1065 if [ -n "$rsum" ]; then
1066 old_file=$(awk -F$'\t' -vname="$PACKAGE" '{
1067 if ($1 == name) printf("%s-%s.tazpkg", $1, $2);
1068 }' $PKGS/packages.info)
1069 if [ -f "$PKGS/$old_file" ]; then
1070 action 'Removing old package "%s"' "$old_file"
1071 rm -f "$PKGS/$old_file"
1072 status
1073 fi
1074 # package changed, substitute old package by new
1075 mv -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg $PKGS
1076 else
1077 # package not changed, remove new package
1078 rm -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1079 fi
1081 sed -i "/^${pkg}$/d" $broken
1082 #action 'Removing source tree...'
1083 #rm -f $WOK/$pkg/source; status
1084 }
1087 # Return all the names of packages bundled in this receipt
1089 all_names() {
1090 # Get package names from $SPLIT variable
1091 local split=$(echo $SPLIT \
1092 | awk '
1093 BEGIN { RS = " "; FS = ":"; }
1094 { print $1; }' \
1095 | tr '\n' ' ')
1096 local split_space=" $split "
1097 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
1098 # For receipts v1: $SPLIT may present in the $WANTED package,
1099 # but split packages have their own receipts
1100 echo $PACKAGE
1101 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
1102 # $PACKAGE included somewhere in $SPLIT (probably in the end).
1103 # We should build packages in the order defined in the $SPLIT.
1104 echo $split
1105 else
1106 # We'll build the $PACKAGE, then all defined in the $SPLIT.
1107 echo $PACKAGE $split
1108 fi
1109 }
1112 # v2: pack all packages using compiled files
1114 packall() {
1115 set_paths
1116 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1117 for i in $(all_names); do
1118 unset TAGS DEPENDS CAT CONFIG_FILES PROVIDE SUGGESTED DATABASE_FILES TAZPANEL_DAEMON
1119 packit $i
1120 done
1121 else
1122 packit
1123 fi
1124 }
1127 # Reverse "cat" command: prints input lines in the reverse order
1129 tac() {
1130 sed '1!G;h;$!d' $1
1131 }
1134 # Update chroot with freshly rebuilt package: keep env up-to-date.
1136 update_chroot() {
1137 local PACKAGE="$pkg"
1138 for i in $(all_names); do
1139 if [ -d "$root$INSTALLED/$i" ]; then
1140 . /etc/slitaz/cook.conf
1141 . $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt
1142 _ 'Updating %s chroot environment...' "$ARCH"
1143 _ 'Updating chroot: %s' "$i ($VERSION$EXTRAVERSION$arch)" | log
1144 cd $PKGS
1145 tazpkg install $i-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1146 fi
1147 done
1148 }
1151 # Install package on --inst or update the chroot.
1153 install_package() {
1154 set_paths
1155 case "$ARCH" in
1156 arm*|x86_64)
1157 arch="-$ARCH"
1158 root="$CROSS_TREE/sysroot" ;;
1159 esac
1160 # Install package if requested but skip install if target host doesn't
1161 # match build system or it will break the build chroot.
1162 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1163 if [ -n "$inst" -a "$build" == "$ARCH" ]; then
1164 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1165 cd $PKGS
1166 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1167 else
1168 broken
1169 die 'Unable to install package, build has failed.'
1170 fi
1171 fi
1173 update_chroot
1174 }
1177 # remove chroot jail
1179 umount_aufs() {
1180 tac ${1}rw/aufs-umount.sh | sh
1181 rm -rf ${1}rw
1182 umount ${1}root
1183 rmdir ${1}r*
1184 }
1187 # Launch the cook command into a chroot jail protected by aufs.
1188 # The current filesystems are used read-only and updates are
1189 # stored in a separate branch.
1191 try_aufs_chroot() {
1193 base="/dev/shm/aufsmnt$$"
1195 # Can we setup the chroot? Is it already done?
1196 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1197 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1198 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1199 grep -q ^aufs /proc/modules || modprobe aufs 2> /dev/null || return
1200 mkdir ${base}root ${base}rw || return
1202 _ 'Setup aufs chroot...'
1204 # Sanity check
1205 for i in / /proc /sys /dev/shm /home ; do
1206 case " $AUFS_MOUNTS " in
1207 *\ $i\ *) ;;
1208 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1209 esac
1210 done
1211 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1212 mount --bind $mnt ${base}root$mnt
1213 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1214 _ 'Aufs mount failure'
1215 umount ${base}root
1216 rm -rf ${base}r*
1217 return
1218 fi
1219 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1220 done
1221 trap "umount_aufs ${base}" INT
1223 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1224 status=$?
1226 _ 'Leaving aufs chroot...'
1227 umount_aufs $base
1228 # Install package outside the aufs jail
1229 install_package
1230 exit $status
1231 }
1234 # Encode predefined XML entities
1236 xml_ent() {
1237 sed -e 's|&|\&|g; s|<|\<|g; s|>|\>|g; s|"|\"|g' -e "s|'|\'|g"
1238 }
1241 # Create a XML feed for freshly built packages.
1243 gen_rss() {
1244 pubdate=$(date '+%a, %d %b %Y %X')
1245 cat > $FEEDS/$pkg.xml <<EOT
1246 <item>
1247 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1248 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1249 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1250 <pubDate>$pubdate</pubDate>
1251 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1252 </item>
1253 EOT
1254 }
1257 # Truncate stdout log file to $1 Mb.
1259 loglimit() {
1260 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1261 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1262 else
1263 tee /dev/stderr
1264 fi
1265 }
1268 #
1269 # Receipt functions to ease packaging
1270 #
1272 get_dev_files() {
1273 action 'Getting standard devel files...'
1274 mkdir -p $fs/usr/lib
1275 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1276 cp -a $install/usr/lib/*a $fs/usr/lib
1277 cp -a $install/usr/include $fs/usr
1278 status
1279 }
1282 # Function to use in compile_rules() to copy man page from $src to $install
1284 cook_pick_manpages() {
1285 local name section
1286 action 'Copying man pages...'
1288 for i in $@; do
1289 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1290 section=${name##*/}; section=${section##*.}
1291 mkdir -p $install/usr/share/man/man$section
1292 scopy $i $install/usr/share/man/man$section
1293 done
1294 status
1295 }
1298 # Function to use in compile_rules() to copy documentation from $src to $install
1300 cook_pick_docs() {
1301 local docdir="$install/usr/share/doc/$PACKAGE-$VERSION"
1302 action 'Copying documentation...'
1303 mkdir -p $docdir
1304 cp -r $@ $docdir
1305 chmod -R a+r $docdir
1306 status
1307 }
1310 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1312 cook_copy_files() {
1313 action 'Copying files...'
1314 cd $install
1315 local i j
1316 IFS=$'\n'
1317 for i in $@; do
1318 for j in $(find . -name $i ! -type d); do
1319 mkdir -p $fs$(dirname ${j#.})
1320 scopy $j $fs$(dirname ${j#.})
1321 done
1322 done
1323 cd - >/dev/null
1324 status
1325 }
1328 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1330 cook_copy_folders() {
1331 action 'Copying folders...'
1332 cd $install
1333 local i j
1334 IFS=$'\n'
1335 for i in $@; do
1336 for j in $(find . -name $i -type d); do
1337 mkdir -p $fs$(dirname ${j#.})
1338 cp -a $j $fs$(dirname ${j#.})
1339 done
1340 done
1341 cd - >/dev/null
1342 status
1343 }
1346 # Remove from current $fs files that are already packed (for receipts v2).
1347 # Note: the order in $SPLIT is very important.
1348 # Note 2: working in the current set.
1350 remove_already_packed() {
1351 local i j
1352 neighbors=$(
1353 echo $SPLIT" " \
1354 | awk -F$'\t' -vpkg="$PACKAGE" '
1355 BEGIN { RS = " "; FS = ":"; }
1356 { set[$1] = $2; }
1357 END {
1358 current_set = set[pkg];
1359 for (i in set)
1360 { if (i != pkg && set[i] == current_set) print i; }
1361 }
1362 ')
1363 IFS=$'\n'
1364 for neighbor in $neighbors; do
1365 i="$taz/$neighbor-$VERSION$EXTRAVERSION/files.list"
1366 [ -e "$i" ] || continue
1367 while read j; do
1368 [ -f $fs$j -o -h $fs$j ] || continue
1369 rm $fs$j
1370 rmdir --parents --ignore-fail-on-non-empty $fs$(dirname $j)
1371 done < $i
1372 done
1373 unset IFS
1374 }
1377 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1378 # (default: 16 and 48) from $install to $fs
1380 cook_copy_icons() {
1381 local sizes=$@ i j
1382 action 'Copying hicolor icons...'
1383 [ -d "$fs/usr/share/icons/hicolor" ] && rm -rf "$fs/usr/share/icons/hicolor"
1384 mkdir -p $fs/usr/share/icons/hicolor
1385 for i in ${sizes:-16 48}; do
1386 j="${i}x$i"; [ "$i" == 'scalable' ] && j="$i"
1387 [ ! -e "$install/usr/share/icons/hicolor/$j" ] ||
1388 scopy $install/usr/share/icons/hicolor/$j \
1389 $fs/usr/share/icons/hicolor
1390 done
1391 status
1392 }
1395 # Common function to copy files, folders and patterns
1397 copy() {
1398 action 'Copying folders and files...'
1399 local i j k filelist=$(mktemp) folderlist=$(mktemp)
1401 # Get set name for specified package from $SPLIT variable
1402 local set=$(echo $SPLIT \
1403 | awk -vpkg="$PACKAGE" '
1404 BEGIN { RS = " "; FS = ":"; }
1405 { if ($1 == pkg && $2) { print "-" $2; exit; } }')
1406 # Change set, make filelist and folderlist for new set
1407 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$set"
1408 export install="$WOK/$pkg/install$set"
1409 export DESTDIR="$install"
1410 IFS=$'\n'
1411 cd $install
1412 find ! -type d | sed 's|\.||' > $filelist
1413 find -type d | sed 's|\.||' > $folderlist
1415 for i in $@; do
1416 case $i in
1417 @std)
1418 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1419 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /\.pri$/d; /bin\/.*-config$/d;
1420 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1421 /\/Makefile.*/d; /\.inc$/d; /\/include\//d;
1422 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1423 /\/share\/devhelp\//d; /\/share\/locale\//d;
1424 /\/share\/bash-completion\//d; /\/lib\/systemd\//d;
1425 /\/fonts\.scale$/d; /\/fonts\.dir$/d;
1426 /\/share\/appdata\//d; /\/share\/help\//d;
1427 /\/share\/icons\/hicolor\/[12356][1245][268]*x[12356][1245][268]*\//d; # 22, 24, 32, 64, 128, 256, 512
1428 ' $filelist
1429 ;;
1430 @dev)
1431 # Copy "developer files"
1432 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.la$/p; /\.pc$/p; /\.pri$/p; /bin\/.*-config$/p;
1433 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1434 /\/Makefile.*/p; /\.inc$/p; /\/include\//p;
1435 ' $filelist
1436 ;;
1437 @rm)
1438 # Quick alias
1439 remove_already_packed
1440 ;;
1441 @ico)
1442 # Quick alias
1443 cook_copy_icons >/dev/null
1444 ;;
1445 */)
1446 # Copy specified folders.
1447 i="${i%/}"
1448 find -type d -path "*/${i#/}" | sed 's|^.||'
1449 ;;
1450 *)
1451 # Copy specified files.
1452 find ! -type d -path "*/${i#/}" | sed 's|^.||'
1453 ;;
1454 esac \
1455 | sort -u \
1456 | while read j; do
1457 mkdir -p $fs$(dirname "$j")
1458 if [ -d "$install$j" ]; then
1459 cp -a "$install$j" $fs$(dirname "$j")
1460 else
1461 scopy "$install$j" $fs$(dirname "$j")
1462 fi
1463 done
1464 # Copy empty directories
1465 case $i in
1466 @std)
1467 while read j; do
1468 case $j in
1469 # always skip empty man & doc folders, because this will end up
1470 # copying all the man pages and docs to the package
1471 */man/*|*/doc/*) continue;;
1472 esac
1473 [ -z "$(ls -A "$install$j")" ] || continue
1474 # directory $j is empty
1475 k="$j"
1476 # make 'ladder' from directories, from root dir to $j
1477 # /a /a/b /a/b/c etc.
1478 while :; do
1479 [ -z "$k" ] && break
1480 echo "$k"
1481 k="${k%/*}"
1482 done \
1483 | tac \
1484 | while read k; do
1485 # copy dir with its original ownership/permissions if it does not exist
1486 [ -d "$fs$k" ] || cp -a "$install$k" "$fs$k"
1487 done
1488 done < $folderlist
1489 ;;
1490 esac
1491 done
1492 cd - >/dev/null
1493 unset IFS
1494 rm $filelist $folderlist
1495 status
1496 }
1499 # Update packages database every time after successful build
1501 update_packages_db() {
1502 # packages.info (unsorted, located near to packages)
1503 local pi="$PKGS/packages.info"
1504 unset_receipt; . $pack/receipt
1505 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1507 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1509 rsum=$(release_checksum $pack)
1510 if [ -n "$rsum" ]; then
1511 _ 'The release checksum has changed.\n'
1513 sed -i "/^$PACKAGE\t/d" $pi # remove old entry
1514 cat >> $pi <<EOT
1515 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $rsum $PROVIDE
1516 EOT
1518 # files.list (uncompressed, unsorted, located in $cache)
1519 local fl="$cache/files.list"
1520 touch $fl
1521 sed -i "/^$PACKAGE: /d" $fl
1522 sed "s/^/$PACKAGE: \0/" $pack/files.list >> $fl
1523 else
1524 _ 'The release checksum has not changed.\n'
1525 fi
1526 }
1529 # Update split.db once for receipt
1531 update_split_db() {
1532 local db="$cache/split.db"
1533 touch $db
1534 sed -i "/^$pkg\t/d" $db
1535 echo -e "$pkg\t$(all_names)" >> $db
1536 }
1539 # Recreate whole split.db from scratch
1541 recreate_split_db() {
1542 # Clean
1543 local db="$cache/split.db"
1544 touch $db
1545 > $db
1547 cd $WOK
1548 for pkg in *; do
1549 [ -f "$WOK/$pkg/receipt" ] || continue
1550 unset PACKAGE SPLIT
1551 . $WOK/$pkg/receipt
1552 echo -e "$PACKAGE\t$(all_names)" >> $db
1553 done
1554 }
1557 # Put the status to the activity log
1559 put_status() {
1560 # $1: package, $2: status, one of 'Done', 'Failed'
1561 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1562 }
1567 #
1568 # Commands
1569 #
1571 # cook <package> --deps
1572 [ -n "$deps" ] && {
1573 @@PREFIX@@/libexec/cookutils/deps $1
1574 exit 0
1575 }
1577 # cook <package> --clean
1578 # cook <package> -c
1579 [ -n "$clean" -o "$2" == '-c' ] && {
1580 action 'Cleaning "%s"' "$1"
1581 cd $WOK/$1; rm -rf install taz source
1582 status; newline
1583 touch $activity # update $activity -> something changed -> update webstat
1584 exit 0
1585 }
1587 # cook <package> --getsrc
1588 # cook <package> -gs
1589 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1590 title 'Getting source for "%s"' "$1"
1591 receipt="$WOK/$pkg/receipt"
1592 check_pkg_in_wok
1593 unset_receipt
1594 . $receipt
1595 get_source
1596 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1597 exit 0
1598 }
1600 # cook <package> --block
1601 # cook <package> -b
1602 [ -n "$block" -o "$2" == '-b' ] && {
1603 action 'Blocking package "%s"' "$1"
1604 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1605 status; newline
1606 touch $activity
1607 exit 0
1608 }
1610 # cook <package> --unblock
1611 # cook <package> -ub
1612 [ -n "$unblock" -o "$2" == '-ub' ] && {
1613 action 'Unblocking package "%s"' "$1"
1614 sed -i "/^$1$/d" $blocked
1615 status; newline
1616 touch $activity
1617 exit 0
1618 }
1623 case "$1" in
1624 usage|help|-u|-h)
1625 usage ;;
1627 list-wok)
1628 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1629 cd $WOK
1630 if [ "$ARCH" != 'i486' ]; then
1631 count=0
1632 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1633 do
1634 unset HOST_ARCH
1635 . ./$pkg
1636 count=$(($count + 1))
1637 colorize 34 "$PACKAGE"
1638 done
1639 else
1640 count=$(ls | wc -l)
1641 ls -1
1642 fi
1643 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1644 ;;
1646 activity)
1647 cat $activity ;;
1649 search)
1650 # Just a simple search function, we don't need more actually.
1651 query="$2"
1652 title 'Search results for "%s"' "$query"
1653 cd $WOK; ls -1 | grep "$query"
1654 footer ;;
1656 setup)
1657 # Setup a build environment
1658 check_root
1659 _ 'Cook: setup environment' | log
1660 title 'Setting up your environment'
1661 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1662 cd $SLITAZ
1663 init_db_files
1664 _ 'Checking for packages to install...'
1665 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1666 # ARCH-setup or 'cross check' should be used before: cook setup
1667 case "$ARCH" in
1668 arm*|x86_64)
1669 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1670 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1671 . /etc/slitaz/cross.conf ;;
1672 esac
1673 for pkg in $SETUP_PKGS; do
1674 if [ -n "$forced" ]; then
1675 tazpkg -gi $pkg --forced
1676 else
1677 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1678 fi
1679 done
1681 # Handle --options
1682 case "$2" in
1683 --wok) hg clone $WOK_URL wok || exit 1 ;;
1684 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1685 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1686 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1687 esac
1689 # SliTaz group and permissions
1690 if ! grep -q ^slitaz /etc/group; then
1691 _ 'Adding group "%s"' 'slitaz'
1692 addgroup slitaz
1693 fi
1694 _ 'Setting permissions for group "%s"...' 'slitaz'
1695 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1696 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1697 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1699 *-setup)
1700 # Setup for cross compiling.
1701 arch="${1%-setup}"
1702 check_root
1703 . /etc/slitaz/cook.conf
1704 for pkg in $CROSS_SETUP; do
1705 if [ -n "$forced" ]; then
1706 tazpkg -gi $pkg --forced
1707 else
1708 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1709 fi
1710 done
1712 _ 'Cook: setup %s cross environment' "$arch" | log
1713 title 'Setting up your %s cross environment' "$arch"
1714 init_db_files
1715 sed -i \
1716 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1717 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1718 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1719 /etc/slitaz/cook.conf
1720 case "$arch" in
1721 arm)
1722 flags='-O2 -march=armv6'
1723 host="$ARCH-slitaz-linux-gnueabi" ;;
1724 armv6hf)
1725 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1726 host="$ARCH-slitaz-linux-gnueabi" ;;
1727 armv7)
1728 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1729 host="$ARCH-slitaz-linux-gnueabi" ;;
1730 x86_64)
1731 flags='-O2 -mtune=generic -pipe'
1732 host="$ARCH-slitaz-linux" ;;
1733 esac
1734 sed -i \
1735 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1736 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1737 . /etc/slitaz/cook.conf
1738 sysroot="$CROSS_TREE/sysroot"
1739 tools="/cross/$arch/tools"
1740 root="$sysroot"
1741 # L10n: keep the same width of translations to get a consistent view
1742 _ 'Target arch : %s' "$ARCH"
1743 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1744 _ 'Build flags : %s' "$flags"
1745 _ 'Arch sysroot : %s' "$sysroot"
1746 _ 'Tools prefix : %s' "$tools/bin"
1747 # Tell the packages manager where to find packages.
1748 _ 'Packages DB : %s' "$root$DB"
1749 mkdir -p $root$INSTALLED
1750 cd $root$DB; rm -f *.bak
1751 for list in packages.list packages.desc packages.equiv packages.md5; do
1752 rm -f $list
1753 ln -s $SLITAZ/packages/$list $list
1754 done
1755 # We must have the cross compiled glibc-base installed or default
1756 # i486 package will be used as dep by tazpkg and then break the
1757 # cross environment
1758 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1759 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1760 fi
1761 # Show GCC version or warn if not yet compiled.
1762 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1763 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1764 else
1765 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1766 _ 'Run "%s" to cook a toolchain' 'cross compile'
1767 fi
1768 footer ;;
1770 test)
1771 # Test a cook environment.
1772 _ 'Cook test: testing the cook environment' | log
1773 [ ! -d "$WOK" ] && exit 1
1774 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1775 cook cooktest ;;
1777 new)
1778 # Create the package folder and an empty receipt.
1779 pkg="$2"
1780 [ -z "$pkg" ] && usage
1781 newline
1782 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1784 action 'Creating folder "%s"' "$WOK/$pkg"
1785 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1787 action 'Preparing the package receipt...'
1788 cp $DATA/receipt .
1789 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1790 status; newline
1792 # Interactive mode, asking and seding.
1793 case "$3" in
1794 --interactive|-x)
1795 _ 'Entering interactive mode...'
1796 separator
1797 _ 'Package : %s' "$pkg"
1799 _n 'Version : ' ; read answer
1800 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1802 _n 'Category : ' ; read answer
1803 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1805 # L10n: Short description
1806 _n 'Short desc : ' ; read answer
1807 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1809 _n 'Maintainer : ' ; read answer
1810 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1812 _n 'License : ' ; read answer
1813 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1815 _n 'Web site : ' ; read answer
1816 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1817 newline
1819 # Wget URL.
1820 _ 'Wget URL to download source tarball.'
1821 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1822 _n 'Wget url : ' ; read answer
1823 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1825 # Ask for a stuff dir.
1826 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1827 if [ "$?" -eq 0 ]; then
1828 action 'Creating the stuff directory...'
1829 mkdir $WOK/$pkg/stuff; status
1830 fi
1832 # Ask for a description file.
1833 confirm "$(_n 'Are you going to write a description? (y/N)')"
1834 if [ "$?" -eq 0 ]; then
1835 action 'Creating the "%s" file...' 'description.txt'
1836 touch $WOK/$pkg/description.txt; status
1837 fi
1839 footer "$(_ 'Receipt is ready to use.')" ;;
1840 esac ;;
1842 list)
1843 # Cook a list of packages (better use the Cooker since it will order
1844 # packages before executing cook).
1845 check_root
1846 [ -z "$2" ] && die 'No list in argument.'
1847 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1849 _ 'Starting cooking the list "%s"' "$2" | log
1851 while read pkg; do
1852 cook $pkg || broken
1853 done < $2
1854 ;;
1856 clean-wok)
1857 check_root
1858 newline; action 'Cleaning all packages files...'
1859 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1860 status; newline ;;
1862 clean-src)
1863 check_root
1864 newline; action 'Cleaning all packages sources...'
1865 rm -rf $WOK/*/source
1866 status; newline ;;
1868 uncook)
1869 cd $WOK
1870 count=0
1871 title 'Checking for uncooked packages'
1873 for i in *; do
1874 unset HOST_ARCH EXTRAVERSION
1875 [ ! -e $i/receipt ] && continue
1876 . ./$i/receipt
1877 # Source cooked pkg receipt to get EXTRAVERSION
1878 if [ -d "$WOK/$i/taz" ]; then
1879 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
1880 . ./receipt; cd $WOK
1881 fi
1882 case "$ARCH" in
1883 i486)
1884 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1885 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1886 count=$(($count + 1))
1887 colorize 34 "$i"
1888 fi ;;
1889 arm*)
1890 # Check only packages included in arch
1891 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1892 # *.tazpkg
1893 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1894 count=$(($count + 1))
1895 colorize 34 "$i"
1896 fi
1897 fi ;;
1898 esac
1899 done
1901 if [ "$count" -gt 0 ]; then
1902 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1903 else
1904 _ 'All packages are cooked :-)'
1905 newline
1906 fi
1907 ;;
1909 pkgdb)
1910 # Create suitable packages list for TazPkg and only for built packages
1911 # as well as flavors files for TazLiTo. We don't need logs since we do it
1912 # manually to ensure everything is fine before syncing the mirror.
1913 recreate_split_db
1914 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1915 ;;
1917 splitdb)
1918 # File split.db is useful for searching for split packages.
1919 recreate_split_db
1920 ;;
1922 *)
1923 # Just cook and generate a package.
1924 check_root
1925 time=$(date +%s)
1926 pkg="$1"
1927 [ -z "$pkg" ] && usage
1929 # Search last successful cook time in all logs from newer to older
1930 for i in '' $(seq 0 9 | sed 's|^|.|'); do
1931 [ -f "$LOGS/$pkg.log$i" ] || break
1932 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1933 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
1934 [ -n "$lastcooktime" ] && break
1935 done
1937 receipt="$WOK/$pkg/receipt"
1938 check_pkg_in_wok
1939 newline
1941 unset inst
1942 unset_receipt
1943 . $receipt
1945 # Handle cross compilation.
1946 case "$ARCH" in
1947 arm*)
1948 if [ -z "$HOST_ARCH" ]; then
1949 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1950 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1951 _ 'cook: %s' "$error"
1952 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1953 _ 'Cook skip: %s' "$error" | log
1954 newline
1955 broken; exit 1
1956 fi ;;
1957 esac
1959 # Some packages are not included in some arch or fail to cross compile.
1960 : ${HOST_ARCH=i486}
1961 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1962 # Handle arm{v6hf,v7,..}
1963 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1964 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1965 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1966 _ 'cook: %s' "error"
1967 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1968 _ 'Cook skip: %s' "$error" | log
1969 sed -i "/^${pkg}$/d" $broken
1970 newline
1971 exit 0
1972 fi
1974 # Skip blocked, 3 lines also for the Cooker.
1975 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1976 die 'Package "%s" is blocked' "$pkg"
1978 try_aufs_chroot "$@"
1980 # Log and source receipt.
1981 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1982 echo "cook:$pkg" > $command
1984 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1986 while read cmd duration start; do
1987 [ $(($start + $duration)) -lt $(date +%s) ] &&
1988 echo "sed -i '/^$cmd $duration/d' $cooktime"
1989 done < $cooktime | sh
1991 # Display and log info if cook process stopped.
1992 # FIXME: gettext not working (in single quotes) here!
1993 trap '_ "\n\nCook stopped: control-C\n\n" | \
1994 tee -a $LOGS/$pkg.log' INT
1996 update_split_db
1998 # Handle --options
1999 case "$2" in
2000 --install|-i)
2001 inst='yes' ;;
2003 --pack)
2004 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
2005 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
2006 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -rf $LOGS/$pkg-pack.log
2007 sed -i '$ s|$| (packing)|' $activity
2008 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
2009 clean_log "$pkg-pack"
2010 time=$(($(date +%s) - $time))
2011 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
2012 put_status $pkg Done
2013 rm -f $command
2014 exit 0 ;;
2016 --trials|-t)
2017 trials='yes' ;;
2018 esac
2020 # Rotate log
2021 for i in $(seq 9 -1 1); do
2022 j=$(($i - 1))
2023 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2024 done
2025 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2027 # Check if wanted is built now so we have separate log files.
2028 for wanted in $WANTED ; do
2029 if grep -q "^$wanted$" $blocked; then
2030 broken
2031 rm -f $command
2032 die 'WANTED package "%s" is blocked' "$wanted"
2033 fi
2034 if grep -q "^$wanted$" $broken; then
2035 broken
2036 rm -f $command
2037 die 'WANTED package "%s" is broken' "$wanted"
2038 fi
2039 if [ ! -d "$WOK/$wanted/install" ]; then
2040 cook "$wanted" || { broken; exit 1; }
2041 fi
2042 done
2044 # Cook and pack or exit on error and log everything.
2045 ((((cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq))
2046 rq=$? # the return code of `cookit $@` above command
2048 # Remove build dependencies both when `cookit` done or fail
2049 remove_deps | tee -a $LOGS/$pkg.log
2050 cookit_quality
2052 # Log and stop if `cookit` fails
2053 if [ $rq -eq 1 ]; then
2054 debug_info | tee -a $LOGS/$pkg.log
2055 put_status $pkg Failed
2056 rm -f $command
2057 broken; exit 1
2058 fi
2060 # Proceed only if `cookit` return code is zero-OK
2061 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2063 clean_log
2065 # Exit if any error in packing.
2066 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
2067 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2068 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2069 debug_info | tee -a $LOGS/$pkg.log
2070 put_status $pkg Failed
2071 rm -f $command
2072 broken; exit 1
2073 fi
2075 # Create an XML feed
2076 gen_rss
2078 # Time and summary
2079 time=$(($(date +%s) - $time))
2080 summary | tee -a $LOGS/$pkg.log
2081 newline
2083 # We may want to install/update (outside aufs jail!).
2084 [ -s /aufs-umount.sh ] || install_package
2086 put_status $pkg Done
2088 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2089 # If you want automation, use the Cooker Build Bot.
2090 rm -f $command
2091 ;;
2092 esac
2094 exit 0