cookutils view cook @ rev 462

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