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