cookutils view cook @ rev 230

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