cookutils view cook @ rev 464

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