cookutils view cook @ rev 459

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