cookutils view cook @ rev 989

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