cookutils view cook @ rev 932

Add modules/deps: check package's dependencies; cook: make/update split.db and files.list; modules/compressor: use static (i.e. unbreakable) versions of pngquant and optipng.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Jun 17 23:56:37 2017 +0300 (2017-06-17)
parents 253b4ffeef27
children 9b8a08ce85c9
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
95 }
98 # QA: check a receipt consistency before building.
100 receipt_quality() {
101 _ 'QA: checking package receipt...'
103 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE; do
104 unset value
105 value="$(. $receipt; eval echo \$$var)"
106 # L10n: QA is quality assurance
107 [ -n "$value" ] || die 'QA: empty variable: %s' "$var=\"\""
109 case "$var" in
110 CATEGORY)
111 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
112 if ! echo " $valid " | grep -q " $value "; then
113 _ 'QA: unknown category "%s"' "$value"
114 die 'Please, use one of: %s' "$valid"
115 fi
116 ;;
117 WEB_SITE)
118 # We don't check WGET_URL since if dl is needed it will fail.
119 # Break also if we're not online. Here error is not fatal.
120 if ifconfig | grep -A1 '^[a-z]*[0-9]' | fgrep -q 'addr:' && \
121 ! busybox wget -T 12 --spider $value 2>/dev/null; then
122 _ 'QA: unable to reach "%s"' "$value"
123 fi
124 ;;
125 esac
126 done
127 }
130 # Paths used in receipt and by cook itself.
132 set_paths() {
133 pkgdir="$WOK/$pkg"
134 . "$pkgdir/receipt"
135 basesrc="$pkgdir/source"
136 tmpsrc="$basesrc/tmp"
137 src="$basesrc/$PACKAGE-$VERSION"
138 taz="$pkgdir/taz"
139 pack="$taz/${1:-$PACKAGE}-$VERSION$EXTRAVERSION" # v2: multiple taz/* folders
140 fs="$pack/fs"
141 stuff="$pkgdir/stuff"
142 install="$pkgdir/install"
144 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
145 lzma_tarball="$pkgsrc.tar.lzma"
147 [ -n "$PATCH" -a -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
149 if [ -n "$WANTED" ]; then
150 basesrc="$WOK/$WANTED/source"
151 src="$basesrc/$WANTED-$VERSION"
152 install="$WOK/$WANTED/install"
153 wanted_stuff="$WOK/$WANTED/stuff"
154 fi
156 [ -n "$SOURCE" ] && source_stuff="$WOK/$SOURCE/stuff"
158 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
159 if [ -f "$WOK/linux/receipt" ]; then
160 kvers=$(. $WOK/linux/receipt; echo $VERSION)
161 kbasevers=$(echo $kvers | cut -d. -f1,2)
162 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
163 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
164 kbasevers=$(echo $kvers | cut -d. -f1,2)
165 fi
167 # Python version
168 [ -f "$WOK/python/receipt" ] && pyvers=$(. $WOK/python/receipt; echo $VERSION)
169 # Perl version for some packages needed it
170 [ -f "$WOK/perl/receipt" ] && perlvers=$(. $WOK/perl/receipt; echo $VERSION)
172 # Old way compatibility.
173 _pkg="$install"
174 }
177 # Create source tarball when URL is a SCM.
179 create_tarball() {
180 local tarball
181 tarball="$pkgsrc.tar.bz2"
182 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
183 _ 'Creating tarball "%s"' "$tarball"
184 if [ -n "$LZMA_SRC" ]; then
185 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
186 LZMA_SRC=''
187 else
188 tar -cjf $tarball $pkgsrc || exit 1
189 mv $tarball $SRC; rm -rf $pkgsrc
190 fi
191 TARBALL="$tarball"
192 }
195 # Get package source. For SCM we are in cache so clone here and create a
196 # tarball here.
198 get_source() {
199 local url
200 url=${WGET_URL#*|}
201 set_paths
202 pwd=$(pwd)
203 case "$WGET_URL" in
204 http://*|ftp://*|https://*)
205 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
206 wget -T 60 -c -O $SRC/$TARBALL $WGET_URL ||
207 wget -T 60 -c -O $SRC/$TARBALL $url ||
208 die 'ERROR: %s' "wget $WGET_URL"
209 ;;
211 hg*|mercurial*)
212 _ 'Getting source from %s...' 'Hg'
213 _ 'URL: %s' "$url"
214 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
215 if [ -n "$BRANCH" ]; then
216 _ 'Hg branch: %s' "$BRANCH"
217 hg clone $url --rev $BRANCH $pkgsrc ||
218 die 'ERROR: %s' "hg clone $url --rev $BRANCH"
219 else
220 hg clone $url $pkgsrc || die 'ERROR: %s' "hg clone $url"
221 fi
222 rm -rf $pkgsrc/.hg
223 create_tarball
224 ;;
226 git*)
227 _ 'Getting source from %s...' 'Git'
228 _ 'URL: %s' "$url"
229 cd $SRC
230 git clone $url $pkgsrc || die 'ERROR: %s' "git clone $url"
231 if [ -n "$BRANCH" ]; then
232 _ 'Git branch: %s' "$BRANCH"
233 cd $pkgsrc; git checkout $BRANCH; cd ..
234 fi
235 cd $SRC
236 create_tarball
237 ;;
239 cvs*)
240 mod=$PACKAGE
241 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
242 _ 'Getting source from %s...' 'CVS'
243 _ 'URL: %s' "$url"
244 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
245 _ 'Cloning to "%s"' "$pwd/$mod"
246 cvs -d:$url co $mod && mv $mod $pkgsrc
247 create_tarball
248 ;;
250 svn*|subversion*)
251 _ 'Getting source from %s...' 'SVN'
252 _ 'URL: %s' "$url"
253 if [ -n "$BRANCH" ]; then
254 echo t | svn co $url -r $BRANCH $pkgsrc
255 else
256 echo t | svn co $url $pkgsrc
257 fi
258 create_tarball
259 ;;
261 bzr*)
262 _ 'Getting source from %s...' 'bazaar'
263 cd $SRC
264 pkgsrc=${url#*:}
265 if [ -n "$BRANCH" ]; then
266 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
267 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
268 else
269 echo "bzr -Ossl.cert_reqs=none branch $url"
270 bzr -Ossl.cert_reqs=none branch $url
271 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
272 _ "Don't forget to add to receipt:"
273 echo -e "BRANCH=\"$BRANCH\"\n"
274 fi
275 mv $pkgsrc $pkgsrc-$BRANCH
276 pkgsrc="$pkgsrc-$BRANCH"
277 create_tarball
278 ;;
280 *)
281 broken; die 'ERROR: Unable to handle "%s"' "$WGET_URL"
282 ;;
283 esac
284 }
287 # Extract source package.
289 extract_source() {
290 if [ ! -s "$SRC/$TARBALL" ]; then
291 local url
292 url="$MIRROR_URL/sources/packages"
293 url="$url/${TARBALL:0:1}/$TARBALL"
294 _ 'Getting source from %s...' 'mirror'
295 _ 'URL: %s' "$url"
296 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
297 fi
298 _ 'Extracting source archive "%s"' "$TARBALL"
299 case "$TARBALL" in
300 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
301 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
302 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
303 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
304 *.tar) tar -xf $SRC/$TARBALL ;;
305 *.zip|*.xpi) unzip -o $SRC/$TARBALL 2>/dev/null >&2;;
306 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
307 tar -xf $SRC/$TARBALL 2>/dev/null;;
308 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
309 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
310 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
311 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
312 *) cp $SRC/$TARBALL $(pwd) ;;
313 esac
314 }
317 # Display time.
319 disp_time() {
320 local sec div min
321 sec="$1"
322 div=$(( ($1 + 30) / 60))
323 case $div in
324 0) min='';;
325 # L10n: 'm' is for minutes (approximate cooking time)
326 *) min=$(_n ' ~ %dm' "$div");;
327 esac
329 # L10n: 's' is for seconds (cooking time)
330 _ '%ds%s' "$sec" "$min"
331 }
334 # Display cooked package summary.
336 summary() {
337 set_paths
338 cd $WOK/$pkg
339 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
340 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
341 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
343 _ 'Summary for: %s' "$PACKAGE $VERSION"
344 separator
346 # L10n: keep the same width of translations to get a consistent view
347 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
348 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
349 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
350 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
351 _ 'Cook time : %s' "$(disp_time "$time")"
352 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
353 _ 'Host arch : %s' "$ARCH"
355 separator -
356 _ ' # : Packed : Compressed : Files : Package name'
357 separator -
358 pkgi=1
359 for i in $(all_names); do
360 fs=$(du -sh $WOK/$pkg/taz/$i-$VERSION | awk '{print $1}')
361 pkgname="$i-$VERSION.tazpkg"
362 size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
363 files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION/files.list)
364 printf "%2d : %7s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
365 pkgi=$((pkgi + 1))
366 done
367 separator
368 }
371 # Display debugging error info.
373 debug_info() {
374 title 'Debug information'
375 # L10n: specify your format of date and time (to help: man date)
376 # L10n: not bad one is '+%x %R'
377 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
378 if [ -n "$time" ]; then
379 times="$(($(date +%s) - $time))"
380 _ 'Wasted time : %s' "$(disp_time "$times")"
381 fi
382 for error in \
383 ERROR 'No package' "cp: can't" "can't open" "can't cd" \
384 'error:' 'fatal error:' 'undefined reference to' \
385 'Unable to connect to' 'link: cannot find the library' \
386 'CMake Error' ': No such file or directory' \
387 'Could not read symbols: File in wrong format'
388 do
389 # format "line number:line content"
390 fgrep -n "$error" $LOGS/$pkg.log
391 done > $LOGS/$pkg.log.debug_info 2>&1
392 # sort by line number, remove duplicates
393 sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
394 rm -f $LOGS/$pkg.log.debug_info
395 footer
396 }
399 # A bit smarter function than the classic `cp` command
401 scopy() {
402 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
403 cp -a "$1" "$2" # copy generic files
404 else
405 cp -al "$1" "$2" # copy hardlinks
406 fi
407 }
410 # Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
411 # We use standard paths, so some packages need to copy these files with the
412 # receipt and genpkg_rules.
413 # This function executes inside the packaging process, before compressor call.
415 copy_generic_files() {
416 # Proceed only for "main" package (for v2), and for any packages (v1)
417 [ "$pkg" == "$PACKAGE" ] || return 0
419 # $LOCALE is set in cook.conf
420 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
421 if [ -d "$install/usr/share/locale" ]; then
422 mkdir -p "$fs/usr/share/locale"
423 for i in $LOCALE; do
424 if [ -d "$install/usr/share/locale/$i" ]; then
425 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
426 fi
427 done
428 fi
429 fi
431 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
432 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
433 if [ -d "$install/usr/share/pixmaps" ]; then
434 mkdir -p "$fs/usr/share/pixmaps"
435 for i in png xpm; do
436 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
437 cp -a $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
438 done
439 fi
440 fi
442 # Desktop entry (.desktop).
443 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
444 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
445 if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
446 mkdir -p "$fs/usr/share"
447 cp -a $install/usr/share/applications $fs/usr/share
448 fi
449 fi
450 }
453 # Copy pixmaps, desktop files and licenses from $stuff to $install.
454 # This function executes after the main compile_rules() is done.
456 copy_generic_stuff() {
457 # Custom or homemade PNG pixmap can be in stuff.
458 if [ -f "$stuff/$PACKAGE.png" ]; then
459 mkdir -p $install/usr/share/pixmaps
460 cp $stuff/$PACKAGE.png $install/usr/share/pixmaps
461 fi
463 # Homemade desktop file(s) can be in stuff.
464 if [ -d "$stuff/applications" ]; then
465 mkdir -p $install/usr/share
466 cp -a $stuff/applications $install/usr/share
467 fi
468 if [ -f "$stuff/$PACKAGE.desktop" ]; then
469 mkdir -p $install/usr/share/applications
470 cp $stuff/$PACKAGE.desktop $install/usr/share/applications
471 fi
473 # Add custom licenses
474 if [ -d "$stuff/licenses" ]; then
475 mkdir -p $install/usr/share/licenses
476 cp -a $stuff/licenses $install/usr/share/licenses/$PACKAGE
477 fi
478 }
481 # Remove files provided by split packages
482 # For example:
483 # 1. Package "pkg-main":
484 # SPLIT="pkg-1 pkg-2 pkg-extra"
485 # 2. Package="pkg-extra":
486 # WANTED="pkg-main"
487 # BUILD_DEPENDS="pkg-1 pkg-2"
488 # cook_copy_folders usr
489 # cook_split_rm $BUILD_DEPENDS
491 cook_split_rm() {
492 for i in $@; do
493 action 'Remove files provided by split package %s...' "$i"
494 while read j; do
495 [ -f "$fs$j" -o -h "$fs$j" ] && rm $fs$j
496 rmdir "$(dirname "$fs$j")" 2>/dev/null
497 done < $WOK/$i/taz/$i-$VERSION/files.list
498 :; status
499 done
500 }
503 # Update installed.cook.diff
505 update_installed_cook_diff() {
506 # If a cook failed deps are removed.
507 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
508 cd $CACHE
509 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
510 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
511 deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
512 }
515 # Remove installed deps.
517 remove_deps() {
518 # Now remove installed build deps.
519 diff='/tmp/installed.cook.diff'
520 [ -s "$diff" ] || return
522 deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
523 nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
524 newline
525 _n 'Build dependencies to remove:'; echo " $nb"
526 [ -n "$root" ] && echo "root=\"$root\""
527 {
528 _n 'Removing:'
529 for dep in $deps; do
530 echo -n " $dep"
531 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
532 done
533 newline; newline
534 # Keep the last diff for debug and info.
535 mv -f $diff $CACHE/installed.diff
536 } | fold -sw80
537 }
540 # Automatically patch the sources.
542 patchit() {
543 [ -f "$stuff/patches/series" ] || return
545 while read i; do
546 [ -f "$src/done.$i" ] && continue
547 newline
548 _ 'Applying patch %s' "$i"
549 patch -p1 -i $stuff/patches/$i | sed 's|^| |'
550 touch $src/done.$i
551 done < $stuff/patches/series
552 newline
553 }
556 # Check source tarball integrity.
558 check_integrity() {
559 for i in sha1 sha3 sha256 sha512 md5; do
560 I=$(echo $i | tr 'a-z' 'A-Z')
561 eval sum=\$TARBALL_$I
562 if [ -n "$sum" ]; then
563 newline
564 _ 'Checking %ssum of source tarball...' "$i"
565 echo "$sum $SRC/$TARBALL" | ${i}sum -c || exit 1
566 fi
567 done
568 newline
569 }
572 # The main cook function.
574 cookit() {
575 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
576 _ 'ERROR: Broken setup. Abort.'
577 return
578 fi
580 title 'Cook: %s' "$PACKAGE $VERSION"
581 set_paths
583 # Handle cross-tools.
584 case "$ARCH" in
585 arm*|x86_64)
586 # CROSS_COMPILE is used by at least Busybox and the kernel to set
587 # the cross-tools prefix. Sysroot is the root of our target arch
588 sysroot="$CROSS_TREE/sysroot"
589 tools="$CROSS_TREE/tools"
590 # Set root path when cross compiling. ARM tested but not x86_64
591 # When cross compiling we must install build deps in $sysroot.
592 arch="-$ARCH"
593 root="$sysroot"
594 _ '%s sysroot: %s' "$ARCH" "$sysroot"
595 _ 'Adding "%s" to PATH' "$tools/bin"
596 export PATH="$PATH:$tools/bin"
597 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
598 export CROSS_COMPILE="$HOST_SYSTEM-"
599 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
600 if [ "$ARCH" == 'x86_64' ]; then
601 export CC="$HOST_SYSTEM-gcc -m64"
602 export CXX="$HOST_SYSTEM-g++ -m64"
603 else
604 export CC="$HOST_SYSTEM-gcc"
605 export CXX="$HOST_SYSTEM-g++"
606 fi
607 export AR="$HOST_SYSTEM-ar"
608 export AS="$HOST_SYSTEM-as"
609 export RANLIB="$HOST_SYSTEM-ranlib"
610 export LD="$HOST_SYSTEM-ld"
611 export STRIP="$HOST_SYSTEM-strip"
612 export LIBTOOL="$HOST_SYSTEM-libtool"
613 ;;
614 esac
616 [ -n "$QA" ] && receipt_quality
618 cd $pkgdir
619 [ -z "$continue" ] && rm -rf source 2>/dev/null
620 rm -rf install taz 2>/dev/null
622 # Disable -pipe if less than 512 MB free RAM.
623 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
624 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
625 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
626 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
627 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
628 fi
629 unset free
631 # Export flags and path to be used by make and receipt.
632 DESTDIR="$pkgdir/install"
633 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
634 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
635 #LDFLAGS
637 # BUILD_DEPENDS may vary depending on the ARCH
638 case "$ARCH" in
639 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
640 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
641 esac
643 # Check for build deps and handle implicit depends of *-dev packages
644 # (ex: libusb-dev :: libusb).
645 # rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
646 # touch $CACHE/installed.local $CACHE/installed.web
647 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
648 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
650 for action in check install; do
651 for dep in $BUILD_DEPENDS; do
652 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
653 for i in $dep $implicit; do
654 # Skip if package already installed
655 [ -f "$root$INSTALLED/$i/receipt" ] && continue
657 case $action in
658 check)
659 # Search for local package or local provided-package
660 name=$(awk -F$'\t' -vpkg="$i" '{
661 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
662 }' "$PKGS/packages.info")
663 if [ -z "$name" ]; then
664 # Search for package in mirror
665 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
666 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
667 fi
668 ;;
669 install)
670 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
671 ;;
672 esac
673 done
674 done
675 done
677 # # Get the list of installed packages
678 # cd $root$INSTALLED; ls -1 > $CACHE/installed.list
679 #
680 # # Have we a missing build dep to cook?
681 # if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
682 # _ 'Auto cook config is set: %s' "$AUTO_COOK"
683 # cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
684 # for i in $(uniq $CACHE/missing.dep); do
685 # (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
686 # tee -a $LOGS/$PACKAGE.log.$$
687 # # programmers: next two messages are exact copy from remove_deps()
688 # togrep1=$(_n 'Build dependencies to remove:')
689 # togrep2=$(_n 'Removing:')
690 # cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
691 # fgrep $togrep1 $LOGS/$i.log && \
692 # fgrep $togrep2 $LOGS/$i.log && newline) | \
693 # tee -a $LOGS/$PACKAGE.log.$$ && break
694 # done
695 # rm -f $CACHE/missing.dep
696 # mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
697 # fi
698 #
699 # # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
700 # # is enabled and cook fails we have ERROR in log, if no auto cook we have
701 # # missing dep in cached file.
702 # lerror=$(_n 'ERROR')
703 # if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
704 # [ -s "$CACHE/missing.dep" ] && nb=$(wc -l < $CACHE/missing.dep)
705 # _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
706 # broken; exit 1
707 # fi
708 #
709 # # Install local packages: package-version$arch
710 # cd $PKGS
711 # for i in $(uniq $CACHE/installed.local); do
712 # # _ 'Installing dep (pkg/local): %s' "$i"
713 # tazpkg install $i --root=$root --local --quiet --cookmode
714 # done
715 #
716 # # Install web or cached packages (if mirror is set to $PKGS we only
717 # # use local packages).
718 # for i in $(uniq $CACHE/installed.web); do
719 # # _ 'Installing dep (web/cache): %s' "$i"
720 # tazpkg get-install $i --root=$root --local --quiet --cookmode
721 # done
723 update_installed_cook_diff
725 # Get source tarball and make sure we have source dir named:
726 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
727 # tarball if it exists.
728 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
729 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
730 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
731 LZMA_SRC=''
732 else
733 get_source || { broken; exit 1; }
734 fi
735 fi
736 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
737 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
738 if ! extract_source ; then
739 get_source
740 extract_source || { broken; exit 1; }
741 fi
742 if [ -n "$LZMA_SRC" ]; then
743 cd $pkgdir/source
744 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
745 mv tmp tmp-1; mkdir tmp
746 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
747 fi
748 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
749 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
750 fi
751 fi
752 cd $pkgdir/source/tmp
753 # Some archives are not well done and don't extract to one dir (ex lzma).
754 files=$(ls | wc -l)
755 [ "$files" -eq 1 -a -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
756 [ "$files" -eq 1 -a -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
757 mv * ../$PACKAGE-$VERSION/$TARBALL
758 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
759 mv * ../$PACKAGE-$VERSION
760 cd ..; rm -rf tmp
761 fi
763 check_integrity
765 # Libtool shared libs path hack.
766 case "$ARCH" in
767 arm*) cross libhack ;;
768 esac
770 # Execute receipt rules.
771 if grep -q ^compile_rules $receipt; then
772 _ 'Executing: %s' 'compile_rules'
773 echo "CFLAGS : $CFLAGS"
774 #echo "LDFLAGS : $LDFLAGS"
775 [ -d "$src" ] && cd $src
776 patchit
777 compile_rules $@ || { broken; exit 1; }
778 # Stay compatible with _pkg
779 [ -d "$src/_pkg" ] && mv $src/_pkg $install
780 # QA: compile_rules success so valid.
781 mkdir -p $install
782 else
783 # QA: no compile_rules so no error, valid.
784 mkdir -p $install
785 fi
787 copy_generic_stuff
789 # Actions to do after compiling the package
790 # Skip all for split packages (already done in main package)
791 if [ -z "$WANTED" ]; then
792 footer
793 export COOKOPTS ARCH install; @@PREFIX@@/libexec/cookutils/compressor install
794 fi
795 footer
797 # Execute testsuite.
798 if grep -q ^testsuite $receipt; then
799 title 'Running testsuite'
800 testsuite $@ || { broken; exit 1; }
801 footer
802 fi
804 update_installed_cook_diff force
805 }
808 # Cook quality assurance.
810 cookit_quality() {
811 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
812 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
813 fi
814 # ERROR can be echoed any time in cookit()
815 lerror=$(_n 'ERROR')
816 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
817 grep -Eq "(^$lerror|undefined reference to)" ; then
818 debug_info | tee -a $LOGS/$pkg.log
819 sed -i '$ s|$| [ Failed ]|' $activity
820 rm -f $command
821 broken; exit 1
822 fi
823 }
826 # Receipt used for cooking the package is redundant to be included into package.
827 # This script will strip the original receipt to bare minimum: variables,
828 # {pre,post}_{install,remove} functions.
830 mk_pkg_receipt() {
831 orig_receipt="$1"
833 # Receipt's signature is important, although some receipts may miss it
834 signature=$(head -n1 "$orig_receipt")
835 [ "${signature:0:1}" == '#' ] || signature='# SliTaz package receipt.'
837 save_PACKAGE="$PACKAGE"; save_DEPENDS="$DEPENDS"; save_PROVIDE="$PROVIDE"
838 save_SUGGESTED="$SUGGESTED"; save_TAZPANEL_DAEMON="$TAZPANEL_DAEMON"
839 save_TAGS="$TAGS"
840 unset_receipt
841 . "$orig_receipt"
842 PACKAGE="$save_PACKAGE"; DEPENDS="$save_DEPENDS"; PROVIDE="$save_PROVIDE"
843 SUGGESTED="$save_SUGGESTED"; TAZPANEL_DAEMON="$save_TAZPANEL_DAEMON"
844 TAGS="$save_TAGS"
846 # Manage split packages
847 SPLIT=" $SPLIT "
848 if [ "$SPLIT" != ' ' -a "${SPLIT/ $PACKAGE /}" != "$SPLIT" ]; then
849 # For packages with empty $DEPENDS
850 if [ -z "$DEPENDS" ]; then
851 case $PACKAGE in
852 *-dev)
853 # main package and all the split packages but this *-dev itself
854 DEPENDS=$(echo "$pkg $SPLIT " | sed "s| $PACKAGE | |; s| *$||") ;;
855 *)
856 # main package
857 DEPENDS="$pkg" ;;
858 esac
859 fi
861 # Default $CAT
862 [ -z "$CAT" ] &&
863 case $PACKAGE in
864 *-dev) CAT="development|development files" ;;
865 esac
866 fi
868 # Manage two-in-one $CAT="$CATEGORY|$SHORT_DESC_ADDITION"
869 if [ -n "$CAT" ]; then
870 CATEGORY="${CAT%|*}"
871 SHORT_DESC="$SHORT_DESC (${CAT#*|})"
872 fi
874 # escape quotes for receipt
875 SHORT_DESC="${SHORT_DESC//\"/\\\"}"
877 # Mandatory variables
878 cat <<EOF
879 $signature
881 PACKAGE="$PACKAGE"
882 VERSION="$VERSION"
883 CATEGORY="$CATEGORY"
884 SHORT_DESC="$SHORT_DESC"
885 MAINTAINER="$MAINTAINER"
886 LICENSE="$LICENSE"
887 WEB_SITE="$WEB_SITE"
888 EOF
890 # Optional variables
891 [ -n "$TAGS" ] && echo "TAGS=\"$TAGS\"" | tr -ds '\t' ' '
892 [ -n "${DEPENDS# }" ] && echo "DEPENDS=\"$DEPENDS\"" | tr -ds '\t' ' '
893 [ -n "$PROVIDE" ] && echo "PROVIDE=\"$PROVIDE\"" | tr -ds '\t' ' '
894 [ -n "$CONFIG_FILES" ] && echo "CONFIG_FILES=\"$CONFIG_FILES\"" | tr -ds '\t' ' '
895 [ -n "$SUGGESTED" ] && echo "SUGGESTED=\"$SUGGESTED\"" | tr -ds '\t' ' '
896 [ -n "$DATABASE_FILES" ] && echo "DATABASE_FILES=\"$DATABASE_FILES\""
897 [ -n "$TAZPANEL_DAEMON" ] && echo "TAZPANEL_DAEMON=\"$TAZPANEL_DAEMON\""
899 # Extract {pre,post}_{install,remove} functions;
900 # post_install() will be copied for both main and all the split packages
901 # post_install_gtk_() will be copied as post_install() for gtk+ package only
902 #
903 # restricted name (gtk+ -> gtk_; acl-dev -> acl_dev)
904 rname=$(echo -n $PACKAGE | tr -c 'a-zA-Z0-9' '_')
905 for i in pre post; do
906 for j in install remove; do
907 sed "/^${i}_${j}()/,/^}/!d" "$orig_receipt"
908 sed "/^${i}_${j}_$rname()/,/^}/!d" "$orig_receipt" | \
909 sed "s|^${i}_${j}_$rname()|${i}_${j}()|"
910 done
911 done
912 }
915 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
916 # but it doesn't handle EXTRAVERSION.
918 packit() {
919 set_paths "$1"
920 PACKAGE="${1:-$PACKAGE}"
922 # Handle cross compilation
923 case "$ARCH" in
924 arm*|x86_64) arch="-$ARCH" ;;
925 esac
927 title 'Pack: %s' "$PACKAGE $VERSION$arch"
929 if grep -q ^genpkg_rules $receipt; then
930 _ 'Executing: %s' 'genpkg_rules'
931 set -e; cd $pkgdir; mkdir -p $fs
932 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
933 $LOGS/$pkg.log
934 else
935 _ 'No packages rules: meta package'
936 mkdir -p $fs
937 fi
939 # Check CONFIG_FILES
940 if [ -n "$CONFIG_FILES" ]; then
941 unset IFS
942 for i in $CONFIG_FILES; do
943 if [ ! -e $fs$i ]; then
944 case $i in
945 */) mkdir -p $fs$i ;;
946 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
947 esac
948 fi
949 done
950 fi
952 # First QA check to stop now if genpkg_rules failed.
953 lerror=$(_n 'ERROR')
954 if fgrep -q ^$lerror $LOGS/$pkg.log; then
955 broken; exit 1
956 fi
958 cd $taz
959 action 'Copying "%s"...' 'receipt'
960 mk_pkg_receipt ../receipt > $pack/receipt
961 chown 0.0 $pack/receipt; status
963 unset desc
964 [ "$pkg" == "$PACKAGE" -a -f "../description.txt" ] && desc="../description.txt"
965 [ -f "../description.$PACKAGE.txt" ] && desc="../description.$PACKAGE.txt"
966 if [ -n "$desc" ]; then
967 action 'Copying "%s"...' "$(basename "$desc")"
968 cp -f $desc $pack/description.txt; chown 0.0 $pack/description.txt; status
969 fi
971 copy_generic_files
973 # Strip and stuff files.
974 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
976 # Create files.list with redirecting find output.
977 action 'Creating the list of files...'
978 cd $fs
979 find . -type f -print > ../files.list
980 find . -type l -print >> ../files.list
981 cd ..; sed -i 's|^.||' files.list
982 status
984 # Md5sum of files.
985 action 'Creating md5sum of files...'
986 while read file; do
987 [ -L "fs$file" ] && continue
988 [ -f "fs$file" ] || continue
989 case "$file" in
990 /lib/modules/*/modules.*|*.pyc) continue ;;
991 esac
992 md5sum "fs$file" | sed 's| fs| |'
993 done < files.list > md5sum
994 status
996 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
997 2>/dev/null | awk 'END{ print $1 }')
999 # Build cpio archive.
1000 action 'Compressing the FS...'
1001 find fs -newer $receipt -exec touch -hr $receipt '{}' \;
1002 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1003 mv fs ../
1004 status
1006 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
1007 2>/dev/null | awk 'END{ print $1 }')
1009 action 'Updating receipt sizes...'
1010 sed -i '/^PACKED_SIZE=/d; /^UNPACKED_SIZE=/d' receipt
1011 sed -i "s|^PACKAGE=|PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=|" receipt
1012 status
1014 # Set extra version.
1015 if [ -n "$EXTRAVERSION" ]; then
1016 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
1017 sed -i '/^EXTRAVERSION=/d' receipt
1018 sed -i "s|^VERSION=|EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=|" receipt
1019 status
1020 fi
1022 # Compress.
1023 action 'Creating full cpio archive...'
1024 find . -newer $receipt -exec touch -hr $receipt '{}' \;
1025 find . | cpio -o -H newc --quiet > ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1026 status
1028 action 'Restoring original package tree...'
1029 mv ../fs .
1030 status
1032 rm fs.cpio.lzma; cd ..
1034 # QA and give info.
1035 tazpkg=$(ls *.tazpkg)
1036 packit_quality
1037 footer "$(_ 'Package "%s" created' "$tazpkg")"
1038 update_packages_db
1042 # Verify package quality and consistency.
1044 packit_quality() {
1045 #action 'QA: checking for broken link...'
1046 #link=$(find $fs/usr -type l -follow)
1047 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
1048 #status
1050 # Exit if any error found in log file.
1051 lerror=$(_n 'ERROR')
1052 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1053 rm -f $command
1054 broken; exit 1
1055 fi
1057 action 'QA: checking for empty package...'
1058 files=$(wc -l < $WOK/$pkg/taz/$PACKAGE-$VERSION$EXTRAVERSION/files.list)
1059 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
1060 broken
1061 rm -f $command
1062 die 'ERROR: empty package'
1063 fi
1065 :; status
1066 # Find and remove old package(s)
1067 tempd="$(mktemp -d)"; cd "$tempd"
1068 for testpkg in $(ls $PKGS/$PACKAGE-*.tazpkg 2>/dev/null); do
1069 # Extract receipt from each matched package
1070 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
1071 name=$(. receipt; echo $PACKAGE)
1072 rm receipt
1073 if [ "$name" == "$PACKAGE" ]; then
1074 action 'Removing old package "%s"' "$(basename "$testpkg")"
1075 rm -f "$testpkg"
1076 status
1077 fi
1078 done
1079 rm -r "$tempd"
1080 mv -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg $PKGS
1081 sed -i "/^${pkg}$/d" $broken
1082 #action 'Removing source tree...'
1083 #rm -f $WOK/$pkg/source; status
1087 # Return all the names of packages bundled in this receipt
1089 all_names() {
1090 local split=" $SPLIT "
1091 if [ "${split/ $PACKAGE /}" != "$split" ]; then
1092 # $PACKAGE included somewhere in $SPLIT (probably in the end).
1093 # We should build packages in the order defined in the $SPLIT.
1094 echo $SPLIT
1095 else
1096 # We'll build the $PACKAGE, then all defined in the $SPLIT.
1097 echo $PACKAGE $SPLIT
1098 fi
1102 # v2: pack all packages using compiled files
1104 packall() {
1105 set_paths
1106 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1107 for i in $(all_names); do
1108 unset TAGS DEPENDS CAT CONFIG_FILES PROVIDE SUGGESTED DATABASE_FILES TAZPANEL_DAEMON
1109 packit $i
1110 done
1111 else
1112 packit
1113 fi
1117 # Reverse "cat" command: prints input lines in the reverse order
1119 tac() {
1120 sed '1!G;h;$!d' $1
1124 # Update chroot with freshly rebuilt package: keep env up-to-date.
1126 update_chroot() {
1127 local PACKAGE="$pkg"
1128 for i in $(all_names); do
1129 if [ -d "$root$INSTALLED/$i" ]; then
1130 . /etc/slitaz/cook.conf
1131 . $WOK/$pkg/taz/$i-$VERSION/receipt
1132 _ 'Updating %s chroot environment...' "$ARCH"
1133 _ 'Updating chroot: %s' "$i ($VERSION$EXTRAVERSION$arch)" | log
1134 cd $PKGS
1135 tazpkg install $i-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1136 fi
1137 done
1141 # Install package on --inst or update the chroot.
1143 install_package() {
1144 case "$ARCH" in
1145 arm*|x86_64)
1146 arch="-$ARCH"
1147 root="$CROSS_TREE/sysroot" ;;
1148 esac
1149 # Install package if requested but skip install if target host doesn't
1150 # match build system or it will break the build chroot.
1151 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1152 if [ -n "$inst" -a "$build" == "$ARCH" ]; then
1153 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1154 cd $PKGS
1155 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1156 else
1157 broken
1158 die 'Unable to install package, build has failed.'
1159 fi
1160 fi
1162 update_chroot
1166 # remove chroot jail
1168 umount_aufs() {
1169 tac ${1}rw/aufs-umount.sh | sh
1170 rm -rf ${1}rw
1171 umount ${1}root
1172 rmdir ${1}r*
1176 # Launch the cook command into a chroot jail protected by aufs.
1177 # The current filesystems are used read-only and updates are
1178 # stored in a separate branch.
1180 try_aufs_chroot() {
1182 base="/dev/shm/aufsmnt$$"
1184 # Can we setup the chroot? Is it already done?
1185 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1186 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1187 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1188 grep -q ^aufs /proc/modules || modprobe aufs 2> /dev/null || return
1189 mkdir ${base}root ${base}rw || return
1191 _ 'Setup aufs chroot...'
1193 # Sanity check
1194 for i in / /proc /sys /dev/shm /home ; do
1195 case " $AUFS_MOUNTS " in
1196 *\ $i\ *) ;;
1197 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1198 esac
1199 done
1200 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1201 mount --bind $mnt ${base}root$mnt
1202 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1203 _ 'Aufs mount failure'
1204 umount ${base}root
1205 rm -rf ${base}r*
1206 return
1207 fi
1208 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1209 done
1210 trap "umount_aufs ${base}" INT
1212 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1213 status=$?
1215 _ 'Leaving aufs chroot...'
1216 umount_aufs $base
1217 # Install package outside the aufs jail
1218 install_package
1219 exit $status
1223 # Encode predefined XML entities
1225 xml_ent() {
1226 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1230 # Create a XML feed for freshly built packages.
1232 gen_rss() {
1233 pubdate=$(date '+%a, %d %b %Y %X')
1234 cat > $FEEDS/$pkg.xml <<EOT
1235 <item>
1236 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1237 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1238 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1239 <pubDate>$pubdate</pubDate>
1240 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1241 </item>
1242 EOT
1246 # Truncate stdout log file to $1 Mb.
1248 loglimit() {
1249 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1250 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1251 else
1252 tee /dev/stderr
1253 fi
1258 # Receipt functions to ease packaging
1261 get_dev_files() {
1262 action 'Getting standard devel files...'
1263 mkdir -p $fs/usr/lib
1264 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1265 cp -a $install/usr/lib/*a $fs/usr/lib
1266 cp -a $install/usr/include $fs/usr
1267 status
1271 # Function to use in compile_rules() to copy man page from $src to $install
1273 cook_pick_manpages() {
1274 local name section
1275 action 'Copying man pages...'
1277 for i in $@; do
1278 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1279 section=${name##*/}; section=${section##*.}
1280 mkdir -p $install/usr/share/man/man$section
1281 scopy $i $install/usr/share/man/man$section
1282 done
1283 status
1287 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1289 cook_copy_files() {
1290 action 'Copying files...'
1291 cd $install
1292 local i j
1293 IFS=$'\n'
1294 for i in $@; do
1295 for j in $(find . -name $i ! -type d); do
1296 mkdir -p $fs$(dirname ${j#.})
1297 scopy $j $fs$(dirname ${j#.})
1298 done
1299 done
1300 cd - >/dev/null
1301 status
1305 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1307 cook_copy_folders() {
1308 action 'Copying folders...'
1309 cd $install
1310 local i j
1311 IFS=$'\n'
1312 for i in $@; do
1313 for j in $(find . -name $i -type d); do
1314 mkdir -p $fs$(dirname ${j#.})
1315 cp -a $j $fs$(dirname ${j#.})
1316 done
1317 done
1318 cd - >/dev/null
1319 status
1323 # Common function to copy files, folders and patterns
1325 copy() {
1326 action 'Copying folders and files...'
1327 local i j filelist=$(mktemp)
1328 IFS=$'\n'
1329 cd $install; find ! -type d | sed 's|\.||' > $filelist
1330 for i in $@; do
1331 case $i in
1332 @std)
1333 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1334 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /bin\/.*-config$/d;
1335 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1336 /\/Makefile.*/d; /\.inc$/d; /\/include\//d;
1337 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1338 /\/share\/devhelp\//d; /\/share\/locale\//d;
1339 /\/share\/bash-completion\//d; /\/lib\/systemd\//d;
1340 ' $filelist
1341 ;;
1342 @dev)
1343 # Copy "developer files"
1344 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.la$/p; /\.pc$/p; /bin\/.*-config$/p;
1345 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1346 /\/Makefile.*/p; /\.inc$/p; /\/include\//p;
1347 ' $filelist
1348 ;;
1349 */)
1350 # Copy specified folders.
1351 i="${i%/}"
1352 find -type d -path "*/${i#/}" | sed 's|^.||'
1353 ;;
1354 *)
1355 # Copy specified files.
1356 find ! -type d -path "*/${i#/}" | sed 's|^.||'
1357 ;;
1358 esac | sort -u | \
1359 while read j; do
1360 mkdir -p $fs$(dirname "$j")
1361 if [ -d "$install$j" ]; then
1362 cp -a "$install$j" $fs$(dirname "$j")
1363 else
1364 scopy "$install$j" $fs$(dirname "$j")
1365 fi
1366 done
1367 done
1368 cd - >/dev/null
1369 unset IFS
1370 rm $filelist
1371 status
1375 # Remove from current $fs files that already packed (for receipts v2).
1376 # Note: the order in $SPLIT is very important.
1378 remove_already_packed() {
1379 local i j
1380 IFS=$'\n'
1381 for i in $taz/*/files.list; do
1382 while read j; do
1383 [ -f $fs$j -o -h $fs$j ] || continue
1384 rm $fs$j
1385 rmdir --parents --ignore-fail-on-non-empty $fs$(dirname $j)
1386 done < $i
1387 done
1388 unset IFS
1392 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1393 # (default: 16 and 48) from $install to $fs
1395 cook_copy_icons() {
1396 local sizes=$@
1397 action 'Copying hicolor icons...'
1398 mkdir -p $fs/usr/share/icons/hicolor
1399 for i in ${sizes:-16 48}; do
1400 [ ! -e "$install/usr/share/icons/hicolor/${i}x$i" ] ||
1401 scopy $install/usr/share/icons/hicolor/${i}x$i \
1402 $fs/usr/share/icons/hicolor
1403 done
1404 status
1408 # Update packages database every time after successful build
1410 update_packages_db() {
1411 # packages.info (unsorted, located near to packages)
1412 local pi="$PKGS/packages.info"
1413 sed -i "/^$PACKAGE\t/d" $pi
1414 unset_receipt; . $pack/receipt
1415 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1416 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1417 MD5="$(md5sum "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" | awk '{print $1}')"
1418 cat >> $pi <<EOT
1419 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5 $PROVIDE
1420 EOT
1422 # files.list (uncompressed, unsorted, located in $cache)
1423 local fl="$cache/files.list"
1424 touch $fl
1425 sed -i "/^$PACKAGE: /d" $fl
1426 sed "s/^/$PACKAGE: \0/" $pack/files.list >> $fl
1430 # Update split.db once for receipt
1432 update_split_db() {
1433 local db="$cache/split.db"
1434 touch $db
1435 sed -i "/^$pkg\t/d" $db
1436 echo -e "$pkg\t$(all_names)" >> $db
1440 # Recreate whole split.db from scratch
1442 recreate_split_db() {
1443 # Clean
1444 local db="$cache/split.db"
1445 touch $db
1446 > $db
1448 cd $WOK
1449 for i in *; do
1450 [ -f "$WOK/$i/receipt" ] || continue
1451 unset PACKAGE SPLIT
1452 . $WOK/$i/receipt
1453 echo -e "$PACKAGE\t$(all_names)" >> $db
1454 done
1461 # Commands
1464 # cook <package> --deps
1465 [ -n "$deps" ] && { @@PREFIX@@/libexec/cookutils/deps $1; exit 0; }
1468 case "$1" in
1469 usage|help|-u|-h)
1470 usage ;;
1472 list-wok)
1473 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1474 cd $WOK
1475 if [ "$ARCH" != 'i486' ]; then
1476 count=0
1477 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1478 do
1479 unset HOST_ARCH
1480 . $pkg
1481 count=$(($count + 1))
1482 colorize 34 "$PACKAGE"
1483 done
1484 else
1485 count=$(ls | wc -l)
1486 ls -1
1487 fi
1488 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1489 ;;
1491 activity)
1492 cat $activity ;;
1494 search)
1495 # Just a simple search function, we don't need more actually.
1496 query="$2"
1497 title 'Search results for "%s"' "$query"
1498 cd $WOK; ls -1 | grep "$query"
1499 footer ;;
1501 setup)
1502 # Setup a build environment
1503 check_root
1504 _ 'Cook: setup environment' | log
1505 title 'Setting up your environment'
1506 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1507 cd $SLITAZ
1508 init_db_files
1509 _ 'Checking for packages to install...'
1510 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1511 # ARCH-setup or 'cross check' should be used before: cook setup
1512 case "$ARCH" in
1513 arm*|x86_64)
1514 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1515 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1516 . /etc/slitaz/cross.conf ;;
1517 esac
1518 for pkg in $SETUP_PKGS; do
1519 if [ -n "$forced" ]; then
1520 tazpkg -gi $pkg --forced
1521 else
1522 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1523 fi
1524 done
1526 # Handle --options
1527 case "$2" in
1528 --wok) hg clone $WOK_URL wok || exit 1 ;;
1529 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1530 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1531 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1532 esac
1534 # SliTaz group and permissions
1535 if ! grep -q ^slitaz /etc/group; then
1536 _ 'Adding group "%s"' 'slitaz'
1537 addgroup slitaz
1538 fi
1539 _ 'Setting permissions for group "%s"...' 'slitaz'
1540 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1541 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1542 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1544 *-setup)
1545 # Setup for cross compiling.
1546 arch="${1%-setup}"
1547 check_root
1548 . /etc/slitaz/cook.conf
1549 for pkg in $CROSS_SETUP; do
1550 if [ -n "$forced" ]; then
1551 tazpkg -gi $pkg --forced
1552 else
1553 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1554 fi
1555 done
1557 _ 'Cook: setup %s cross environment' "$arch" | log
1558 title 'Setting up your %s cross environment' "$arch"
1559 init_db_files
1560 sed -i \
1561 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1562 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1563 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1564 /etc/slitaz/cook.conf
1565 case "$arch" in
1566 arm)
1567 flags='-O2 -march=armv6'
1568 host="$ARCH-slitaz-linux-gnueabi" ;;
1569 armv6hf)
1570 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1571 host="$ARCH-slitaz-linux-gnueabi" ;;
1572 armv7)
1573 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1574 host="$ARCH-slitaz-linux-gnueabi" ;;
1575 x86_64)
1576 flags='-O2 -mtune=generic -pipe'
1577 host="$ARCH-slitaz-linux" ;;
1578 esac
1579 sed -i \
1580 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1581 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1582 . /etc/slitaz/cook.conf
1583 sysroot="$CROSS_TREE/sysroot"
1584 tools="/cross/$arch/tools"
1585 root="$sysroot"
1586 # L10n: keep the same width of translations to get a consistent view
1587 _ 'Target arch : %s' "$ARCH"
1588 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1589 _ 'Build flags : %s' "$flags"
1590 _ 'Arch sysroot : %s' "$sysroot"
1591 _ 'Tools prefix : %s' "$tools/bin"
1592 # Tell the packages manager where to find packages.
1593 _ 'Packages DB : %s' "$root$DB"
1594 mkdir -p $root$INSTALLED
1595 cd $root$DB; rm -f *.bak
1596 for list in packages.list packages.desc packages.equiv packages.md5; do
1597 rm -f $list
1598 ln -s $SLITAZ/packages/$list $list
1599 done
1600 # We must have the cross compiled glibc-base installed or default
1601 # i486 package will be used as dep by tazpkg and then break the
1602 # cross environment
1603 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1604 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1605 fi
1606 # Show GCC version or warn if not yet compiled.
1607 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1608 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1609 else
1610 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1611 _ 'Run "%s" to cook a toolchain' 'cross compile'
1612 fi
1613 footer ;;
1615 test)
1616 # Test a cook environment.
1617 _ 'Cook test: testing the cook environment' | log
1618 [ ! -d "$WOK" ] && exit 1
1619 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1620 cook cooktest ;;
1622 new)
1623 # Create the package folder and an empty receipt.
1624 pkg="$2"
1625 [ -z "$pkg" ] && usage
1626 newline
1627 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1629 action 'Creating folder "%s"' "$WOK/$pkg"
1630 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1632 action 'Preparing the package receipt...'
1633 cp $DATA/receipt .
1634 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1635 status; newline
1637 # Interactive mode, asking and seding.
1638 case "$3" in
1639 --interactive|-x)
1640 _ 'Entering interactive mode...'
1641 separator
1642 _ 'Package : %s' "$pkg"
1644 _n 'Version : ' ; read answer
1645 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1647 _n 'Category : ' ; read answer
1648 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1650 # L10n: Short description
1651 _n 'Short desc : ' ; read answer
1652 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1654 _n 'Maintainer : ' ; read answer
1655 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1657 _n 'License : ' ; read answer
1658 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1660 _n 'Web site : ' ; read answer
1661 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1662 newline
1664 # Wget URL.
1665 _ 'Wget URL to download source tarball.'
1666 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1667 _n 'Wget url : ' ; read answer
1668 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1670 # Ask for a stuff dir.
1671 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1672 if [ "$?" -eq 0 ]; then
1673 action 'Creating the stuff directory...'
1674 mkdir $WOK/$pkg/stuff; status
1675 fi
1677 # Ask for a description file.
1678 confirm "$(_n 'Are you going to write a description? (y/N)')"
1679 if [ "$?" -eq 0 ]; then
1680 action 'Creating the "%s" file...' 'description.txt'
1681 touch $WOK/$pkg/description.txt; status
1682 fi
1684 footer "$(_ 'Receipt is ready to use.')" ;;
1685 esac ;;
1687 list)
1688 # Cook a list of packages (better use the Cooker since it will order
1689 # packages before executing cook).
1690 check_root
1691 [ -z "$2" ] && die 'No list in argument.'
1692 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1694 _ 'Starting cooking the list "%s"' "$2" | log
1696 while read pkg; do
1697 cook $pkg || broken
1698 done < $2
1699 ;;
1701 clean-wok)
1702 check_root
1703 newline; action 'Cleaning all packages files...'
1704 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1705 status; newline ;;
1707 clean-src)
1708 check_root
1709 newline; action 'Cleaning all packages sources...'
1710 rm -rf $WOK/*/source
1711 status; newline ;;
1713 uncook)
1714 cd $WOK
1715 count=0
1716 title 'Checking for uncooked packages'
1718 for pkg in *; do
1719 unset HOST_ARCH EXTRAVERSION
1720 [ ! -e $pkg/receipt ] && continue
1721 . $pkg/receipt
1722 # Source cooked pkg receipt to get EXTRAVERSION
1723 if [ -d "$WOK/$pkg/taz" ]; then
1724 cd $WOK/$pkg/taz/$pkg-*
1725 . receipt; cd $WOK
1726 fi
1727 case "$ARCH" in
1728 i486)
1729 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1730 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1731 count=$(($count + 1))
1732 colorize 34 "$pkg"
1733 fi ;;
1734 arm*)
1735 # Check only packages included in arch
1736 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1737 # *.tazpkg
1738 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1739 count=$(($count + 1))
1740 colorize 34 "$pkg"
1741 fi
1742 fi ;;
1743 esac
1744 done
1746 if [ "$count" -gt 0 ]; then
1747 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1748 else
1749 _ 'All packages are cooked :-)'
1750 newline
1751 fi
1752 ;;
1754 pkgdb)
1755 # Create suitable packages list for TazPkg and only for built packages
1756 # as well as flavors files for TazLiTo. We don't need logs since we do it
1757 # manually to ensure everything is fine before syncing the mirror.
1758 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1759 ;;
1761 splitdb)
1762 # File split.db is useful for searching for split packages.
1763 recreate_split_db
1764 ;;
1766 *)
1767 # Just cook and generate a package.
1768 check_root
1769 time=$(date +%s)
1770 pkg="$1"
1771 [ -z "$pkg" ] && usage
1773 # Search last successful cook time in all logs from newer to older
1774 for i in '' $(seq 0 9 | sed 's|^|.|'); do
1775 [ -f "$LOGS/$pkg.log$i" ] || break
1776 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1777 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
1778 [ -n "$lastcooktime" ] && break
1779 done
1781 receipt="$WOK/$pkg/receipt"
1782 check_pkg_in_wok
1783 newline
1785 unset inst
1786 unset_receipt
1787 . $receipt
1789 # Handle cross compilation.
1790 case "$ARCH" in
1791 arm*)
1792 if [ -z "$HOST_ARCH" ]; then
1793 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1794 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1795 _ 'cook: %s' "$error"
1796 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1797 _ 'Cook skip: %s' "$error" | log
1798 newline
1799 broken; exit 1
1800 fi ;;
1801 esac
1803 # Some packages are not included in some arch or fail to cross compile.
1804 : ${HOST_ARCH=i486}
1805 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1806 # Handle arm{v6hf,v7,..}
1807 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1808 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1809 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1810 _ 'cook: %s' "error"
1811 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1812 _ 'Cook skip: %s' "$error" | log
1813 sed -i "/^${pkg}$/d" $broken
1814 newline
1815 exit 0
1816 fi
1818 # Skip blocked, 3 lines also for the Cooker.
1819 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1820 die 'Package "%s" is blocked' "$pkg"
1822 try_aufs_chroot "$@"
1824 # Log and source receipt.
1825 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1826 echo "cook:$pkg" > $command
1828 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1830 while read cmd duration start; do
1831 [ $(($start + $duration)) -lt $(date +%s) ] &&
1832 echo "sed -i '/^$cmd $duration/d' $cooktime"
1833 done < $cooktime | sh
1835 # Display and log info if cook process stopped.
1836 # FIXME: gettext not working (in single quotes) here!
1837 trap '_ "\n\nCook stopped: control-C\n\n" | \
1838 tee -a $LOGS/$pkg.log' INT
1840 update_split_db
1842 # Handle --options
1843 case "$2" in
1844 --clean|-c)
1845 action 'Cleaning "%s"' "$pkg"
1846 cd $WOK/$pkg; rm -rf install taz source
1847 status; newline
1848 exit 0 ;;
1850 --install|-i)
1851 inst='yes' ;;
1853 --getsrc|-gs)
1854 title 'Getting source for "%s"' "$pkg"
1855 get_source
1856 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1857 exit 0 ;;
1859 --block|-b)
1860 action 'Blocking package "%s"' "$pkg"
1861 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1862 status; newline
1863 exit 0 ;;
1865 --unblock|-ub)
1866 action 'Unblocking package "%s"' "$pkg"
1867 sed -i "/^${pkg}$/d" $blocked
1868 status; newline
1869 exit 0 ;;
1871 --pack)
1872 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
1873 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
1874 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -rf $LOGS/$pkg-pack.log
1875 sed -i '$ s|$| (packing)|' $activity
1876 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
1877 clean_log "$pkg-pack"
1878 time=$(($(date +%s) - $time))
1879 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
1880 sed -i '$ s|$| [ Done ]|' $activity
1881 rm -f $command
1882 exit 0 ;;
1883 esac
1885 # Rotate log
1886 for i in $(seq 9 -1 1); do
1887 j=$(($i - 1))
1888 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1889 done
1890 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1892 # Check if wanted is built now so we have separate log files.
1893 for wanted in $WANTED ; do
1894 if grep -q "^$wanted$" $blocked; then
1895 broken
1896 rm -f $command
1897 die 'WANTED package "%s" is blocked' "$wanted"
1898 fi
1899 if grep -q "^$wanted$" $broken; then
1900 broken
1901 rm -f $command
1902 die 'WANTED package "%s" is broken' "$wanted"
1903 fi
1904 if [ ! -d "$WOK/$wanted/install" ]; then
1905 cook "$wanted" || { broken; exit 1; }
1906 fi
1907 done
1909 # Cook and pack or exit on error and log everything.
1910 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1911 remove_deps | tee -a $LOGS/$pkg.log
1912 cookit_quality
1913 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1914 clean_log
1916 # Exit if any error in packing.
1917 lerror=$(_n 'ERROR')
1918 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1919 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1920 debug_info | tee -a $LOGS/$pkg.log
1921 sed -i '$ s|$| [ Failed ]|' $activity
1922 rm -f $command
1923 broken; exit 1
1924 fi
1926 # Create an XML feed
1927 gen_rss
1929 # Time and summary
1930 time=$(($(date +%s) - $time))
1931 summary | tee -a $LOGS/$pkg.log
1932 newline
1934 # We may want to install/update (outside aufs jail!).
1935 [ -s /aufs-umount.sh ] || install_package
1937 sed -i '$ s|$| [ Done ]|' $activity
1939 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1940 # If you want automation, use the Cooker Build Bot.
1941 rm -f $command
1942 ;;
1943 esac
1945 exit 0