cookutils view cook @ rev 618

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