cookutils view cook @ rev 642

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