cookutils view cook @ rev 397

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