cookutils view cook @ rev 610

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