cookutils view cook @ rev 465

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