cookutils view cook @ rev 596

cook: rework and finish i18n (for local use), translate to Russian
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Mar 29 17:05:30 2013 +0000 (2013-03-29)
parents fe2d8f2ac5e4
children f3eb8e8e9d2e
line source
1 #!/bin/sh
2 #
3 # Cook - A tool to cook and generate SliTaz packages. Read the README
4 # before adding or modifing any code in cook!
5 #
6 # Copyright (C) SliTaz GNU/Linux - GNU gpl v3
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
9 . /usr/lib/slitaz/libcook.sh
11 VERSION="3.1.4"
13 # Internationalization.
14 . /usr/bin/gettext.sh
15 TEXTDOMAIN='cook'
16 export TEXTDOMAIN
18 _() echo -e "$(eval_gettext "$1")"
19 _n() echo -en "$(eval_gettext "$1")"
20 # to disable i18n:
21 # _() echo -e "$1"
22 # _n() echo -en "$1"
25 #
26 # Functions
27 #
29 usage() {
30 cat << EOT
32 $(_ "\033[1mUsage:\033[0m cook [package|command] [list|--option]")
34 $(_ "\033[1mCommands:\033[0m")
35 usage|help $(_ "Display this short usage.")
36 setup $(_ "Setup your build environment.")
37 *-setup $(_ "Setup a cross environment.")
38 test $(_ "Test environment and cook a package.")
39 list-wok $(_ "List packages in the wok.")
40 search $(_ "Simple packages search function.")
41 new $(_ "Create a new package with a receipt.")
42 list $(_ "Cook a list of packages.")
43 clean-wok $(_ "Clean-up all packages files.")
44 clean-src $(_ "Clean-up all packages sources.")
45 pkgdb $(_ "Create packages DB lists and flavors.")
47 $(_ "\033[1mOptions:\033[0m")
48 --clean|-c Cook : $(_ "clean the package in the wok.")
49 --install|-i Cook : $(_ "cook and install the package.")
50 --getsrc|-gs Cook : $(_ "get the package source tarball.")
51 --block|-b Cook : $(_ "block a package so cook will skip it.")
52 --unblock|-ub Cook : $(_ "unblock a blocked package.")
53 --pack Cook : $(_ "repack an already built package.")
54 --interactive|-x New : $(_ "create a receipt interactively.")
55 --wok Setup: $(_ "clone the cooking wok from Hg repo.")
56 --stable Setup: $(_ "clone the stable wok from Hg repo.")
57 --undigest Setup: $(_ "clone the undigest wok from Hg repo.")
58 --tiny Setup: $(_ "clone the tiny SliTaz wok from Hg repo.")
59 --forced Setup: $(_ "force reinstall of chroot packages.")
60 --flavors Pkgdb: $(_ "create up-to-date flavors files.")
62 EOT
63 exit 0
64 }
66 # We don't want these escapes in web interface.
67 clean_log() {
68 sed -i -e s'|\[70G\[ \[1;32m| |' \
69 -e s'|\[0;39m \]||' $LOGS/$pkg.log
70 }
72 # Be sure package exists in wok.
73 check_pkg_in_wok() {
74 if [ ! -d "$WOK/$pkg" ]; then
75 newline; _ "Unable to find package in the wok: \$pkg"; newline
76 exit 1
77 fi
78 }
80 if_empty_value() {
81 if [ -z "$value" ]; then
82 # L10n: QA is quality assurance
83 _ "QA: empty variable: \${var}=\"\""; newline
84 exit 1
85 fi
86 }
88 # Initialize files used in $CACHE
89 init_db_files() {
90 _ "Creating directories structure in: \$SLITAZ"
91 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
92 _ "Creating DB files in: \$CACHE"
93 for f in $activity $command $broken $blocked
94 do
95 touch $f
96 done
97 }
99 # QA: check a receipt consistency before building.
100 receipt_quality() {
101 _ "QA: checking package receipt..."
102 unset online
103 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
104 online="online"
105 fi
106 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
107 do
108 unset value
109 value="$(. $receipt ; eval echo \$$var)"
110 case "$var" in
111 PACKAGE|VERSION|SHORT_DESC)
112 if_empty_value ;;
113 CATEGORY)
114 [ -z "$value" ] && value="empty"
115 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
116 if ! echo "$valid" | grep -q -w "$value"; then
117 _ "QA: unknown category: \$value"
118 _ "Please, use one of: \$valid" | busybox fold -s
119 newline; exit 1
120 fi ;;
121 WEB_SITE)
122 # We don't check WGET_URL since if dl is needed it will fail.
123 # Break also if we're not online. Here error is not fatal.
124 if_empty_value
125 [ -z "$online" ] || break
126 if ! busybox wget -T 12 -s $value 2>/dev/null; then
127 _ "QA: unable to reach: \$value"
128 fi ;;
129 esac
130 done
131 }
133 # Paths used in receipt and by cook itself.
134 set_paths() {
135 pkgdir=$WOK/$PACKAGE
136 basesrc=$pkgdir/source
137 tmpsrc=$basesrc/tmp
138 src=$basesrc/$PACKAGE-$VERSION
139 taz=$pkgdir/taz
140 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
141 fs=$pack/fs
142 stuff=$pkgdir/stuff
143 install=$pkgdir/install
144 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
145 lzma_tarball="$pkgsrc.tar.lzma"
146 if [ "$PATCH" ]; then
147 [ "${PTARBALL}" ] || PTARBALL="$(basename $PATCH)"
148 fi
149 if [ "$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
155 if [ "$SOURCE" ]; then
156 source_stuff=$WOK/$SOURCE/stuff
157 fi
158 # Kernel version is set from linux
159 if [ -f "$WOK/linux/receipt" ]; then
160 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d '"' -f 2)
161 kbasevers=${kvers:0:3}
162 fi
163 # Python version
164 if [ -f "$WOK/python/receipt" ]; then
165 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d '"' -f 2)
166 fi
167 # perl version for some packages needed it
168 if [ -f "$WOK/perl/receipt" ]; then
169 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d '"' -f 2)
170 fi
171 # Old way compatibility.
172 _pkg=$install
173 }
175 # Create source tarball when URL is a SCM.
176 create_tarball() {
177 local tarball
178 tarball=$pkgsrc.tar.bz2
179 [ "$LZMA_SRC" ] && tarball=$lzma_tarball
180 _ "Creating tarball: \$tarball"
181 if [ "$LZMA_SRC" ]; then
182 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
183 LZMA_SRC=""
184 else
185 tar cjf $tarball $pkgsrc || exit 1
186 mv $tarball $SRC && rm -rf $pkgsrc
187 fi
188 TARBALL=$tarball
189 }
191 # Get package source. For SCM we are in cache so clone here and create a
192 # tarball here.
193 get_source() {
194 set_paths
195 pwd=$(pwd)
196 case "$WGET_URL" in
197 http://*|ftp://*)
198 # Busybox Wget is better!
199 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
200 (_ "ERROR: wget \$WGET_URL" && exit 1) ;;
201 https://*)
202 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
203 (_ "ERROR: wget \$WGET_URL" && exit 1) ;;
204 hg*|mercurial*)
205 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
206 url=${WGET_URL#hg|}
207 else
208 url=${WGET_URL#mercurial|}
209 fi
210 _ "Getting source from Hg..."
211 _ "URL: \$url"
212 _ "Cloning to: \$pwd/\$pkgsrc"
213 if [ "$BRANCH" ]; then
214 _ "Hg branch: \$BRANCH"
215 hg clone $url --rev $BRANCH $pkgsrc || \
216 (_ "ERROR: hg clone \$url --rev \$BRANCH" && exit 1)
217 else
218 hg clone $url $pkgsrc || (_ "ERROR: hg clone \$url" && exit 1)
219 fi
220 rm -rf $pkgsrc/.hg
221 create_tarball ;;
222 git*)
223 url=${WGET_URL#git|}
224 _ "Getting source from Git..."
225 _ "URL: \$url"
226 git clone $url $pkgsrc || (_ "ERROR: git clone \$url" && exit 1)
227 if [ "$BRANCH" ]; then
228 _ "Git branch: \$BRANCH"
229 cd $pkgsrc && git checkout $BRANCH && cd ..
230 fi
231 create_tarball ;;
232 cvs*)
233 url=${WGET_URL#cvs|}
234 mod=$PACKAGE
235 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
236 _ "Getting source from CVS..."
237 _ "URL: \$url"
238 [ "$CVS_MODULE" ] && _ "CVS module: \$mod"
239 _ "Cloning to: \$pwd/\$mod"
240 cvs -d:$url co $mod && mv $mod $pkgsrc
241 create_tarball ;;
242 svn*|subversion*)
243 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
244 url=${WGET_URL#svn|}
245 else
246 url=${WGET_URL#subversion|}
247 fi
248 _ "Getting source from SVN..."
249 _ "URL: \$url"
250 if [ "$BRANCH" ]; then
251 echo t | svn co $url -r $BRANCH $pkgsrc
252 else
253 echo t | svn co $url $pkgsrc
254 fi
255 create_tarball ;;
256 bzr*)
257 url=${WGET_URL#bzr|}
258 _ "Getting source from bazaar..."
259 cd $SRC
260 pkgsrc=${url#*:}
261 if [ "$BRANCH" ]; then
262 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
263 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
264 else
265 echo "bzr -Ossl.cert_reqs=none branch $url"
266 bzr -Ossl.cert_reqs=none branch $url
267 cd $pkgsrc && BRANCH=$(bzr revno) && cd ..
268 _ "Don't forget to add to receipt:"
269 echo 'BRANCH="'$BRANCH'"'; newline
270 fi
271 mv $pkgsrc $pkgsrc-$BRANCH
272 pkgsrc=$pkgsrc-$BRANCH
273 create_tarball ;;
274 *)
275 (newline; _ "ERROR: Unable to handle: \$WGET_URL"; newline) | \
276 tee -a $LOGS/$PACKAGE.log
277 exit 1 ;;
278 esac
279 }
281 # Extract source package.
282 extract_source() {
283 if [ ! -s "$SRC/$TARBALL" ]; then
284 local url
285 url="$MIRROR_URL/sources/packages"
286 url=$url/${TARBALL:0:1}/$TARBALL
287 _ "Getting source from mirror: \$url"
288 busybox wget -c -P $SRC $url || _ "ERROR: wget \$url"
289 fi
290 _ "Extracting: \$TARBALL"
291 case "$TARBALL" in
292 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
293 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
294 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
295 *.tar) tar xf $SRC/$TARBALL ;;
296 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
297 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
298 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
299 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
300 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
301 *) cp $SRC/$TARBALL $(pwd) ;;
302 esac
303 }
305 # Display cooked package summary.
306 summary() {
307 cd $WOK/$pkg
308 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
309 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
310 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
311 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
312 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
313 [ "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
314 cookdate=$(date "$(_ '+%Y-%m-%d %H:%M')")
315 sec=$time
316 div=$(( ($time + 30) / 60))
317 # L10n: 'm' is for minutes (approximate cooking time)
318 min=$(_n "~ \${div}m"); [ "$div" = 0 ] && min=""
319 _ "Summary for: \$PACKAGE \$VERSION"
320 separator
321 # L10n: keep the same width of translations to get a consistent view
322 [ "$srcdir" ] && _ "Source dir : \$srcdir"
323 [ "$TARBALL" ] && _ "Src file : \$TARBALL"
324 [ "$srcsize" ] && _ "Src size : \$srcsize"
325 [ "$prod" ] && _ "Produced : \$prod"
326 _ "Packed : \$fs"
327 _ "Compressed : \$size"
328 _ "Files : \$files"
329 # L10n: 's' is for seconds (cooking time)
330 _ "Cook time : \${sec}s \$min"
331 _ "Cook date : \$cookdate"
332 _ "Host arch : \$ARCH"
333 separator
334 }
336 # Display debugging error info.
337 debug_info() {
338 newline; _ "Debug information"; separator
339 # L10n: specify your format of date and time (to help: man date)
340 # L10n: not bad one is '+%x %R'
341 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
342 _ "Cook date: \$datenow"
343 # L10n: Please, translate all messages beginning with ERROR in a same way
344 lerror=$(_n "ERROR")
345 for error in \
346 ERROR $lerror "No package" "cp: can't" "can't open" "can't cd" \
347 "error:" "fatal error:" "undefined reference to" \
348 "Unable to connect to" "link: cannot find the library" \
349 "CMake Error"
350 do
351 fgrep "$error" $LOGS/$pkg.log
352 done
353 separator; newline
354 }
356 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
357 # so some packages need to copy these files with the receipt and genpkg_rules.
358 copy_generic_files()
359 {
360 # $LOCALE is set in cook.conf
361 if [ "$LOCALE" -a "$WANTED" = "" ]; then
362 if [ -d "$install/usr/share/locale" ]; then
363 mkdir -p $fs/usr/share/locale
364 for i in $LOCALE
365 do
366 if [ -d "$install/usr/share/locale/$i" ]; then
367 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
368 fi
369 done
370 fi
371 fi
373 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
374 if [ "$GENERIC_PIXMAPS" != "no" ]; then
375 if [ -d "$install/usr/share/pixmaps" ]; then
376 mkdir -p $fs/usr/share/pixmaps
377 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
378 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
379 $fs/usr/share/pixmaps
380 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
381 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
382 $fs/usr/share/pixmaps
383 fi
384 fi
386 # Custom or homemade PNG pixmap can be in stuff.
387 if [ -f "$stuff/$PACKAGE.png" ]; then
388 mkdir -p $fs/usr/share/pixmaps
389 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
390 fi
391 fi
393 # Desktop entry (.desktop).
394 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
395 if [ "$GENERIC_MENUS" != "no" ]; then
396 if [ -d "$install/usr/share/applications" ] && [ "$WANTED" == "" ]; then
397 mkdir -p $fs/usr/share
398 cp -a $install/usr/share/applications $fs/usr/share
399 fi
400 fi
402 # Homemade desktop file(s) can be in stuff.
403 if [ -d "$stuff/applications" ]; then
404 mkdir -p $fs/usr/share
405 cp -a $stuff/applications $fs/usr/share
406 fi
407 if [ -f "$stuff/$PACKAGE.desktop" ]; then
408 mkdir -p $fs/usr/share/applications
409 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
410 fi
412 # Add custom licenses
413 if [ -d "$stuff/licenses" ]; then
414 mkdir -p $fs/usr/share/licenses
415 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
416 fi
417 }
419 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
420 # as removing uneeded files like in Python packages. Cross compiled binaries
421 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
422 strip_package() {
423 case "$ARCH" in
424 arm|x86_64) export STRIP=${HOST_SYSTEM}-strip ;;
425 *) export STRIP=strip ;;
426 esac
427 _n "Executing strip on all files..."
428 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
429 do
430 if [ -d "$dir" ]; then
431 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
432 fi
433 done
434 find $fs -name "*.so*" -exec $STRIP -s '{}' 2>/dev/null \;
435 find $fs -name "*.a" -exec $STRIP --strip-debug '{}' 2>/dev/null \;
436 status
438 # Remove Python .pyc and .pyo from packages.
439 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
440 _n "Removing Python compiled files..."
441 find $fs -type f -name "*.pyc" -delete 2>/dev/null
442 find $fs -type f -name "*.pyo" -delete 2>/dev/null
443 status
444 fi
446 # Remove Perl perllocal.pod and .packlist from packages.
447 if echo "$DEPENDS" | fgrep -q "perl"; then
448 _n "Removing Perl compiled files..."
449 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
450 find $fs -type f -name ".packlist" -delete 2>/dev/null
451 status
452 fi
453 }
455 # Remove installed deps.
456 remove_deps() {
457 # Now remove installed build deps.
458 diff="$CACHE/installed.cook.diff"
459 if [ -s "$CACHE/installed.cook.diff" ]; then
460 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
461 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
462 _n "Build dependencies to remove: "; echo $nb $root
463 _n "Removing:"
464 for dep in $deps
465 do
466 echo -n " $dep"
467 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
468 done
469 newline; newline
470 # Keep the last diff for debug and info.
471 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
472 fi
473 }
475 # The main cook function.
476 cookit() {
477 _ "Cook: \$PACKAGE \$VERSION"; separator
478 set_paths
480 # Handle cross-tools.
481 case "$ARCH" in
482 arm|x86_64)
483 # CROSS_COMPILE is used by at least Busybox and the kernel to set
484 # the cross-tools prefix. Sysroot is the root of our target arch
485 sysroot=$CROSS_TREE/sysroot
486 tools=$CROSS_TREE/tools
487 # Set root path when cross compiling. ARM tested but not x86_64
488 # When cross compiling we must install build deps in $sysroot.
489 arch="-${ARCH}"
490 root=$sysroot
491 _ "\$ARCH sysroot: \$sysroot"
492 _ "Adding \$tools/bin to PATH"
493 export PATH=$PATH:$tools/bin
494 export PKG_CONFIG_PATH=$sysroot/usr/lib/pkgconfig
495 export CROSS_COMPILE=${HOST_SYSTEM}-
496 _ "Using cross-tools: \$CROSS_COMPILE"
497 if [ "$ARCH" == "x86_64" ]; then
498 export CC="${HOST_SYSTEM}-gcc -m64"
499 export CXX="${HOST_SYSTEM}-g++ -m64"
500 else
501 export CC=${HOST_SYSTEM}-gcc
502 export CXX=${HOST_SYSTEM}-g++
503 fi
504 export AR=${HOST_SYSTEM}-ar
505 export AS=${HOST_SYSTEM}-as
506 export RANLIB=${HOST_SYSTEM}-ranlib
507 export LD=${HOST_SYSTEM}-ld
508 export STRIP=${HOST_SYSTEM}-strip ;;
509 esac
511 [ "$QA" ] && receipt_quality
512 cd $pkgdir
513 rm -rf install taz source
515 # Disable -pipe if less than 512Mb free RAM.
516 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
517 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
518 _ "Disabling -pipe compile flag: \$free RAM"
519 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
520 CXXFLAGS="${CXXFLAGS/-pipe}" && \
521 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
522 fi
523 unset free
525 # Export flags and path to be used by make and receipt.
526 DESTDIR=$pkgdir/install
527 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
528 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
529 #LDFLAGS
531 # Check for build deps and handle implicit depends of *-dev packages
532 # (ex: libusb-dev :: libusb).
533 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
534 touch $CACHE/installed.local $CACHE/installed.web
535 [ "$BUILD_DEPENDS" ] && _ "Checking build dependencies..."
536 [ "$root" ] && _ "Using packages DB: \${root}\$DB"
537 for dep in $BUILD_DEPENDS
538 do
539 implicit=${dep%-dev}
540 for i in $dep $implicit
541 do
542 if [ ! -f "${root}$INSTALLED/$i/receipt" ]; then
543 # Try local package first. In some cases implicit doesn't exist, ex:
544 # libboost-dev exists but not libboost, so check if we got vers.
545 unset vers
546 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
547 # We may have a local package.
548 if [ ! "$vers" ]; then
549 vers=$(grep "^$i |" $PKGS/packages.desc | awk '{print $3}')
550 fi
551 debug "bdep: $i version: $vers"
552 if [ -f "$PKGS/$i-${vers}${arch}.tazpkg" ]; then
553 echo $i-${vers}${arch}.tazpkg >> $CACHE/installed.local
554 else
555 # Priority to package version in wok (maybe more up-to-date)
556 # than the mirrored one.
557 if [ "$vers" ]; then
558 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
559 echo $i >> $CACHE/installed.web
560 else
561 # So package exists in wok but not available.
562 _ "Missing dep (wok/pkg): \$i \$vers"
563 echo $i >> $CACHE/missing.dep
564 fi
565 else
566 # Package is not in wok but may be in online repo.
567 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
568 echo $i >> $CACHE/installed.web
569 else
570 _ "ERROR: unknown dep \$i"; exit 1
571 fi
572 fi
573 fi
574 fi
575 done
576 done
578 # Get the list of installed packages
579 cd ${root}$INSTALLED && ls -1 > $CACHE/installed.list
581 # Have we a missing build dep to cook?
582 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
583 _ "Auto cook config is set: AUTO_COOK"
584 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
585 for i in $(uniq $CACHE/missing.dep)
586 do
587 (_ "Building dep (wok/pkg) : \$i \$vers") | \
588 tee -a $LOGS/$PACKAGE.log.$$
589 # programmers: next two messages are exact copy from remove_deps()
590 togrep1=$(_n "Build dependencies to remove: ")
591 togrep2=$(_n "Removing:")
592 cook $i || (_ "ERROR: can't cook dep '\$i'" && newline && \
593 fgrep $togrep1 $LOGS/$i.log && \
594 fgrep $togrep2 $LOGS/$i.log && newline) | \
595 tee -a $LOGS/$PACKAGE.log.$$ && break
596 done
597 rm -f $CACHE/missing.dep
598 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
599 fi
601 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
602 # is enabled and cook fails we have ERROR in log, if no auto cook we have
603 # missing dep in cached file.
604 lerror=$(_n "ERROR")
605 if fgrep -q $lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
606 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
607 _ "ERROR: missing dep \$nb" && exit 1
608 fi
610 # Install local packages: package-version${arch}
611 cd $PKGS
612 for i in $(uniq $CACHE/installed.local)
613 do
614 _ "Installing dep (pkg/local): \$i"
615 tazpkg install $i --root=$root >/dev/null
616 done
618 # Install web or cached packages (if mirror is set to $PKGS we only
619 # use local packages).
620 for i in $(uniq $CACHE/installed.web)
621 do
622 _ "Installing dep (web/cache): \$i"
623 tazpkg get-install $i --root=$root >/dev/null
624 done
626 # If a cook failed deps are removed.
627 cd ${root}$INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
628 [ ! -s "installed.cook.diff" ] && \
629 busybox diff installed.list installed.cook > installed.cook.diff
630 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
632 # Get source tarball and make sure we have source dir named:
633 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
634 # tarball if it exists.
635 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
636 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
637 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
638 LZMA_SRC=""
639 else
640 get_source || exit 1
641 fi
642 fi
643 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
644 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
645 if ! extract_source ; then
646 get_source
647 extract_source || exit 1
648 fi
649 if [ "$LZMA_SRC" ]; then
650 cd $pkgdir/source
651 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
652 mv tmp tmp-1 && mkdir tmp
653 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
654 fi
655 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
656 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
657 fi
658 fi
659 cd $pkgdir/source/tmp
660 # Some archives are not well done and don't extract to one dir (ex lzma).
661 files=$(ls | wc -l)
662 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
663 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
664 mv * ../$PACKAGE-$VERSION/$TARBALL
665 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
666 mv * ../$PACKAGE-$VERSION
667 cd .. && rm -rf tmp
668 fi
670 # Execute receipt rules.
671 if grep -q ^compile_rules $receipt; then
672 _ "Executing: compile_rules"
673 echo "CFLAGS : $CFLAGS"
674 #echo "LDFLAGS : $LDFLAGS"
675 [ -d "$src" ] && cd $src
676 compile_rules $@ || exit 1
677 # Stay compatible with _pkg
678 [ -d "$src/_pkg" ] && mv $src/_pkg $install
679 # QA: compile_rules success so valid.
680 mkdir -p $install
681 else
682 # QA: no compile_rules so no error, valid.
683 mkdir -p $install
684 fi
685 separator; newline
687 # Execute testsuite.
688 if grep -q ^testsuite $receipt; then
689 _ "Running testsuite"; separator
690 testsuite $@ || exit 1
691 separator; newline
692 fi
693 }
695 # Cook quality assurance.
696 cookit_quality() {
697 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
698 _ "ERROR: cook failed" | tee -a $LOGS/$pkg.log
699 fi
700 # ERROR can be echoed any time in cookit()
701 lerror=$(_n "ERROR")
702 if grep -Eq "($lerror|undefined reference to)" $LOGS/$pkg.log; then
703 debug_info | tee -a $LOGS/$pkg.log
704 rm -f $command && exit 1
705 fi
706 }
708 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
709 # but it doesn't handle EXTRAVERSION.
710 packit() {
711 set_paths
713 # Handle cross compilation
714 case "$ARCH" in
715 arm|x86_64) arch="-$ARCH" ;;
716 esac
718 _ "Pack: \$PACKAGE \${VERSION}\${arch}"; separator
720 if grep -q ^genpkg_rules $receipt; then
721 _ "Executing: genpkg_rules"
722 set -e && cd $pkgdir && mkdir -p $fs
723 genpkg_rules || (newline; _ "ERROR: genpkg_rules failed"; newline) >> \
724 $LOGS/$pkg.log
725 else
726 _ "No packages rules: meta package"
727 mkdir -p $fs
728 fi
730 # First QA check to stop now if genpkg_rules failed.
731 lerror=$(_n "ERROR")
732 if fgrep -q $lerror $LOGS/$pkg.log; then
733 exit 1
734 fi
736 cd $taz
737 for file in receipt description.txt
738 do
739 [ ! -f "../$file" ] && continue
740 _n "Copying \$file..."
741 cp -f ../$file $pack && chown 0.0 $pack/$file && status
742 done
743 copy_generic_files
745 # Create files.list with redirecting find output.
746 _n "Creating the list of files..."
747 cd $fs
748 find . -type f -print > ../files.list
749 find . -type l -print >> ../files.list
750 cd .. && sed -i s/'^.'/''/ files.list
751 status
753 # Strip and stuff files.
754 strip_package
756 # Md5sum of files.
757 _n "Creating md5sum of files..."
758 while read file; do
759 [ -L "fs$file" ] && continue
760 [ -f "fs$file" ] || continue
761 case "$file" in
762 /lib/modules/*/modules.*|*.pyc) continue ;;
763 esac
764 md5sum "fs$file" | sed 's/ fs/ /'
765 done < files.list > md5sum
766 status
767 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
768 description.txt 2> /dev/null | awk \
769 '{ sz=$1 } END { print sz }')
771 # Build cpio archives.
772 _n "Compressing the fs..."
773 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
774 rm -rf fs
775 status
776 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
777 md5sum description.txt 2> /dev/null | awk \
778 '{ sz=$1 } END { print sz }')
779 _n "Updating receipt sizes..."
780 sed -i s/^PACKED_SIZE.*$// receipt
781 sed -i s/^UNPACKED_SIZE.*$// receipt
782 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
783 status
785 # Set extra version.
786 if [ "$EXTRAVERSION" ]; then
787 _n "Updating receipt EXTRAVERSION: \$EXTRAVERSION"
788 sed -i s/^EXTRAVERSION.*$// receipt
789 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
790 status
791 fi
793 # Compress.
794 _n "Creating full cpio archive..."
795 find . -print | cpio -o -H newc --quiet > \
796 ../$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg
797 status
798 _n "Restoring original package tree..."
799 unlzma -c fs.cpio.lzma | cpio -idm --quiet
800 status
801 rm fs.cpio.lzma && cd ..
803 # QA and give info.
804 tazpkg=$(ls *.tazpkg)
805 packit_quality
806 separator; _ "Package: \$tazpkg"; newline
807 }
809 # Verify package quality and consistency.
810 packit_quality() {
811 #gettext "QA: checking for broken link..."
812 #link=$(find $fs/usr -type l -follow)
813 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
814 #status
816 # Exit if any error found in log file.
817 lerror=$(_n "ERROR")
818 if fgrep -q $lerror $LOGS/$pkg.log; then
819 rm -f $command && exit 1
820 fi
822 _n "QA: checking for empty package..."
823 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
824 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
825 newline; _ "ERROR: empty package"
826 rm -f $command && exit 1
827 else
828 # Ls sort by name so the first file is the one we want.
829 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
830 status
831 if [ -f "$old" ]; then
832 old_pkg=$(basename $old)
833 _n "Removing old: \$old_pkg"
834 rm -f $old && status
835 fi
836 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
837 sed -i /^${pkg}$/d $broken
838 #gettext "Removing source tree..."
839 #rm -f $WOK/$pkg/source && status
840 fi
841 }
843 # Tic tac, tic tac...
844 tac() {
845 sed '1!G;h;$!d' $1
846 }
848 # Install package on --install or update the chroot.
849 install_package() {
850 case "$ARCH" in
851 arm|x86_64)
852 arch="-${ARCH}"
853 root=$CROSS_TREE/sysroot ;;
854 esac
855 # Install package if requested but skip install if target host doesn't
856 # match build system or it will break the build chroot.
857 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
858 if [ "$inst" ] && [ "$build" == "$ARCH" ]; then
859 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
860 cd $PKGS && tazpkg install \
861 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
862 else
863 _ "Unable to install package, build has failed."; newline
864 exit 1
865 fi
866 fi
868 # Install package if part of the chroot to keep env up-to-date.
869 if [ -d "${root}$INSTALLED/$pkg" ]; then
870 . /etc/slitaz/cook.conf
871 . $WOK/$pkg/taz/$pkg-*/receipt
872 _ "Updating \$ARCH chroot environment..."
873 _ "Updating chroot: \$pkg (\${VERSION}\${EXTRAVERSION}\${arch})" | log
874 cd $PKGS && tazpkg install \
875 $pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg \
876 --forced --root=$root
877 fi
878 }
880 # Launch the cook command into a chroot jail protected by aufs.
881 # The current filesystems are used read-only and updates are
882 # stored in a separate branch.
883 try_aufs_chroot() {
885 base=/dev/shm/aufsmnt$$
887 # Can we setup the chroot? Is it already done?
888 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
889 grep -q ^AUFS_NOT_RAMFS $receipt && base=/mnt/aufsmnt$$
890 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
891 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
892 mkdir ${base}root ${base}rw || return
894 _ "Setup aufs chroot..."
896 # Sanity check
897 for i in / /proc /sys /dev/shm /home ; do
898 case " $AUFS_MOUNTS " in
899 *\ $i\ *) ;;
900 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
901 esac
902 done
903 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
904 mount --bind $mnt ${base}root$mnt
905 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
906 _ "Aufs mountage failure"
907 umount ${base}root
908 rmdir ${base}*
909 return
910 fi
911 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
912 done
914 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
915 status=$?
917 _ "Leaving aufs chroot..."
918 tac ${base}rw/aufs-umount.sh | sh
919 rm -rf ${base}rw
920 umount ${base}root
921 rmdir $base*
922 # Dont install pkg twice... it's done after
923 #install_package
924 exit $status
925 }
927 # Create a XML feed for freshly built packages.
928 gen_rss() {
929 pubdate=$(date "+%a, %d %b %Y %X")
930 cat > $FEEDS/$pkg.xml << EOT
931 <item>
932 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
933 <link>${COOKER_URL}?pkg=$PACKAGE</link>
934 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
935 <pubDate>$pubdate</pubDate>
936 <description>$SHORT_DESC</description>
937 </item>
938 EOT
939 }
941 # Truncate stdout log file to $1 Mb.
942 loglimit()
943 {
944 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
945 tee /dev/stderr | dd bs=1k count=$((1024*${1:-$DEFAULT_LOG_LIMIT})) conv=noerror 2> /dev/null
946 else
947 tee /dev/stderr
948 fi
949 }
951 #
952 # Commands
953 #
955 case "$1" in
956 usage|help|-u|-h)
957 usage ;;
958 list-wok)
959 newline; _ "List of packages in: \$WOK"; separator
960 cd $WOK && ls -1
961 separator
962 pkg_total=$(ls | wc -l)
963 _ "Packages: \$pkg_total"; newline ;;
964 activity)
965 cat $activity ;;
966 search)
967 # Just a simple search function, we dont need more actually.
968 query="$2"
969 newline; _ "Search results for: \$query"; separator
970 cd $WOK && ls -1 | grep "$query"
971 separator; newline ;;
972 setup)
973 # Setup a build environment
974 check_root
975 _ "Cook: setup environment" | log
976 newline; _ "Setting up your environment"; separator
977 cd $SLITAZ
978 init_db_files
979 _ "Checking for packages to install..."
980 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
981 # ARCH-setup or 'cross check-env' should be used before: cook setup
982 case "$ARCH" in
983 arm|x86_64)
984 if [ ! -x "/usr/bin/cross" ]; then
985 _ "ERROR: cross is not installed"
986 exit 1
987 fi
988 _ "Using config file: /etc/slitaz/cross.conf"
989 . /etc/slitaz/cross.conf ;;
990 esac
991 for pkg in $SETUP_PKGS; do
992 if [ "$forced" ]; then
993 tazpkg -gi $pkg --forced
994 else
995 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
996 fi
997 done
999 # Handle --options
1000 case "$2" in
1001 --wok)
1002 hg clone $WOK_URL wok || exit 1 ;;
1003 --stable)
1004 hg clone $WOK_URL-stable wok || exit 1 ;;
1005 --undigest)
1006 hg clone $WOK_URL-undigest wok || exit 1 ;;
1007 --tiny)
1008 hg clone $WOK_URL-tiny wok || exit 1 ;;
1009 esac
1011 # SliTaz group and permissions
1012 if ! grep -q ^slitaz /etc/group; then
1013 _ "Adding group: slitaz"
1014 addgroup slitaz
1015 fi
1016 _ "Setting permissions for slitaz group..."
1017 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1018 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1019 separator; _ "All done, ready to cook packages :-)"; newline ;;
1020 *-setup)
1021 # Setup for cross compiling.
1022 arch=${1%-setup}
1023 check_root
1024 _ "Cook: setup \$arch cross environment" | log
1025 newline; boldify $(_n "Setting up your \$arch cross environment"); separator
1026 init_db_files
1027 sed -i \
1028 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1029 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1030 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1031 /etc/slitaz/cook.conf
1032 case "$arch" in
1033 arm)
1034 sed -i \
1035 -e s'/CFLAGS=.*/CFLAGS="-march=armv6 -O2"/' \
1036 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux-gnueabi/' \
1037 -e s'/xorg-dev/""/' \
1038 /etc/slitaz/cook.conf ;;
1039 x86_64)
1040 sed -i \
1041 -e s'/CFLAGS=.*/CFLAGS=""/' \
1042 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux/' \
1043 /etc/slitaz/cook.conf ;;
1044 esac
1045 . /etc/slitaz/cook.conf
1046 sysroot=$CROSS_TREE/sysroot
1047 tools=/cross/$arch/tools
1048 root=$sysroot
1049 CC=$tools/bin/${HOST_SYSTEM}-gcc
1050 # L10n: keep the same width of translations to get a consistent view
1051 _ "Target arch : \$ARCH"
1052 _ "Configure args : \$CONFIGURE_ARGS"
1053 _ "Arch sysroot : \$sysroot"
1054 _ "Tools prefix : \$tools/bin"
1055 # Tell the packages manager where to find packages.
1056 _ "Packages DB : \${root}\$DB"
1057 mkdir -p ${root}$INSTALLED
1058 cd ${root}$DB && rm -f *.bak
1059 for list in packages.list packages.desc packages.equiv packages.md5
1060 do
1061 rm -f $list && ln -s $SLITAZ/packages/$list $list
1062 done
1063 # We must have the cross compiled glibc-base installed or default
1064 # i486 package will be used as dep by tazpkg and then break the
1065 # cross environment
1066 if [ ! -f "${root}$INSTALLED/glibc-base/receipt" ]; then
1067 colorize 36 $(_ "WARNING: (e)glibc-base is not installed in sysroot")
1068 fi
1069 # Show GCC version or warn if not yet compiled.
1070 if [ -x $CC ]; then
1071 _ "Cross compiler : \${HOST_SYSTEM}-gcc"
1072 else
1073 colorize 36 $(_ "C compiler is missing: \${HOST_SYSTEM}-gcc")
1074 _ "Run 'cross compile' to cook a toolchain"
1075 fi
1076 separator; newline ;;
1077 test)
1078 # Test a cook environment.
1079 _ "Cook test: testing the cook environment" | log
1080 [ ! -d "$WOK" ] && exit 1
1081 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1082 cook cooktest ;;
1083 new)
1084 # Create the package folder and an empty receipt.
1085 pkg="$2"
1086 [ "$pkg" ] || usage
1087 newline
1088 if [ -d "$WOK/$pkg" ]; then
1089 _ "\$pkg package already exists."
1090 exit 1
1091 fi
1092 _n "Creating \$WOK/\$pkg"
1093 mkdir $WOK/$pkg && cd $WOK/$pkg && status
1094 _n "Preparing the package receipt..."
1095 cp $DATA/receipt .
1096 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1097 status && newline
1099 # Interactive mode, asking and seding.
1100 case "$3" in
1101 --interactive|-x)
1102 _ "Entering interactive mode..."
1103 separator
1104 _ "Package : \$pkg"
1105 _n "Version : " ; read answer
1106 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1107 _n "Category : " ; read answer
1108 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1109 # L10n: Short description
1110 _n "Short desc : " ; read answer
1111 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1112 _n "Maintainer : " ; read answer
1113 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1114 _n "License : " ; read answer
1115 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1116 _n "Web site : " ; read answer
1117 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1118 newline
1119 # Wget URL.
1120 _ "Wget URL to download source tarball."
1121 _n "Example : " ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1122 _n "Wget url : " ; read answer
1123 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$answer\""# receipt
1124 # Ask for a stuff dir.
1125 _n "Do you need a stuff directory? (y/N) : " ; read answer
1126 if [ "$answer" = "y" ]; then
1127 _n "Creating the stuff directory..."
1128 mkdir $WOK/$pkg/stuff && status
1129 fi
1130 # Ask for a description file.
1131 _n "Are you going to write a description? (y/N) : " ; read answer
1132 if [ "$answer" = "y" ]; then
1133 _n "Creating the description.txt file..."
1134 newline > $WOK/$pkg/description.txt && status
1135 fi
1136 separator; _ "Receipt is ready to use."; newline ;;
1137 esac ;;
1138 list)
1139 # Cook a list of packages (better use the Cooker since it will order
1140 # packages before executing cook).
1141 check_root
1142 [ -z "$2" ] && (newline; _ "No list in argument."; newline) && exit 1
1143 list2=$2
1144 [ ! -f "$2" ] && (newline; _ "No list found: \$list2"; newline) && exit 1
1145 _ "Cook list starting: \$list2" | log
1146 for pkg in $(cat $2)
1147 do
1148 cook $pkg || broken
1149 done ;;
1150 clean-wok)
1151 check_root
1152 newline; _n "Cleaning all packages files..."
1153 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1154 status; newline ;;
1155 clean-src)
1156 check_root
1157 newline; _n "Cleaning all packages sources..."
1158 rm -rf $WOK/*/source
1159 status; newline ;;
1160 pkgdb)
1161 # Create suitable packages list for TazPKG and only for built packages
1162 # as well as flavors files for TazLiTo. We dont need logs since we do it
1163 # manually to ensure everything is fine before syncing the mirror.
1164 case "$2" in
1165 --flavors)
1166 continue ;;
1167 *)
1168 [ "$2" ] && PKGS="$2"
1169 [ ! -d "$PKGS" ] && \
1170 newline && _ "Packages directory doesn't exist" && \
1171 newline && exit 1 ;;
1172 esac
1173 time=$(date +%s)
1174 flavors=$SLITAZ/flavors
1175 live=$SLITAZ/live
1176 echo "cook:pkgdb" > $command
1177 _ "Cook pkgdb: Creating all packages lists" | log
1178 newline; _ "Creating lists for: \$PKGS"; separator
1179 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
1180 _ "Cook pkgdb started: \$datenow"
1181 cd $PKGS
1182 rm -f packages.*
1183 _ "Creating: packages.list"
1184 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1185 _ "Creating: packages.md5"
1186 md5sum *.tazpkg > $PKGS/packages.md5
1187 md5sum packages.md5 | cut -f1 -d' ' > ID
1188 _ "Creating lists from: \$WOK"
1189 cd $WOK
1190 for pkg in *
1191 do
1192 unset_receipt
1193 . $pkg/receipt
1194 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1195 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1196 if [ -s $pkg/taz/*/receipt ]; then
1197 . $pkg/taz/*/receipt
1198 fi
1199 # packages.desc lets us search easily in DB
1200 cat >> $PKGS/packages.desc << EOT
1201 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1202 EOT
1203 # packages.txt used by tazpkg and tazpkg-web also to provide
1204 # a human readable package list with version and description.
1205 cat >> $PKGS/packages.txt << EOT
1206 $PACKAGE
1207 ${VERSION}$EXTRAVERSION
1208 $SHORT_DESC
1209 $PACKED_SIZE ($UNPACKED_SIZE installed)
1211 EOT
1212 # packages.equiv is used by tazpkg install to check depends.
1213 for i in $PROVIDE; do
1214 DEST=""
1215 echo $i | fgrep -q : && DEST="${i#*:}:"
1216 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1217 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1218 $PKGS/packages.equiv
1219 else
1220 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1221 fi
1222 done
1223 # files.list provides a list of all packages files.
1224 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1225 $PKGS/files.list
1226 fi
1227 done
1229 # Display list size.
1230 _ "Done: packages.desc"
1231 _ "Done: packages.txt"
1232 _ "Done: packages.equiv"
1234 # files.list.lzma
1235 _ "Creating: files.list.lzma"
1236 cd $PKGS && lzma e files.list files.list.lzma
1237 rm -f files.list
1239 # Display some info.
1240 separator
1241 nb=$(ls $PKGS/*.tazpkg | wc -l)
1242 time=$(($(date +%s) - $time))
1243 # L10n: 's' is for seconds (cooking time)
1244 _ "Packages: \$nb - Time: \${time}s"; newline
1246 # Create all flavors files at once. Do we really need code to monitor
1247 # flavors changes? Lets just build them with packages lists before
1248 # syncing the mirror.
1249 [ "$2" == "--flavors" ] || exit 1
1250 [ ! -d "$flavors" ] && (_ "Missing flavors: \$flavors"; newline) && exit 1
1251 [ -d "$live" ] || mkdir -p $live
1252 _ "Creating flavors files in: \$live"
1253 _ "Cook pkgdb: Creating all flavors" | log
1254 separator
1255 _ "Recharging lists to use latest packages..."
1256 tazpkg recharge >/dev/null 2>/dev/null
1258 # We need a custom tazlito config to set working dir to /home/slitaz.
1259 if [ ! -f "$live/tazlito.conf" ]; then
1260 _ "Creating configuration file: tazlito.conf"
1261 cp /etc/tazlito/tazlito.conf $live
1262 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1263 $live/tazlito.conf
1264 fi
1266 # Update Hg flavors repo and pack.
1267 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
1269 cd $live
1270 _ "Starting to generate flavors..."
1271 rm -f flavors.list *.flavor
1272 for i in $flavors/*
1273 do
1274 fl=$(basename $i)
1275 _ "Packing flavor: \$fl"
1276 tazlito pack-flavor $fl >/dev/null || exit 1
1277 tazlito show-flavor $fl --brief --noheader 2> \
1278 /dev/null >> flavors.list
1279 done
1280 cp -f $live/*.flavor $live/flavors.list $PKGS
1281 separator
1282 fl_size=$(du -sh $live | awk '{print $1}')
1283 _ "Flavors size: \$fl_size"; newline
1284 rm -f $command
1285 separator
1286 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
1287 _ "Cook pkgdb end: \$datenow" ;;
1288 *)
1289 # Just cook and generate a package.
1290 check_root
1291 time=$(date +%s)
1292 pkg="$1"
1293 [ -z "$pkg" ] && usage
1294 receipt="$WOK/$pkg/receipt"
1295 check_pkg_in_wok && newline
1297 unset inst
1298 unset_receipt
1299 . $receipt
1301 # Handle cross compilation.
1303 # CROSS_NOTE: Actually we are running an ARM cooker but running
1304 # the cooker and build each commit in wok is not possible since
1305 # we dont cook the full wok for this arch. For ARM we need a set
1306 # of packages to handle a touch screen desktop, servers but not
1307 # erlang.
1309 # The temporary solution is to build only reviewed and tested
1310 # packages with HOST_ARCH set in receipt.
1311 case "$ARCH" in
1312 arm)
1313 if [ ! "$HOST_ARCH" ]; then
1314 _ "cook: HOST_ARCH is not set in \$pkg receipt"
1315 _ "cook: This package is not included in: \$ARCH"
1316 [ "$CROSS_BUGS" ] && _ "bugs: \$CROSS_BUGS"
1317 _ "Cook skip: \$pkg is not included in: \$ARCH" | log
1318 newline && exit 1
1319 fi ;;
1320 esac
1322 # Some packages are not included in some arch or fail to cross compile.
1323 : ${HOST_ARCH=i486}
1324 if ! $(echo "$HOST_ARCH" | fgrep -q $ARCH); then
1325 _ "cook: HOST_ARCH=\$HOST_ARCH"
1326 _ "cook: \$pkg doesn't cook or is not included in: \$ARCH"
1327 [ "$CROSS_BUGS" ] && _ "bugs: \$CROSS_BUGS"
1328 _ "Cook skip: \$pkg doesn't cook or is not included in: \$ARCH" | log
1329 newline && exit 1
1330 fi
1332 # Skip blocked, 3 lines also for the Cooker.
1333 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1334 _ "Blocked package: \$pkg"; newline
1335 exit 0
1336 fi
1338 try_aufs_chroot "$@"
1340 # Log and source receipt.
1341 _ "Cook started for: <a href='cooker.cgi?pkg=\$pkg'>\$pkg</a>" | log
1342 echo "cook:$pkg" > $command
1344 # Display and log info if cook process stopped.
1345 # FIXME: gettext not worked (in single quotes) here!
1346 trap '_ "\n\nCook stopped: control-C\n\n" | \
1347 tee -a $LOGS/$pkg.log' INT
1349 # Handle --options
1350 case "$2" in
1351 --clean|-c)
1352 _n "Cleaning: \$pkg"
1353 cd $WOK/$pkg && rm -rf install taz source
1354 status && newline && exit 0 ;;
1355 --install|-i)
1356 inst='yes' ;;
1357 --getsrc|-gs)
1358 _ "Getting source for: \$pkg"; separator
1359 get_source
1360 _ "Tarball: \$SRC/\$TARBALL"; newline
1361 exit 0 ;;
1362 --block|-b)
1363 _n "Blocking: \$pkg"
1364 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1365 status && newline && exit 0 ;;
1366 --unblock|-ub)
1367 _n "Unblocking: \$pkg"
1368 sed -i "/^${pkg}$/"d $blocked
1369 status && newline && exit 0 ;;
1370 --pack)
1371 if [ -d $WOK/$pkg/taz ]; then
1372 rm -rf $WOK/$pkg/taz
1373 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1374 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1375 clean_log
1376 else
1377 _ "Need to build \$pkg." && exit 0
1378 fi
1379 exit 0 ;;
1380 esac
1382 # Check if wanted is built now so we have separate log files.
1383 for wanted in $WANTED ; do
1384 if grep -q "^$wanted$" $blocked; then
1385 _ "WANTED package is blocked: \$wanted" | tee $LOGS/$pkg.log
1386 newline && rm -f $command && exit 1
1387 fi
1388 if grep -q "^$wanted$" $broken; then
1389 _ "WANTED package is broken: \$wanted" | tee $LOGS/$pkg.log
1390 newline && rm -f $command && exit 1
1391 fi
1392 if [ ! -d "$WOK/$wanted/install" ]; then
1393 cook "$wanted" || exit 1
1394 fi
1395 done
1397 # Cook and pack or exit on error and log everything.
1398 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1399 remove_deps | tee -a $LOGS/$pkg.log
1400 cookit_quality
1401 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1402 clean_log
1404 # Exit if any error in packing.
1405 lerror=$(_n "ERROR")
1406 if grep -Eq "(^$lerror|No such file or directory)" $LOGS/$pkg.log; then
1407 debug_info | tee -a $LOGS/$pkg.log
1408 rm -f $command && exit 1
1409 fi
1411 # Create an XML feed
1412 gen_rss
1414 # Time and summary
1415 time=$(($(date +%s) - $time))
1416 summary | tee -a $LOGS/$pkg.log
1417 newline
1419 # We may want to install/update.
1420 install_package
1422 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1423 # You want automation: use the Cooker Build Bot.
1424 rm -f $command ;;
1425 esac
1427 exit 0