cookutils view cook @ rev 1018

cook: cook_copy_icons(): fix function
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Dec 01 16:22:12 2017 +0200 (2017-12-01)
parents f6c47e5f4a8e
children f92f75dce828
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
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
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
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
1099 # Reverse "cat" command: prints input lines in the reverse order
1101 tac() {
1102 sed '1!G;h;$!d' $1
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
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
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*
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
1206 # Encode predefined XML entities
1208 xml_ent() {
1209 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
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
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
1241 # Receipt functions to ease packaging
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
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
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
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
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
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; }
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
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 ifs="$IFS"
1354 unset IFS
1355 action 'Copying hicolor icons...'
1356 [ -d "$fs/usr/share/icons/hicolor" ] && rm -rf "$fs/usr/share/icons/hicolor"
1357 mkdir -p $fs/usr/share/icons/hicolor
1358 for i in ${sizes:-16 48}; do
1359 j="${i}x$i"; [ "$i" == 'scalable' ] && j="$i"
1360 [ ! -e "$install/usr/share/icons/hicolor/$j" ] ||
1361 scopy $install/usr/share/icons/hicolor/$j \
1362 $fs/usr/share/icons/hicolor
1363 done
1364 status
1365 IFS="$ifs"
1369 # Common function to copy files, folders and patterns
1371 copy() {
1372 action 'Copying folders and files...'
1373 local i j k filelist=$(mktemp) folderlist=$(mktemp)
1375 # Get set name for specified package from $SPLIT variable
1376 local set=$(echo $SPLIT \
1377 | awk -vpkg="$PACKAGE" '
1378 BEGIN { RS = " "; FS = ":"; }
1379 { if ($1 == pkg && $2) { print "-" $2; exit; } }')
1380 # Change set, make filelist and folderlist for new set
1381 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$set"
1382 export install="$WOK/$pkg/install$set"
1383 export DESTDIR="$install"
1384 IFS=$'\n'
1385 cd $install
1386 find ! -type d | sed 's|\.||' > $filelist
1387 find -type d | sed 's|\.||' > $folderlist
1389 for i in $@; do
1390 case $i in
1391 @std)
1392 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1393 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /\.pri$/d; /bin\/.*-config$/d;
1394 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1395 /\/Makefile.*/d; /\.inc$/d; /\/include\//d;
1396 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1397 /\/share\/devhelp\//d; /\/share\/locale\//d;
1398 /\/share\/bash-completion\//d; /\/lib\/systemd\//d;
1399 /\/fonts\.scale$/d; /\/fonts\.dir$/d;
1400 /\/share\/appdata\//d; /\/share\/help\//d;
1401 /\/share\/icons\/hicolor\/[12356][1245][268]*x[12356][1245][268]*\//d; # 22, 24, 32, 64, 128, 256, 512
1402 ' $filelist
1403 ;;
1404 @dev)
1405 # Copy "developer files"
1406 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.la$/p; /\.pc$/p; /\.pri$/p; /bin\/.*-config$/p;
1407 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1408 /\/Makefile.*/p; /\.inc$/p; /\/include\//p;
1409 ' $filelist
1410 ;;
1411 @rm)
1412 # Quick alias
1413 remove_already_packed
1414 ;;
1415 @ico)
1416 # Quick alias
1417 cook_copy_icons >/dev/null
1418 ;;
1419 */)
1420 # Copy specified folders.
1421 i="${i%/}"
1422 find -type d -path "*/${i#/}" | sed 's|^.||'
1423 ;;
1424 *)
1425 # Copy specified files.
1426 find ! -type d -path "*/${i#/}" | sed 's|^.||'
1427 ;;
1428 esac \
1429 | sort -u \
1430 | while read j; do
1431 mkdir -p $fs$(dirname "$j")
1432 if [ -d "$install$j" ]; then
1433 cp -a "$install$j" $fs$(dirname "$j")
1434 else
1435 scopy "$install$j" $fs$(dirname "$j")
1436 fi
1437 done
1438 # Copy empty directories
1439 case $i in
1440 @std)
1441 while read j; do
1442 case $j in
1443 # always skip empty man & doc folders, because this will end up
1444 # copying all the man pages and docs to the package
1445 */man/*|*/doc/*) continue;;
1446 esac
1447 [ -z "$(ls -A "$install$j")" ] || continue
1448 # directory $j is empty
1449 k="$j"
1450 # make 'ladder' from directories, from root dir to $j
1451 # /a /a/b /a/b/c etc.
1452 while :; do
1453 [ -z "$k" ] && break
1454 echo "$k"
1455 k="${k%/*}"
1456 done \
1457 | tac \
1458 | while read k; do
1459 # copy dir with its original ownership/permissions if it does not exist
1460 [ -d "$fs$k" ] || cp -a "$install$k" "$fs$k"
1461 done
1462 done < $folderlist
1463 ;;
1464 esac
1465 done
1466 cd - >/dev/null
1467 unset IFS
1468 rm $filelist $folderlist
1469 status
1473 # Update packages database every time after successful build
1475 update_packages_db() {
1476 # packages.info (unsorted, located near to packages)
1477 local pi="$PKGS/packages.info"
1478 unset_receipt; . $pack/receipt
1479 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1481 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1483 rsum=$(release_checksum $pack)
1484 if [ -n "$rsum" ]; then
1485 _ 'The release checksum has changed.\n'
1487 sed -i "/^$PACKAGE\t/d" $pi # remove old entry
1488 cat >> $pi <<EOT
1489 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $rsum $PROVIDE
1490 EOT
1492 # files.list (uncompressed, unsorted, located in $cache)
1493 local fl="$cache/files.list"
1494 touch $fl
1495 sed -i "/^$PACKAGE: /d" $fl
1496 sed "s/^/$PACKAGE: \0/" $pack/files.list >> $fl
1497 else
1498 _ 'The release checksum has not changed.\n'
1499 fi
1503 # Update split.db once for receipt
1505 update_split_db() {
1506 local db="$cache/split.db"
1507 touch $db
1508 sed -i "/^$pkg\t/d" $db
1509 echo -e "$pkg\t$(all_names)" >> $db
1513 # Recreate whole split.db from scratch
1515 recreate_split_db() {
1516 # Clean
1517 local db="$cache/split.db"
1518 touch $db
1519 > $db
1521 cd $WOK
1522 for pkg in *; do
1523 [ -f "$WOK/$pkg/receipt" ] || continue
1524 unset PACKAGE SPLIT
1525 . $WOK/$pkg/receipt
1526 echo -e "$PACKAGE\t$(all_names)" >> $db
1527 done
1531 # Put the status to the activity log
1533 put_status() {
1534 # $1: package, $2: status, one of 'Done', 'Failed'
1535 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1542 # Commands
1545 # cook <package> --deps
1546 [ -n "$deps" ] && {
1547 @@PREFIX@@/libexec/cookutils/deps $1
1548 exit 0
1551 # cook <package> --clean
1552 # cook <package> -c
1553 [ -n "$clean" -o "$2" == '-c' ] && {
1554 action 'Cleaning "%s"' "$1"
1555 cd $WOK/$1; rm -rf install taz source
1556 status; newline
1557 touch $activity # update $activity -> something changed -> update webstat
1558 exit 0
1561 # cook <package> --getsrc
1562 # cook <package> -gs
1563 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1564 title 'Getting source for "%s"' "$1"
1565 receipt="$WOK/$pkg/receipt"
1566 check_pkg_in_wok
1567 unset_receipt
1568 . $receipt
1569 get_source
1570 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1571 exit 0
1574 # cook <package> --block
1575 # cook <package> -b
1576 [ -n "$block" -o "$2" == '-b' ] && {
1577 action 'Blocking package "%s"' "$1"
1578 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1579 status; newline
1580 touch $activity
1581 exit 0
1584 # cook <package> --unblock
1585 # cook <package> -ub
1586 [ -n "$unblock" -o "$2" == '-ub' ] && {
1587 action 'Unblocking package "%s"' "$1"
1588 sed -i "/^$1$/d" $blocked
1589 status; newline
1590 touch $activity
1591 exit 0
1597 case "$1" in
1598 usage|help|-u|-h)
1599 usage ;;
1601 list-wok)
1602 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1603 cd $WOK
1604 if [ "$ARCH" != 'i486' ]; then
1605 count=0
1606 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1607 do
1608 unset HOST_ARCH
1609 . ./$pkg
1610 count=$(($count + 1))
1611 colorize 34 "$PACKAGE"
1612 done
1613 else
1614 count=$(ls | wc -l)
1615 ls -1
1616 fi
1617 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1618 ;;
1620 activity)
1621 cat $activity ;;
1623 search)
1624 # Just a simple search function, we don't need more actually.
1625 query="$2"
1626 title 'Search results for "%s"' "$query"
1627 cd $WOK; ls -1 | grep "$query"
1628 footer ;;
1630 setup)
1631 # Setup a build environment
1632 check_root
1633 _ 'Cook: setup environment' | log
1634 title 'Setting up your environment'
1635 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1636 cd $SLITAZ
1637 init_db_files
1638 _ 'Checking for packages to install...'
1639 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1640 # ARCH-setup or 'cross check' should be used before: cook setup
1641 case "$ARCH" in
1642 arm*|x86_64)
1643 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1644 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1645 . /etc/slitaz/cross.conf ;;
1646 esac
1647 for pkg in $SETUP_PKGS; do
1648 if [ -n "$forced" ]; then
1649 tazpkg -gi $pkg --forced
1650 else
1651 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1652 fi
1653 done
1655 # Handle --options
1656 case "$2" in
1657 --wok) hg clone $WOK_URL wok || exit 1 ;;
1658 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1659 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1660 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1661 esac
1663 # SliTaz group and permissions
1664 if ! grep -q ^slitaz /etc/group; then
1665 _ 'Adding group "%s"' 'slitaz'
1666 addgroup slitaz
1667 fi
1668 _ 'Setting permissions for group "%s"...' 'slitaz'
1669 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1670 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1671 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1673 *-setup)
1674 # Setup for cross compiling.
1675 arch="${1%-setup}"
1676 check_root
1677 . /etc/slitaz/cook.conf
1678 for pkg in $CROSS_SETUP; do
1679 if [ -n "$forced" ]; then
1680 tazpkg -gi $pkg --forced
1681 else
1682 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1683 fi
1684 done
1686 _ 'Cook: setup %s cross environment' "$arch" | log
1687 title 'Setting up your %s cross environment' "$arch"
1688 init_db_files
1689 sed -i \
1690 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1691 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1692 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1693 /etc/slitaz/cook.conf
1694 case "$arch" in
1695 arm)
1696 flags='-O2 -march=armv6'
1697 host="$ARCH-slitaz-linux-gnueabi" ;;
1698 armv6hf)
1699 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1700 host="$ARCH-slitaz-linux-gnueabi" ;;
1701 armv7)
1702 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1703 host="$ARCH-slitaz-linux-gnueabi" ;;
1704 x86_64)
1705 flags='-O2 -mtune=generic -pipe'
1706 host="$ARCH-slitaz-linux" ;;
1707 esac
1708 sed -i \
1709 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1710 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1711 . /etc/slitaz/cook.conf
1712 sysroot="$CROSS_TREE/sysroot"
1713 tools="/cross/$arch/tools"
1714 root="$sysroot"
1715 # L10n: keep the same width of translations to get a consistent view
1716 _ 'Target arch : %s' "$ARCH"
1717 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1718 _ 'Build flags : %s' "$flags"
1719 _ 'Arch sysroot : %s' "$sysroot"
1720 _ 'Tools prefix : %s' "$tools/bin"
1721 # Tell the packages manager where to find packages.
1722 _ 'Packages DB : %s' "$root$DB"
1723 mkdir -p $root$INSTALLED
1724 cd $root$DB; rm -f *.bak
1725 for list in packages.list packages.desc packages.equiv packages.md5; do
1726 rm -f $list
1727 ln -s $SLITAZ/packages/$list $list
1728 done
1729 # We must have the cross compiled glibc-base installed or default
1730 # i486 package will be used as dep by tazpkg and then break the
1731 # cross environment
1732 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1733 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1734 fi
1735 # Show GCC version or warn if not yet compiled.
1736 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1737 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1738 else
1739 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1740 _ 'Run "%s" to cook a toolchain' 'cross compile'
1741 fi
1742 footer ;;
1744 test)
1745 # Test a cook environment.
1746 _ 'Cook test: testing the cook environment' | log
1747 [ ! -d "$WOK" ] && exit 1
1748 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1749 cook cooktest ;;
1751 new)
1752 # Create the package folder and an empty receipt.
1753 pkg="$2"
1754 [ -z "$pkg" ] && usage
1755 newline
1756 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1758 action 'Creating folder "%s"' "$WOK/$pkg"
1759 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1761 action 'Preparing the package receipt...'
1762 cp $DATA/receipt .
1763 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1764 status; newline
1766 # Interactive mode, asking and seding.
1767 case "$3" in
1768 --interactive|-x)
1769 _ 'Entering interactive mode...'
1770 separator
1771 _ 'Package : %s' "$pkg"
1773 _n 'Version : ' ; read answer
1774 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1776 _n 'Category : ' ; read answer
1777 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1779 # L10n: Short description
1780 _n 'Short desc : ' ; read answer
1781 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1783 _n 'Maintainer : ' ; read answer
1784 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1786 _n 'License : ' ; read answer
1787 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1789 _n 'Web site : ' ; read answer
1790 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1791 newline
1793 # Wget URL.
1794 _ 'Wget URL to download source tarball.'
1795 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1796 _n 'Wget url : ' ; read answer
1797 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1799 # Ask for a stuff dir.
1800 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1801 if [ "$?" -eq 0 ]; then
1802 action 'Creating the stuff directory...'
1803 mkdir $WOK/$pkg/stuff; status
1804 fi
1806 # Ask for a description file.
1807 confirm "$(_n 'Are you going to write a description? (y/N)')"
1808 if [ "$?" -eq 0 ]; then
1809 action 'Creating the "%s" file...' 'description.txt'
1810 touch $WOK/$pkg/description.txt; status
1811 fi
1813 footer "$(_ 'Receipt is ready to use.')" ;;
1814 esac ;;
1816 list)
1817 # Cook a list of packages (better use the Cooker since it will order
1818 # packages before executing cook).
1819 check_root
1820 [ -z "$2" ] && die 'No list in argument.'
1821 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1823 _ 'Starting cooking the list "%s"' "$2" | log
1825 while read pkg; do
1826 cook $pkg || broken
1827 done < $2
1828 ;;
1830 clean-wok)
1831 check_root
1832 newline; action 'Cleaning all packages files...'
1833 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1834 status; newline ;;
1836 clean-src)
1837 check_root
1838 newline; action 'Cleaning all packages sources...'
1839 rm -rf $WOK/*/source
1840 status; newline ;;
1842 uncook)
1843 cd $WOK
1844 count=0
1845 title 'Checking for uncooked packages'
1847 for i in *; do
1848 unset HOST_ARCH EXTRAVERSION
1849 [ ! -e $i/receipt ] && continue
1850 . ./$i/receipt
1851 # Source cooked pkg receipt to get EXTRAVERSION
1852 if [ -d "$WOK/$i/taz" ]; then
1853 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
1854 . ./receipt; cd $WOK
1855 fi
1856 case "$ARCH" in
1857 i486)
1858 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1859 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1860 count=$(($count + 1))
1861 colorize 34 "$i"
1862 fi ;;
1863 arm*)
1864 # Check only packages included in arch
1865 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1866 # *.tazpkg
1867 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1868 count=$(($count + 1))
1869 colorize 34 "$i"
1870 fi
1871 fi ;;
1872 esac
1873 done
1875 if [ "$count" -gt 0 ]; then
1876 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1877 else
1878 _ 'All packages are cooked :-)'
1879 newline
1880 fi
1881 ;;
1883 pkgdb)
1884 # Create suitable packages list for TazPkg and only for built packages
1885 # as well as flavors files for TazLiTo. We don't need logs since we do it
1886 # manually to ensure everything is fine before syncing the mirror.
1887 recreate_split_db
1888 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1889 ;;
1891 splitdb)
1892 # File split.db is useful for searching for split packages.
1893 recreate_split_db
1894 ;;
1896 *)
1897 # Just cook and generate a package.
1898 check_root
1899 time=$(date +%s)
1900 pkg="$1"
1901 [ -z "$pkg" ] && usage
1903 # Search last successful cook time in all logs from newer to older
1904 for i in '' $(seq 0 9 | sed 's|^|.|'); do
1905 [ -f "$LOGS/$pkg.log$i" ] || break
1906 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1907 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
1908 [ -n "$lastcooktime" ] && break
1909 done
1911 receipt="$WOK/$pkg/receipt"
1912 check_pkg_in_wok
1913 newline
1915 unset inst
1916 unset_receipt
1917 . $receipt
1919 # Handle cross compilation.
1920 case "$ARCH" in
1921 arm*)
1922 if [ -z "$HOST_ARCH" ]; then
1923 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1924 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1925 _ 'cook: %s' "$error"
1926 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1927 _ 'Cook skip: %s' "$error" | log
1928 newline
1929 broken; exit 1
1930 fi ;;
1931 esac
1933 # Some packages are not included in some arch or fail to cross compile.
1934 : ${HOST_ARCH=i486}
1935 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1936 # Handle arm{v6hf,v7,..}
1937 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1938 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1939 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1940 _ 'cook: %s' "error"
1941 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1942 _ 'Cook skip: %s' "$error" | log
1943 sed -i "/^${pkg}$/d" $broken
1944 newline
1945 exit 0
1946 fi
1948 # Skip blocked, 3 lines also for the Cooker.
1949 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1950 die 'Package "%s" is blocked' "$pkg"
1952 try_aufs_chroot "$@"
1954 # Log and source receipt.
1955 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1956 echo "cook:$pkg" > $command
1958 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1960 while read cmd duration start; do
1961 [ $(($start + $duration)) -lt $(date +%s) ] &&
1962 echo "sed -i '/^$cmd $duration/d' $cooktime"
1963 done < $cooktime | sh
1965 # Display and log info if cook process stopped.
1966 # FIXME: gettext not working (in single quotes) here!
1967 trap '_ "\n\nCook stopped: control-C\n\n" | \
1968 tee -a $LOGS/$pkg.log' INT
1970 update_split_db
1972 # Handle --options
1973 case "$2" in
1974 --install|-i)
1975 inst='yes' ;;
1977 --pack)
1978 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
1979 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
1980 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -rf $LOGS/$pkg-pack.log
1981 sed -i '$ s|$| (packing)|' $activity
1982 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
1983 clean_log "$pkg-pack"
1984 time=$(($(date +%s) - $time))
1985 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
1986 put_status $pkg Done
1987 rm -f $command
1988 exit 0 ;;
1990 --trials|-t)
1991 trials='yes' ;;
1992 esac
1994 # Rotate log
1995 for i in $(seq 9 -1 1); do
1996 j=$(($i - 1))
1997 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1998 done
1999 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2001 # Check if wanted is built now so we have separate log files.
2002 for wanted in $WANTED ; do
2003 if grep -q "^$wanted$" $blocked; then
2004 broken
2005 rm -f $command
2006 die 'WANTED package "%s" is blocked' "$wanted"
2007 fi
2008 if grep -q "^$wanted$" $broken; then
2009 broken
2010 rm -f $command
2011 die 'WANTED package "%s" is broken' "$wanted"
2012 fi
2013 if [ ! -d "$WOK/$wanted/install" ]; then
2014 cook "$wanted" || { broken; exit 1; }
2015 fi
2016 done
2018 # Cook and pack or exit on error and log everything.
2019 ((((cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq))
2020 rq=$? # the return code of `cookit $@` above command
2022 # Remove build dependencies both when `cookit` done or fail
2023 remove_deps | tee -a $LOGS/$pkg.log
2024 cookit_quality
2026 # Log and stop if `cookit` fails
2027 if [ $rq -eq 1 ]; then
2028 debug_info | tee -a $LOGS/$pkg.log
2029 put_status $pkg Failed
2030 rm -f $command
2031 broken; exit 1
2032 fi
2034 # Proceed only if `cookit` return code is zero-OK
2035 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2037 clean_log
2039 # Exit if any error in packing.
2040 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
2041 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2042 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2043 debug_info | tee -a $LOGS/$pkg.log
2044 put_status $pkg Failed
2045 rm -f $command
2046 broken; exit 1
2047 fi
2049 # Create an XML feed
2050 gen_rss
2052 # Time and summary
2053 time=$(($(date +%s) - $time))
2054 summary | tee -a $LOGS/$pkg.log
2055 newline
2057 # We may want to install/update (outside aufs jail!).
2058 [ -s /aufs-umount.sh ] || install_package
2060 put_status $pkg Done
2062 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2063 # If you want automation, use the Cooker Build Bot.
2064 rm -f $command
2065 ;;
2066 esac
2068 exit 0