cookutils view cook @ rev 500

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