cookutils view cook @ rev 239

improve and fix flavors creation
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 27 15:15:19 2011 +0200 (2011-05-27)
parents 9c07802ebc58
children 2389eed5eeb6
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 #
10 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
11 [ -f "cook.conf" ] && . ./cook.conf
13 # Share DB and status with the Cooker.
14 activity="$CACHE/activity"
15 command="$CACHE/command"
16 broken="$CACHE/broken"
17 blocked="$CACHE/blocked"
19 # Old style compatibility
20 SOURCES_REPOSITORY=$SRC
22 #
23 # Functions
24 #
26 usage() {
27 cat << EOT
29 $(echo -e "\033[1m$(gettext "Usage:")\033[0m") cook [package|command] [list|--option]
31 $(echo -e "\033[1m$(gettext "Commands:")\033[0m")
32 usage|help $(gettext "Display this short usage.")
33 setup $(gettext "Setup your build environment.")
34 test $(gettext "Test environment and cook a package.")
35 list-wok $(gettext "List packages in the wok.")
36 search $(gettext "Simple packages search function.")
37 new $(gettext "Create a new package with a receipt".)
38 list $(gettext "Cook a list of packages.")
39 clean-wok $(gettext "Clean-up all packages files.")
40 clean-src $(gettext "Clean-up all packages sources.")
41 pkgdb $(gettext "Create packages DB lists and flavors.")
43 $(echo -e "\033[1m$(gettext "Options:")\033[0m")
44 --clean|-c Cook : $(gettext "clean the package in the wok.")
45 --install|-i Cook : $(gettext "cook and install the package.")
46 --getsrc|-gs Cook : $(gettext "get the package source tarball.")
47 --block|-b Cook : $(gettext "Block a package so cook will skip it.")
48 --unblock|-ub Cook : $(gettext "Unblock a blocked package.")
49 --interactive|-x New : $(gettext "create a receipt interactively.")
50 --wok|-w Setup: $(gettext "clone the cooking wok from Hg repo.")
51 --stable Setup: $(gettext "clone the stable wok from Hg repo.")
52 --undigest Setup: $(gettext "clone the undigest wok from Hg repo.")
53 --flavors Pkgdb: $(gettext "create up-to-date flavors files.")
55 EOT
56 exit 0
57 }
59 # Be sure we're root.
60 check_root() {
61 [ $(id -u) != 0 ] && gettext -e "\nYou must be root to cook.\n\n" && exit 0
62 }
64 separator() {
65 echo "================================================================================"
66 }
68 status() {
69 echo -en "\\033[70G[ "
70 if [ $? = 0 ]; then
71 echo -en "\\033[1;32mOK"
72 else
73 echo -en "\\033[1;31mFailed"
74 fi
75 echo -e "\\033[0;39m ]"
76 }
78 # Log activities, we want first letter capitalized.
79 log() {
80 grep ^[A-Z] | \
81 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
82 }
84 # We don't want these escapes in web interface.
85 clean_log() {
86 sed -i -e s'|\[70G\[ \[1;32m| |' \
87 -e s'|\[0;39m \]||' $LOGS/$pkg.log
88 }
90 # Log broken packages.
91 broken() {
92 if ! grep -q "^$pkg$" $broken; then
93 echo "$pkg" >> $broken
94 fi
95 }
97 # Be sure package exists in wok.
98 check_pkg_in_wok() {
99 if [ ! -d "$WOK/$pkg" ]; then
100 gettext -e "\nUnable to find package in the wok:"
101 echo -e " $pkg\n" && exit 1
102 fi
103 }
105 if_empty_value() {
106 if [ -z "$value" ]; then
107 gettext "QA: empty variable:"; echo -e " ${var}=\"\"\n"
108 exit 1
109 fi
110 }
112 # Initialize files used in $CACHE
113 init_db_files() {
114 gettext "Creating directories structure in:"; echo " $SLITAZ"
115 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS
116 gettext "Creating DB files in:"; echo " $CACHE"
117 for f in $activity $command $broken $blocked
118 do
119 touch $f
120 done
121 }
123 # QA: check a receipt consistency before building.
124 receipt_quality() {
125 gettext -e "QA: checking package receipt...\n"
126 unset online
127 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
128 online="online"
129 fi
130 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
131 do
132 unset value
133 value=$(grep ^$var= $receipt | cut -d \" -f 2)
134 case "$var" in
135 PACKAGE|VERSION|SHORT_DESC)
136 if_empty_value ;;
137 CATEGORY)
138 [ -z "$value" ] && value="empty"
139 valid="base-system x-window utilities network graphics \
140 multimedia office development system-tools security games \
141 misc meta non-free"
142 if ! echo "$valid" | grep -q -w "$value"; then
143 gettext "QA: unknown category:"; echo -e " $value\n"
144 exit 1
145 fi ;;
146 WEB_SITE)
147 # We don't check WGET_URL since if dl is needed it will fail.
148 # Break also if we're not online. Here error is not fatal.
149 if_empty_value
150 [ -z "$online" ] || break
151 if ! busybox wget -T 12 -s $value 2>/dev/null; then
152 gettext "QA: Unable to reach:"; echo -e " $value"
153 fi ;;
154 esac
155 done
156 }
158 # Executed before sourcing a receipt.
159 unset_receipt() {
160 unset DEPENDS BUILD_DEPENDS WANTED EXTRAVERSION WGET_URL PROVIDE TARBALL
161 }
163 # Paths used in receipt and by cook itself.
164 set_paths() {
165 pkgdir=$WOK/$PACKAGE
166 src=$pkgdir/source/$PACKAGE-$VERSION
167 taz=$pkgdir/taz
168 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
169 fs=$pack/fs
170 stuff=$pkgdir/stuff
171 install=$pkgdir/install
172 if [ "$WANTED" ]; then
173 src=$WOK/$WANTED/source/$WANTED-$VERSION
174 install=$WOK/$WANTED/install
175 wanted_stuff=$WOK/$WANTED/stuff
176 fi
177 # Kernel version is set from linux-api-headers since it part of toolchain.
178 if [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
179 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d '"' -f 2)
180 fi
181 # Old way compatibility.
182 _pkg=$install
183 }
185 # Create source tarball when URL is a SCM.
186 create_tarball() {
187 gettext "Creating tarball: "; echo "$tarball"
188 if [ "$LZMA_SRC" ]; then
189 tar -c $pkgsrc | lzma e $SRC/$tarball -si || exit 1
190 else
191 tar cjf $tarball $pkgsrc || exit 1
192 mv $tarball $SRC && rm -rf $pkgsrc
193 fi
194 }
196 # Get package source. For SCM we are in cache so clone here and create a
197 # tarball here.
198 get_source() {
199 pwd=$(pwd)
200 pkgsrc=${SOURCE:-$PACKAGE}-$VERSION
201 tarball=$pkgsrc.tar.bz2
202 [ "$LZMA_SRC" ] && tarball=$pkgsrc.tar.lzma
203 case "$WGET_URL" in
204 http://*|ftp://*)
205 # Busybox Wget is better!
206 busybox wget -T 12 -c -P $SRC $WGET_URL || \
207 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
208 https://*)
209 wget -c --no-check-certificate -P $SRC $WGET_URL || \
210 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
211 hg*|mercurial*)
212 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
213 url=${WGET_URL#hg|}
214 else
215 url=${WGET_URL#mercurial|}
216 fi
217 gettext -e "Getting source from Hg...\n"
218 echo "URL: $url"
219 gettext "Cloning to: "; echo "$pwd/$pkgsrc"
220 hg clone $url $pkgsrc || (echo "ERROR: hg clone $url" && exit 1)
221 create_tarball ;;
222 git*)
223 url=${WGET_URL#git|}
224 gettext -e "Getting source from Git...\n"
225 echo "URL: $url"
226 git clone $url $pkgsrc || (echo "ERROR: git clone $url" && exit 1)
227 if [ "$BRANCH" ]; then
228 echo "Git branch: $BRANCH"
229 cd $pkgsrc && git checkout $BRANCH && cd ..
230 fi
231 create_tarball ;;
232 cvs*)
233 url=${WGET_URL#cvs|}
234 mod=$PACKAGE
235 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
236 gettext -e "Getting source from CVS...\n"
237 echo "URL: $url"
238 [ "$CVS_MODULE" ] && echo "CVS module: $mod"
239 gettext "Cloning to: "; echo "$pwd/$mod"
240 cvs -d:$url co $mod && mv $mod $pkgsrc
241 create_tarball ;;
242 svn*|subversion*)
243 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
244 url=${WGET_URL#svn|}
245 else
246 url=${WGET_URL#subversion|}
247 fi
248 gettext -e "Getting source from SVN...\n"
249 echo "URL: $url"
250 if [ "$BRANCH" ]; then
251 echo t | svn co $url -r $BRANCH $pkgsrc
252 else
253 echo t | svn co $url $pkgsrc
254 fi
255 create_tarball ;;
256 *)
257 gettext -e "\nERROR: Unable to handle:"; echo -e " $WGET_URL \n" | \
258 tee -a $LOGS/$PACKAGE.log
259 exit 1 ;;
260 esac
261 }
263 # Extract source package.
264 extract_source() {
265 if [ ! -s "$SRC/$TARBALL" ]; then
266 local url
267 url="http://mirror.slitaz.org/sources/packages"
268 url=$url/${TARBALL:0:1}/$TARBALL
269 gettext "Getting source from mirror:"; echo " $url"
270 busybox wget -c -P $SRC $url || echo -e "ERROR: wget $url"
271 fi
272 gettext "Extracting:"; echo " $TARBALL"
273 case "$TARBALL" in
274 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
275 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
276 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
277 *.tar) tar xf $SRC/$TARBALL ;;
278 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
279 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
280 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
281 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
282 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
283 *) cp $SRC/$TARBALL $(pwd) ;;
284 esac
285 }
287 # Display cooked package summary.
288 summary() {
289 cd $WOK/$pkg
290 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
291 fs=$(du -sh taz/* | awk '{print $1}')
292 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
293 files=$(cat taz/$pkg-*/files.list | wc -l)
294 cookdate=$(date "+%Y-%m-%d %H:%M")
295 sec=$time
296 div=$(($time / 60))
297 [ "$div" != 0 ] && min="~ ${div}m"
298 gettext "Summary for:"; echo " $PACKAGE $VERSION"
299 separator
300 [ "$prod" ] && echo "Produced : $prod"
301 cat << EOT
302 Packed : $fs
303 Compressed : $size
304 Files : $files
305 Cook time : ${sec}s $min
306 Cook date : $cookdate
307 $(separator)
308 EOT
309 }
311 # Display debugging error info.
312 debug_info() {
313 echo -e "\nDebug information"
314 separator
315 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
316 for error in \
317 ERROR "No package" "cp: can't" "can't open" "can't cd" \
318 "error:" "fatal error:"
319 do
320 fgrep "$error" $LOGS/$pkg.log
321 done
322 separator && echo ""
323 }
325 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
326 # so some packages need to copy these files with the receipt and genpkg_rules.
327 copy_generic_files()
328 {
329 # $LOCALE is set in cook.conf
330 if [ "$LOCALE" ]; then
331 if [ -d "$_pkg/usr/share/locale" ]; then
332 mkdir -p $fs/usr/share/locale
333 for i in $LOCALE
334 do
335 if [ -d "$_pkg/usr/share/locale/$i" ]; then
336 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
337 fi
338 done
339 fi
340 fi
342 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
343 if [ "$GENERIC_PIXMAPS" != "no" ]; then
344 if [ -d "$_pkg/usr/share/pixmaps" ]; then
345 mkdir -p $fs/usr/share/pixmaps
346 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
347 $fs/usr/share/pixmaps 2>/dev/null
348 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
349 $fs/usr/share/pixmaps 2>/dev/null
350 fi
352 # Custom or homemade PNG pixmap can be in stuff.
353 if [ -f "$stuff/$PACKAGE.png" ]; then
354 mkdir -p $fs/usr/share/pixmaps
355 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
356 fi
357 fi
359 # Desktop entry (.desktop).
360 if [ -d "$_pkg/usr/share/applications" ]; then
361 cp -a $_pkg/usr/share/applications $fs/usr/share
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.
377 strip_package()
378 {
379 gettext "Executing strip on all files..."
380 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
381 do
382 if [ -d "$dir" ]; then
383 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
384 fi
385 done
386 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
387 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
388 status
390 # Remove Python .pyc and .pyo from packages.
391 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
392 gettext "Removing Python compiled files..."
393 find $fs -type f -name "*.pyc" -delete 2>/dev/null
394 find $fs -type f -name "*.pyo" -delete 2>/dev/null
395 status
396 fi
398 # Remove Perl perllocal.pod and .packlist from packages.
399 if echo "$DEPENDS" | fgrep -q "perl"; then
400 gettext "Removing Perl compiled files..."
401 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
402 find $fs -type f -name ".packlist" -delete 2>/dev/null
403 status
404 fi
405 }
407 # Remove installed deps.
408 remove_deps() {
409 # Now remove installed build deps.
410 diff="$CACHE/installed.cook.diff"
411 if [ -s "$CACHE/installed.cook.diff" ]; then
412 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
413 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
414 gettext "Build dependencies to remove:"; echo " $nb"
415 gettext "Removing:"
416 for dep in $deps
417 do
418 echo -n " $dep"
419 echo 'y' | tazpkg remove $dep >/dev/null
420 done
421 echo -e "\n"
422 # Keep the last diff for debug and info.
423 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
424 fi
425 }
427 # The main cook function.
428 cookit() {
429 echo "Cook: $PACKAGE $VERSION"
430 separator
431 set_paths
432 [ "$QA" ] && receipt_quality
433 cd $pkgdir
434 rm -rf install taz source
436 # Disable -pipe if less than 512Mb free RAM.
437 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
438 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
439 gettext -e "Disabling -pipe compile flag: $free RAM\n"
440 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
441 CXXFLAGS="${CXXFLAGS/-pipe}" && \
442 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
443 fi
444 unset free
446 # Export flags and path to be used by make and receipt.
447 DESTDIR=$pkgdir/install
448 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
450 # Check for build deps and handle implicit depends of *-dev packages
451 # (ex: libusb-dev :: libusb).
452 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
453 touch $CACHE/installed.local $CACHE/installed.web
454 [ "$BUILD_DEPENDS" ] && gettext -e "Checking build dependencies...\n"
455 for dep in $BUILD_DEPENDS
456 do
457 implicit=${dep%-dev}
458 for i in $dep $implicit
459 do
460 if [ ! -f "$INSTALLED/$i/receipt" ]; then
461 # Try local package first. In some cases implicit doesn't exist, ex:
462 # libboost-dev exists but not libboost, so check if we got vers.
463 unset vers
464 vers=$(grep ^VERSION= $WOK/$i/receipt 2>/dev/null | cut -d '"' -f 2)
465 if [ -f "$PKGS/$i-$vers.tazpkg" ]; then
466 echo $i-$vers.tazpkg >> $CACHE/installed.local
467 else
468 # Priority to package version in wok (maybe more up-to-date)
469 # than the mirrored one.
470 if [ "$vers" ]; then
471 if fgrep -q $i-$vers $DB/packages.list; then
472 echo $i >> $CACHE/installed.web
473 else
474 # So package exists in wok but not available.
475 gettext "Missing dep (wok/pkg):"; echo " $i $vers"
476 echo $i >> $CACHE/missing.dep
477 fi
478 else
479 # Package is not in wok but may be in repo.
480 if fgrep -q $i-$vers $DB/packages.list; then
481 echo $i >> $CACHE/installed.web
482 else
483 echo "ERROR: unknown dep $i" && exit 1
484 fi
485 fi
486 fi
487 fi
488 done
489 done
491 # Get the list of installed packages
492 cd $INSTALLED && ls -1 > $CACHE/installed.list
494 # Have we a missing build dep to cook ?
495 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
496 gettext -e "Auto cook config is set : AUTO_COOK\n"
497 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
498 for i in $(uniq $CACHE/missing.dep)
499 do
500 (gettext "Building dep (wok/pkg) :"; echo " $i $vers") | \
501 tee -a $LOGS/$PACKAGE.log.$$
502 cook $i || (echo -e "ERROR: can't cook dep '$i'\n" && \
503 fgrep "remove: " $LOGS/$i.log && \
504 fgrep "Removing: " $LOGS/$i.log && echo "") | \
505 tee -a $LOGS/$PACKAGE.log.$$ && break
506 done
507 rm -f $CACHE/missing.dep
508 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
509 fi
511 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
512 # is enabled and cook fails we have ERROR in log, if no auto cook we have
513 # missing dep in cached file.
514 if fgrep -q "ERROR:" $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
515 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
516 echo "ERROR: missing dep $nb" && exit 1
517 fi
519 # Install local packages.
520 cd $PKGS
521 for i in $(uniq $CACHE/installed.local)
522 do
523 gettext "Installing dep (pkg/local):"; echo " $i"
524 tazpkg install $i >/dev/null
525 done
527 # Install web or cached packages (if mirror is set to $PKGS we only
528 # use local packages).
529 for i in $(uniq $CACHE/installed.web)
530 do
531 gettext "Installing dep (web/cache):"; echo " $i"
532 tazpkg get-install $i >/dev/null
533 done
535 # If a cook failed deps are removed.
536 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
537 [ ! -s "installed.cook.diff" ] && \
538 busybox diff installed.list installed.cook > installed.cook.diff
539 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
541 # Get source tarball and make sure we have source dir named:
542 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
543 # tarball if it exists.
544 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
545 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
546 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
547 LZMA_SRC=""
548 else
549 get_source || exit 1
550 fi
551 fi
552 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
553 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
554 extract_source || exit 1
555 if [ "$LZMA_SRC" ]; then
556 cd $pkgdir/source
557 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
558 mv tmp tmp-1 && mkdir tmp
559 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
560 fi
561 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
562 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
563 fi
564 fi
565 cd $pkgdir/source/tmp
566 # Some archives are not well done and don't extract to one dir (ex lzma).
567 files=$(ls | wc -l)
568 [ "$files" == 1 ] && mv * ../$PACKAGE-$VERSION
569 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
570 mv * ../$PACKAGE-$VERSION
571 cd .. && rm -rf tmp
572 fi
574 # Execute receipt rules.
575 if grep -q ^compile_rules $receipt; then
576 gettext -e "Executing: compile_rules\n"
577 [ -d "$src" ] && cd $src
578 compile_rules $@ || exit 1
579 # Stay compatible with _pkg
580 [ -d "$src/_pkg" ] && mv $src/_pkg $install
581 # QA: compile_rules success so valid.
582 mkdir -p $install
583 else
584 # QA: No compile_rules so no error, valid.
585 mkdir -p $install
586 fi
587 separator && echo ""
588 }
590 # Cook quality assurance.
591 cookit_quality() {
592 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
593 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
594 fi
595 # ERROR can be echoed any time in cookit()
596 if fgrep -q ERROR: $LOGS/$pkg.log; then
597 debug_info | tee -a $LOGS/$pkg.log
598 rm -f $command && exit 1
599 fi
600 }
602 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
603 # but it doesn't handle EXTRAVERSION.
604 packit() {
605 set_paths
606 echo "Pack: $PACKAGE $VERSION"
607 separator
608 if grep -q ^genpkg_rules $receipt; then
609 gettext -e "Executing: genpkg_rules\n"
610 cd $pkgdir && mkdir -p $fs
611 genpkg_rules || echo -e "\nERROR: genpkg_rules failed\n" >> \
612 $LOGS/$pkg.log
613 fi
615 # First QA check to stop now if genpkg_rules failed.
616 if fgrep -q ERROR: $LOGS/$pkg.log; then
617 exit 1
618 fi
620 cd $taz
621 for file in receipt description.txt
622 do
623 [ ! -f "../$file" ] && continue
624 gettext "Copying"; echo -n " $file..."
625 cp -f ../$file $pack && chown 0.0 $pack/$file && status
626 done
627 copy_generic_files
629 # Create files.list with redirecting find output.
630 gettext "Creating the list of files..." && cd $fs
631 find . -type f -print > ../files.list
632 find . -type l -print >> ../files.list
633 cd .. && sed -i s/'^.'/''/ files.list
634 status
636 # Strip and stuff files.
637 strip_package
639 # Md5sum of files.
640 gettext "Creating md5sum of files..."
641 while read file; do
642 [ -L "fs$file" ] && continue
643 [ -f "fs$file" ] || continue
644 case "$file" in
645 /lib/modules/*/modules.*|*.pyc) continue ;;
646 esac
647 md5sum "fs$file" | sed 's/ fs/ /'
648 done < files.list > md5sum
649 status
650 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
651 description.txt 2> /dev/null | awk \
652 '{ sz=$1 } END { print sz }')
654 # Build cpio archives.
655 gettext "Compressing the fs... "
656 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
657 rm -rf fs
658 status
659 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
660 md5sum description.txt 2> /dev/null | awk \
661 '{ sz=$1 } END { print sz }')
662 gettext "Updating receipt sizes..."
663 sed -i s/^PACKED_SIZE.*$// receipt
664 sed -i s/^UNPACKED_SIZE.*$// receipt
665 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
666 status
668 # Set extra version.
669 if [ "$EXTRAVERSION" ]; then
670 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
671 sed -i s/^EXTRAVERSION.*$// receipt
672 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
673 status
674 fi
676 # Compress.
677 gettext "Creating full cpio archive... "
678 find . -print | cpio -o -H newc --quiet > \
679 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
680 status
681 gettext "Restoring original package tree... "
682 unlzma -c fs.cpio.lzma | cpio -idm --quiet
683 status
684 rm fs.cpio.lzma && cd ..
686 # QA and give info.
687 tazpkg=$(ls *.tazpkg)
688 packit_quality
689 separator && gettext "Package:"; echo -e " $tazpkg\n"
690 }
692 # Verify package quality and consistency.
693 packit_quality() {
694 #gettext "QA: Checking for broken link..."
695 #link=$(find $fs/usr -type l -follow)
696 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
697 #status
699 # Exit if any error found in log file.
700 if fgrep -q ERROR: $LOGS/$pkg.log; then
701 rm -f $command && exit 1
702 fi
704 gettext "QA: Checking for empty package..."
705 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
706 if [ "$files" -lt 0 ] && [ "$CATEGORY" != "meta" ]; then
707 echo -e "\nERROR: empty package"
708 rm -f $command && exit 1
709 else
710 # Ls sort by name so the first file is the one we want.
711 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
712 status
713 if [ -f "$old" ]; then
714 echo -n "Removing old: $(basename $old)"
715 rm -f $old && status
716 fi
717 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
718 sed -i /^${pkg}$/d $broken
719 fi
720 }
722 #
723 # Commands
724 #
726 case "$1" in
727 usage|help|-u|-h)
728 usage ;;
729 list-wok)
730 gettext -e "\nList of packages in:"; echo " $WOK"
731 separator
732 cd $WOK && ls -1
733 separator
734 echo -n "Packages: " && ls | wc -l
735 echo "" ;;
736 search)
737 # Just a simple search function, we dont need more actually.
738 query="$2"
739 gettext -e "\nSearch results for:"; echo " $query"
740 separator
741 cd $WOK && ls -1 | grep "$query"
742 separator && echo "" ;;
743 setup)
744 # Setup a build environment
745 check_root
746 echo "Cook: setting up the environment" | log
747 gettext -e "\nSetting up your environment\n"
748 separator && cd $SLITAZ
749 init_db_files
750 gettext -e "Checking for packages to install...\n"
751 for pkg in $SETUP_PKGS
752 do
753 [ ! -f "$INSTALLED/$pkg/receipt" ] && tazpkg get-install $pkg
754 done
756 # Handle --options
757 case "$2" in
758 --wok|-w)
759 hg clone $WOK_URL wok || exit 1 ;;
760 --stable)
761 hg clone $WOK_URL-stable wok || exit 1 ;;
762 --undigest)
763 hg clone $WOK_URL-undigest wok || exit 1 ;;
764 esac
766 # SliTaz group and permissions
767 if ! grep -q ^slitaz /etc/group; then
768 gettext -e "Adding group: slitaz\n"
769 addgroup slitaz
770 fi
771 gettext -e "Setting permissions for slitaz group...\n"
772 chown -R root.slitaz $SLITAZ
773 chmod -R g+w $SLITAZ
774 separator
775 gettext -e "All done, ready to cook packages :-)\n\n" ;;
776 test)
777 # Test a cook environment.
778 echo "Cook test: testing the cook environment" | log
779 [ ! -d "$WOK" ] && exit 1
780 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
781 cook cooktest ;;
782 new)
783 # Create the package folder and an empty receipt.
784 pkg="$2"
785 [ "$pkg" ] || usage
786 echo ""
787 if [ -d "$WOK/$pkg" ]; then
788 echo -n "$pkg " && gettext "package already exists."
789 echo -e "\n" && exit 1
790 fi
791 gettext "Creating"; echo -n " $WOK/$pkg"
792 mkdir $WOK/$pkg && cd $WOK/$pkg && status
793 gettext "Preparing the package receipt..."
794 cp $DATA/receipt .
795 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
796 status && echo ""
798 # Interactive mode, asking and seding.
799 case "$3" in
800 --interactive|-x)
801 gettext -e "Entering interactive mode...\n"
802 separator
803 echo "Package : $pkg"
804 # Version.
805 echo -n "Version : " ; read anser
806 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
807 # Category.
808 echo -n "Category : " ; read anser
809 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
810 # Short description.
811 echo -n "Short desc : " ; read anser
812 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
813 # Maintainer.
814 echo -n "Maintainer : " ; read anser
815 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
816 # Web site.
817 echo -n "Web site : " ; read anser
818 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
819 echo ""
820 # Wget URL.
821 echo "Wget URL to download source tarball."
822 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
823 echo -n "Wget url : " ; read anser
824 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
825 # Ask for a stuff dir.
826 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
827 if [ "$anser" = "y" ]; then
828 echo -n "Creating the stuff directory..."
829 mkdir $WOK/$pkg/stuff && status
830 fi
831 # Ask for a description file.
832 echo -n "Are you going to write a description ? (y/N) : " ; read anser
833 if [ "$anser" = "y" ]; then
834 echo -n "Creating the description.txt file..."
835 echo "" > $WOK/$pkg/description.txt && status
836 fi
837 separator
838 gettext -e "Receipt is ready to use.\n"
839 echo "" ;;
840 esac ;;
841 list)
842 # Cook a list of packages (better use the Cooker since it will order
843 # packages before executing cook).
844 check_root
845 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
846 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
847 echo -e " $2\n" && exit 1
848 echo "Cook list starting: $2" | log
849 for pkg in $(cat $2)
850 do
851 cook $pkg || broken
852 done ;;
853 clean-wok)
854 check_root
855 gettext -e "\nCleaning all packages files..."
856 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
857 status && echo "" ;;
858 clean-src)
859 check_root
860 gettext -e "\nCleaning all packages sources..."
861 rm -rf $WOK/*/source
862 status && echo "" ;;
863 pkgdb)
864 # Create suitable packages list for TazPKG and only for built packages
865 # as well as flavors files for TazLiTo. We dont need logs since we do it
866 # manualy to ensure everything is fine before syncing the mirror.
867 case "$2" in
868 --flavors)
869 continue ;;
870 *)
871 PKGS="$2"
872 [ ! -d "$PKGS" ] && \
873 gettext -e "\nPackages directory doesn't exist\n\n" &&
874 exit 1 ;;
875 esac
876 time=$(date +%s)
877 flavors=$SLITAZ/flavors
878 live=$SLITAZ/live
879 echo "cook:pkgdb" > $command
880 echo "Cook pkgdb: Creating all packages lists" | log
881 echo ""
882 gettext "Creating lists for: "; echo "$PKGS"
883 separator
884 gettext "Cook pkgdb started: "; date "+%Y-%m-%d %H:%M"
885 cd $PKGS
886 rm -f packages.*
887 gettext -e "Creating: packages.list\n"
888 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
889 gettext -e "Creating: packages.md5\n"
890 md5sum *.tazpkg > $PKGS/packages.md5
891 gettext -e "Creating lists from: "; echo "$WOK"
892 cd $WOK
893 for pkg in *
894 do
895 unset_receipt
896 . $pkg/receipt
897 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
898 # packages.desc lets us search easily in DB
899 cat >> $PKGS/packages.desc << EOT
900 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
901 EOT
902 # packages.txt used by tazpkg and tazpkg-web also to provide
903 # a human readable package list with version and description.
904 cat >> $PKGS/packages.txt << EOT
905 $PACKAGE
906 ${VERSION}$EXTRAVERSION
907 $SHORT_DESC
908 $PACKED_SIZE ($UNPACKED_SIZE installed)
910 EOT
911 # packages.equiv is used by tazpkg install to check depends.
912 for i in $PROVIDE; do
913 DEST=""
914 echo $i | fgrep -q : && DEST="${i#*:}:"
915 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
916 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
917 $PKGS/packages.equiv
918 else
919 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
920 fi
921 done
922 # files.list provides a list of all packages files.
923 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
924 $PKGS/files.list
925 fi
926 done
928 # Display list size.
929 gettext -e "Done: packages.desc\n"
930 gettext -e "Done: packages.txt\n"
931 gettext -e "Done: packages.equiv\n"
933 # files.list.lzma
934 gettext -e "Creating: files.list.lzma\n"
935 cd $PKGS && lzma e files.list files.list.lzma
936 rm -f files.list
938 # Display some info.
939 separator
940 nb=$(ls $PKGS/*.tazpkg | wc -l)
941 time=$(($(date +%s) - $time))
942 echo -e "Packages: $nb - Time: ${time}s\n"
944 # Create all flavors files at once. Do we realy need code to monitor
945 # flavors changes ? Let just build them with packages lists before
946 # syncing the mirror.
947 [ "$2" == "--flavors" ] || exit 1
948 [ ! -d "$flavors" ] && echo -e "Missing flavors: $flavors\n" && exit 1
949 [ -d "$live" ] || mkdir -p $live
950 gettext "Creating flavors files in:"; echo " $live"
951 echo "Cook pkgdb: Creating all flavors" | log
952 separator
953 gettext -e "Recharging lists to use latest packages...\n"
954 tazpkg recharge 2>1 >/dev/null
956 # We need a custom tazlito config to set working dir to /home/slitaz.
957 if [ ! -f "$live/tazlito.conf" ]; then
958 echo "Creating configuration file: tazlito.conf"
959 cp /etc/tazlito/tazlito.conf $live
960 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
961 $live/tazlito.conf
962 fi
964 # Update Hg flavors repo and pack.
965 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
967 cd $live
968 echo "Starting to generate flavors..."
969 rm -f flavors.list *.flavor
970 for i in $flavors/*
971 do
972 fl=$(basename $i)
973 echo "Packing flavor: $(basename $i)"
974 tazlito pack-flavor $fl >/dev/null || exit 1
975 tazlito show-flavor $fl --brief --noheader 2> \
976 /dev/null >> flavors.list
977 done
978 cp -f $live/*.flavor $live/flavors.list $PKGS
979 separator && gettext "Flavors size: "; du -sh $live | awk '{print $1}'
980 echo "" && rm -f $command ;;
981 *)
982 # Just cook and generate a package.
983 check_root
984 time=$(date +%s)
985 pkg="$1"
986 [ -z "$pkg" ] && usage
987 receipt="$WOK/$pkg/receipt"
988 check_pkg_in_wok && echo ""
990 # Display and log info if cook process stopped.
991 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
992 tee -a $LOGS/$pkg.log' INT
994 # Skip blocked, 3 lines also for the Cooker.
995 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
996 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
997 fi
999 # Log and source receipt.
1000 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1001 echo "cook:$pkg" > $command
1002 unset inst
1003 unset_receipt
1004 . $receipt
1006 # Handle --options
1007 case "$2" in
1008 --clean|-c)
1009 gettext -e "Cleaning:"; echo -n " $pkg"
1010 cd $WOK/$pkg && rm -rf install taz source
1011 status && echo "" && exit 0 ;;
1012 --install|-i)
1013 inst='yes' ;;
1014 --getsrc|-gs)
1015 gettext "Getting source for:"; echo " $pkg"
1016 separator && get_source
1017 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
1018 --block|-b)
1019 gettext "Blocking:"; echo -n " $pkg"
1020 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1021 status && echo "" && exit 0 ;;
1022 --unblock|-ub)
1023 gettext "Unblocking:"; echo -n " $pkg"
1024 sed -i "/^${pkg}$/"d $blocked
1025 status && echo "" && exit 0 ;;
1027 esac
1029 # Check if wanted is built now so we have separate log files.
1030 if [ "$WANTED" ]; then
1031 if grep -q "^$WANTED$" $blocked; then
1032 echo "WANTED package is blocked: $WANTED" | tee $LOGS/$pkg.log
1033 echo "" && rm -f $command && exit 1
1034 fi
1035 if grep -q "^$WANTED$" $broken; then
1036 echo "WANTED package is broken: $WANTED" | tee $LOGS/$pkg.log
1037 echo "" && rm -f $command && exit 1
1038 fi
1039 if [ ! -d "$WOK/$WANTED/install" ]; then
1040 cook "$WANTED" || exit 1
1041 fi
1042 fi
1044 # Cook and pack or exit on error and log everything.
1045 cookit $@ 2>&1 | tee $LOGS/$pkg.log
1046 remove_deps | tee -a $LOGS/$pkg.log
1047 cookit_quality
1048 packit 2>&1 | tee -a $LOGS/$pkg.log
1049 clean_log
1051 # Exit if any error in packing.
1052 if grep -q ^ERROR $LOGS/$pkg.log; then
1053 debug_info | tee -a $LOGS/$pkg.log
1054 rm -f $command && exit 1
1055 fi
1057 # Time and summary
1058 time=$(($(date +%s) - $time))
1059 summary | tee -a $LOGS/$pkg.log
1060 echo ""
1062 # Install package if requested
1063 if [ "$inst" ]; then
1064 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1065 cd $PKGS && tazpkg install \
1066 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1067 else
1068 gettext -e "Unable to install package, build has failed.\n\n"
1069 exit 1
1070 fi
1071 fi
1072 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1073 # You want automation: use the Cooker Build Bot.
1074 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
1075 rm -f $command ;;
1076 esac
1078 exit 0