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