cookutils view cook @ rev 242

Revert last commit, dont do things too quckly...
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 27 18:46:06 2011 +0200 (2011-05-27)
parents 35541dcaad12
children 7484825355cc
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 else
614 gettext "No packages rules: meta package"; echo
615 mkdir -p $fs
616 fi
618 # First QA check to stop now if genpkg_rules failed.
619 if fgrep -q ERROR: $LOGS/$pkg.log; then
620 exit 1
621 fi
623 cd $taz
624 for file in receipt description.txt
625 do
626 [ ! -f "../$file" ] && continue
627 gettext "Copying"; echo -n " $file..."
628 cp -f ../$file $pack && chown 0.0 $pack/$file && status
629 done
630 copy_generic_files
632 # Create files.list with redirecting find output.
633 gettext "Creating the list of files..." && cd $fs
634 find . -type f -print > ../files.list
635 find . -type l -print >> ../files.list
636 cd .. && sed -i s/'^.'/''/ files.list
637 status
639 # Strip and stuff files.
640 strip_package
642 # Md5sum of files.
643 gettext "Creating md5sum of files..."
644 while read file; do
645 [ -L "fs$file" ] && continue
646 [ -f "fs$file" ] || continue
647 case "$file" in
648 /lib/modules/*/modules.*|*.pyc) continue ;;
649 esac
650 md5sum "fs$file" | sed 's/ fs/ /'
651 done < files.list > md5sum
652 status
653 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
654 description.txt 2> /dev/null | awk \
655 '{ sz=$1 } END { print sz }')
657 # Build cpio archives.
658 gettext "Compressing the fs... "
659 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
660 rm -rf fs
661 status
662 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
663 md5sum description.txt 2> /dev/null | awk \
664 '{ sz=$1 } END { print sz }')
665 gettext "Updating receipt sizes..."
666 sed -i s/^PACKED_SIZE.*$// receipt
667 sed -i s/^UNPACKED_SIZE.*$// receipt
668 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
669 status
671 # Set extra version.
672 if [ "$EXTRAVERSION" ]; then
673 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
674 sed -i s/^EXTRAVERSION.*$// receipt
675 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
676 status
677 fi
679 # Compress.
680 gettext "Creating full cpio archive... "
681 find . -print | cpio -o -H newc --quiet > \
682 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
683 status
684 gettext "Restoring original package tree... "
685 unlzma -c fs.cpio.lzma | cpio -idm --quiet
686 status
687 rm fs.cpio.lzma && cd ..
689 # QA and give info.
690 tazpkg=$(ls *.tazpkg)
691 packit_quality
692 separator && gettext "Package:"; echo -e " $tazpkg\n"
693 }
695 # Verify package quality and consistency.
696 packit_quality() {
697 #gettext "QA: Checking for broken link..."
698 #link=$(find $fs/usr -type l -follow)
699 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
700 #status
702 # Exit if any error found in log file.
703 if fgrep -q ERROR: $LOGS/$pkg.log; then
704 rm -f $command && exit 1
705 fi
707 gettext "QA: Checking for empty package..."
708 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
709 if [ "$files" -lt 0 ] && [ "$CATEGORY" != "meta" ]; then
710 echo -e "\nERROR: empty package"
711 rm -f $command && exit 1
712 else
713 # Ls sort by name so the first file is the one we want.
714 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
715 status
716 if [ -f "$old" ]; then
717 echo -n "Removing old: $(basename $old)"
718 rm -f $old && status
719 fi
720 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
721 sed -i /^${pkg}$/d $broken
722 fi
723 }
725 #
726 # Commands
727 #
729 case "$1" in
730 usage|help|-u|-h)
731 usage ;;
732 list-wok)
733 gettext -e "\nList of packages in:"; echo " $WOK"
734 separator
735 cd $WOK && ls -1
736 separator
737 echo -n "Packages: " && ls | wc -l
738 echo "" ;;
739 search)
740 # Just a simple search function, we dont need more actually.
741 query="$2"
742 gettext -e "\nSearch results for:"; echo " $query"
743 separator
744 cd $WOK && ls -1 | grep "$query"
745 separator && echo "" ;;
746 setup)
747 # Setup a build environment
748 check_root
749 echo "Cook: setting up the environment" | log
750 gettext -e "\nSetting up your environment\n"
751 separator && cd $SLITAZ
752 init_db_files
753 gettext -e "Checking for packages to install...\n"
754 for pkg in $SETUP_PKGS
755 do
756 [ ! -f "$INSTALLED/$pkg/receipt" ] && tazpkg get-install $pkg
757 done
759 # Handle --options
760 case "$2" in
761 --wok|-w)
762 hg clone $WOK_URL wok || exit 1 ;;
763 --stable)
764 hg clone $WOK_URL-stable wok || exit 1 ;;
765 --undigest)
766 hg clone $WOK_URL-undigest wok || exit 1 ;;
767 esac
769 # SliTaz group and permissions
770 if ! grep -q ^slitaz /etc/group; then
771 gettext -e "Adding group: slitaz\n"
772 addgroup slitaz
773 fi
774 gettext -e "Setting permissions for slitaz group...\n"
775 chown -R root.slitaz $SLITAZ
776 chmod -R g+w $SLITAZ
777 separator
778 gettext -e "All done, ready to cook packages :-)\n\n" ;;
779 test)
780 # Test a cook environment.
781 echo "Cook test: testing the cook environment" | log
782 [ ! -d "$WOK" ] && exit 1
783 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
784 cook cooktest ;;
785 new)
786 # Create the package folder and an empty receipt.
787 pkg="$2"
788 [ "$pkg" ] || usage
789 echo ""
790 if [ -d "$WOK/$pkg" ]; then
791 echo -n "$pkg " && gettext "package already exists."
792 echo -e "\n" && exit 1
793 fi
794 gettext "Creating"; echo -n " $WOK/$pkg"
795 mkdir $WOK/$pkg && cd $WOK/$pkg && status
796 gettext "Preparing the package receipt..."
797 cp $DATA/receipt .
798 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
799 status && echo ""
801 # Interactive mode, asking and seding.
802 case "$3" in
803 --interactive|-x)
804 gettext -e "Entering interactive mode...\n"
805 separator
806 echo "Package : $pkg"
807 # Version.
808 echo -n "Version : " ; read anser
809 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
810 # Category.
811 echo -n "Category : " ; read anser
812 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
813 # Short description.
814 echo -n "Short desc : " ; read anser
815 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
816 # Maintainer.
817 echo -n "Maintainer : " ; read anser
818 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
819 # Web site.
820 echo -n "Web site : " ; read anser
821 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
822 echo ""
823 # Wget URL.
824 echo "Wget URL to download source tarball."
825 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
826 echo -n "Wget url : " ; read anser
827 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
828 # Ask for a stuff dir.
829 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
830 if [ "$anser" = "y" ]; then
831 echo -n "Creating the stuff directory..."
832 mkdir $WOK/$pkg/stuff && status
833 fi
834 # Ask for a description file.
835 echo -n "Are you going to write a description ? (y/N) : " ; read anser
836 if [ "$anser" = "y" ]; then
837 echo -n "Creating the description.txt file..."
838 echo "" > $WOK/$pkg/description.txt && status
839 fi
840 separator
841 gettext -e "Receipt is ready to use.\n"
842 echo "" ;;
843 esac ;;
844 list)
845 # Cook a list of packages (better use the Cooker since it will order
846 # packages before executing cook).
847 check_root
848 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
849 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
850 echo -e " $2\n" && exit 1
851 echo "Cook list starting: $2" | log
852 for pkg in $(cat $2)
853 do
854 cook $pkg || broken
855 done ;;
856 clean-wok)
857 check_root
858 gettext -e "\nCleaning all packages files..."
859 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
860 status && echo "" ;;
861 clean-src)
862 check_root
863 gettext -e "\nCleaning all packages sources..."
864 rm -rf $WOK/*/source
865 status && echo "" ;;
866 pkgdb)
867 # Create suitable packages list for TazPKG and only for built packages
868 # as well as flavors files for TazLiTo. We dont need logs since we do it
869 # manualy to ensure everything is fine before syncing the mirror.
870 case "$2" in
871 --flavors)
872 continue ;;
873 *)
874 [ "$2" ] && PKGS="$2"
875 [ ! -d "$PKGS" ] && \
876 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1 ;;
877 esac
878 time=$(date +%s)
879 flavors=$SLITAZ/flavors
880 live=$SLITAZ/live
881 echo "cook:pkgdb" > $command
882 echo "Cook pkgdb: Creating all packages lists" | log
883 echo ""
884 gettext "Creating lists for: "; echo "$PKGS"
885 separator
886 gettext "Cook pkgdb started: "; date "+%Y-%m-%d %H:%M"
887 cd $PKGS
888 rm -f packages.*
889 gettext -e "Creating: packages.list\n"
890 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
891 gettext -e "Creating: packages.md5\n"
892 md5sum *.tazpkg > $PKGS/packages.md5
893 gettext -e "Creating lists from: "; echo "$WOK"
894 cd $WOK
895 for pkg in *
896 do
897 unset_receipt
898 . $pkg/receipt
899 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
900 # packages.desc lets us search easily in DB
901 cat >> $PKGS/packages.desc << EOT
902 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
903 EOT
904 # packages.txt used by tazpkg and tazpkg-web also to provide
905 # a human readable package list with version and description.
906 cat >> $PKGS/packages.txt << EOT
907 $PACKAGE
908 ${VERSION}$EXTRAVERSION
909 $SHORT_DESC
910 $PACKED_SIZE ($UNPACKED_SIZE installed)
912 EOT
913 # packages.equiv is used by tazpkg install to check depends.
914 for i in $PROVIDE; do
915 DEST=""
916 echo $i | fgrep -q : && DEST="${i#*:}:"
917 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
918 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
919 $PKGS/packages.equiv
920 else
921 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
922 fi
923 done
924 # files.list provides a list of all packages files.
925 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
926 $PKGS/files.list
927 fi
928 done
930 # Display list size.
931 gettext -e "Done: packages.desc\n"
932 gettext -e "Done: packages.txt\n"
933 gettext -e "Done: packages.equiv\n"
935 # files.list.lzma
936 gettext -e "Creating: files.list.lzma\n"
937 cd $PKGS && lzma e files.list files.list.lzma
938 rm -f files.list
940 # Display some info.
941 separator
942 nb=$(ls $PKGS/*.tazpkg | wc -l)
943 time=$(($(date +%s) - $time))
944 echo -e "Packages: $nb - Time: ${time}s\n"
946 # Create all flavors files at once. Do we realy need code to monitor
947 # flavors changes ? Let just build them with packages lists before
948 # syncing the mirror.
949 [ "$2" == "--flavors" ] || exit 1
950 [ ! -d "$flavors" ] && echo -e "Missing flavors: $flavors\n" && exit 1
951 [ -d "$live" ] || mkdir -p $live
952 gettext "Creating flavors files in:"; echo " $live"
953 echo "Cook pkgdb: Creating all flavors" | log
954 separator
955 gettext -e "Recharging lists to use latest packages...\n"
956 tazpkg recharge 2>1 >/dev/null
958 # We need a custom tazlito config to set working dir to /home/slitaz.
959 if [ ! -f "$live/tazlito.conf" ]; then
960 echo "Creating configuration file: tazlito.conf"
961 cp /etc/tazlito/tazlito.conf $live
962 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
963 $live/tazlito.conf
964 fi
966 # Update Hg flavors repo and pack.
967 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
969 cd $live
970 echo "Starting to generate flavors..."
971 rm -f flavors.list *.flavor
972 for i in $flavors/*
973 do
974 fl=$(basename $i)
975 echo "Packing flavor: $(basename $i)"
976 tazlito pack-flavor $fl >/dev/null || exit 1
977 tazlito show-flavor $fl --brief --noheader 2> \
978 /dev/null >> flavors.list
979 done
980 cp -f $live/*.flavor $live/flavors.list $PKGS
981 separator && gettext "Flavors size: "; du -sh $live | awk '{print $1}'
982 echo "" && rm -f $command ;;
983 *)
984 # Just cook and generate a package.
985 check_root
986 time=$(date +%s)
987 pkg="$1"
988 [ -z "$pkg" ] && usage
989 receipt="$WOK/$pkg/receipt"
990 check_pkg_in_wok && echo ""
992 # Display and log info if cook process stopped.
993 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
994 tee -a $LOGS/$pkg.log' INT
996 # Skip blocked, 3 lines also for the Cooker.
997 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
998 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
999 fi
1001 # Log and source receipt.
1002 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1003 echo "cook:$pkg" > $command
1004 unset inst
1005 unset_receipt
1006 . $receipt
1008 # Handle --options
1009 case "$2" in
1010 --clean|-c)
1011 gettext -e "Cleaning:"; echo -n " $pkg"
1012 cd $WOK/$pkg && rm -rf install taz source
1013 status && echo "" && exit 0 ;;
1014 --install|-i)
1015 inst='yes' ;;
1016 --getsrc|-gs)
1017 gettext "Getting source for:"; echo " $pkg"
1018 separator && get_source
1019 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
1020 --block|-b)
1021 gettext "Blocking:"; echo -n " $pkg"
1022 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1023 status && echo "" && exit 0 ;;
1024 --unblock|-ub)
1025 gettext "Unblocking:"; echo -n " $pkg"
1026 sed -i "/^${pkg}$/"d $blocked
1027 status && echo "" && exit 0 ;;
1029 esac
1031 # Check if wanted is built now so we have separate log files.
1032 if [ "$WANTED" ]; then
1033 if grep -q "^$WANTED$" $blocked; then
1034 echo "WANTED package is blocked: $WANTED" | tee $LOGS/$pkg.log
1035 echo "" && rm -f $command && exit 1
1036 fi
1037 if grep -q "^$WANTED$" $broken; then
1038 echo "WANTED package is broken: $WANTED" | tee $LOGS/$pkg.log
1039 echo "" && rm -f $command && exit 1
1040 fi
1041 if [ ! -d "$WOK/$WANTED/install" ]; then
1042 cook "$WANTED" || exit 1
1043 fi
1044 fi
1046 # Cook and pack or exit on error and log everything.
1047 cookit $@ 2>&1 | tee $LOGS/$pkg.log
1048 remove_deps | tee -a $LOGS/$pkg.log
1049 cookit_quality
1050 packit 2>&1 | tee -a $LOGS/$pkg.log
1051 clean_log
1053 # Exit if any error in packing.
1054 if grep -q ^ERROR $LOGS/$pkg.log; then
1055 debug_info | tee -a $LOGS/$pkg.log
1056 rm -f $command && exit 1
1057 fi
1059 # Time and summary
1060 time=$(($(date +%s) - $time))
1061 summary | tee -a $LOGS/$pkg.log
1062 echo ""
1064 # Install package if requested
1065 if [ "$inst" ]; then
1066 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1067 cd $PKGS && tazpkg install \
1068 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1069 else
1070 gettext -e "Unable to install package, build has failed.\n\n"
1071 exit 1
1072 fi
1073 fi
1074 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1075 # You want automation: use the Cooker Build Bot.
1076 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
1077 rm -f $command ;;
1078 esac
1080 exit 0