cookutils view cook @ rev 236

cook: recharge pkgs list before creating flavors and up documentation
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 27 13:43:35 2011 +0200 (2011-05-27)
parents dc667a8b58d4
children bcc48b546d5b
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 lists and pack 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.")
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 # Kernel version is set from linux-api-headers since it part of toolchain.
177 if [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
178 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d '"' -f 2)
179 fi
180 # Old way compatibility.
181 _pkg=$install
182 }
184 # Create source tarball when URL is a SCM.
185 create_tarball() {
186 gettext "Creating tarball: "; echo "$tarball"
187 if [ "$LZMA_SRC" ]; then
188 tar -c $pkgsrc | lzma e $SRC/$tarball -si || exit 1
189 else
190 tar cjf $tarball $pkgsrc || exit 1
191 mv $tarball $SRC && rm -rf $pkgsrc
192 fi
193 }
195 # Get package source. For SCM we are in cache so clone here and create a
196 # tarball here.
197 get_source() {
198 pwd=$(pwd)
199 pkgsrc=${SOURCE:-$PACKAGE}-$VERSION
200 tarball=$pkgsrc.tar.bz2
201 [ "$LZMA_SRC" ] && tarball=$pkgsrc.tar.lzma
202 case "$WGET_URL" in
203 http://*|ftp://*)
204 # Busybox Wget is better!
205 busybox wget -T 12 -c -P $SRC $WGET_URL || \
206 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
207 https://*)
208 wget -c --no-check-certificate -P $SRC $WGET_URL || \
209 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
210 hg*|mercurial*)
211 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
212 url=${WGET_URL#hg|}
213 else
214 url=${WGET_URL#mercurial|}
215 fi
216 gettext -e "Getting source from Hg...\n"
217 echo "URL: $url"
218 gettext "Cloning to: "; echo "$pwd/$pkgsrc"
219 hg clone $url $pkgsrc || (echo "ERROR: hg clone $url" && exit 1)
220 create_tarball ;;
221 git*)
222 url=${WGET_URL#git|}
223 gettext -e "Getting source from Git...\n"
224 echo "URL: $url"
225 git clone $url $pkgsrc || (echo "ERROR: git clone $url" && exit 1)
226 if [ "$BRANCH" ]; then
227 echo "Git branch: $BRANCH"
228 cd $pkgsrc && git checkout $BRANCH && cd ..
229 fi
230 create_tarball ;;
231 cvs*)
232 url=${WGET_URL#cvs|}
233 mod=$PACKAGE
234 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
235 gettext -e "Getting source from CVS...\n"
236 echo "URL: $url"
237 [ "$CVS_MODULE" ] && echo "CVS module: $mod"
238 gettext "Cloning to: "; echo "$pwd/$mod"
239 cvs -d:$url co $mod && mv $mod $pkgsrc
240 create_tarball ;;
241 svn*|subversion*)
242 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
243 url=${WGET_URL#svn|}
244 else
245 url=${WGET_URL#subversion|}
246 fi
247 gettext -e "Getting source from SVN...\n"
248 echo "URL: $url"
249 if [ "$BRANCH" ]; then
250 echo t | svn co $url -r $BRANCH $pkgsrc
251 else
252 echo t | svn co $url $pkgsrc
253 fi
254 create_tarball ;;
255 *)
256 gettext -e "\nERROR: Unable to handle:"; echo -e " $WGET_URL \n" | \
257 tee -a $LOGS/$PACKAGE.log
258 exit 1 ;;
259 esac
260 }
262 # Extract source package.
263 extract_source() {
264 if [ ! -s "$SRC/$TARBALL" ]; then
265 local url
266 url="http://mirror.slitaz.org/sources/packages"
267 url=$url/${TARBALL:0:1}/$TARBALL
268 gettext "Getting source from mirror:"; echo " $url"
269 busybox wget -c -P $SRC $url || echo -e "ERROR: wget $url"
270 fi
271 gettext "Extracting:"; echo " $TARBALL"
272 case "$TARBALL" in
273 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
274 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
275 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
276 *.tar) tar xf $SRC/$TARBALL ;;
277 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
278 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
279 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
280 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
281 *.run) /bin/sh $SRC/$TARBALL ;;
282 *) cp $SRC/$TARBALL $(pwd) ;;
283 esac
284 }
286 # Display cooked package summary.
287 summary() {
288 cd $WOK/$pkg
289 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
290 fs=$(du -sh taz/* | awk '{print $1}')
291 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
292 files=$(cat taz/$pkg-*/files.list | wc -l)
293 cookdate=$(date "+%Y-%m-%d %H:%M")
294 sec=$time
295 div=$(($time / 60))
296 [ "$div" != 0 ] && min="~ ${div}m"
297 gettext "Summary for:"; echo " $PACKAGE $VERSION"
298 separator
299 [ "$prod" ] && echo "Produced : $prod"
300 cat << EOT
301 Packed : $fs
302 Compressed : $size
303 Files : $files
304 Cook time : ${sec}s $min
305 Cook date : $cookdate
306 $(separator)
307 EOT
308 }
310 # Display debugging error info.
311 debug_info() {
312 echo -e "\nDebug information"
313 separator
314 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
315 for error in \
316 ERROR "No package" "cp: can't" "can't open" "can't cd" \
317 "error:" "fatal error:"
318 do
319 fgrep "$error" $LOGS/$pkg.log
320 done
321 separator && echo ""
322 }
324 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
325 # so some packages need to copy these files with the receipt and genpkg_rules.
326 copy_generic_files()
327 {
328 # $LOCALE is set in cook.conf
329 if [ "$LOCALE" ]; then
330 if [ -d "$_pkg/usr/share/locale" ]; then
331 mkdir -p $fs/usr/share/locale
332 for i in $LOCALE
333 do
334 if [ -d "$_pkg/usr/share/locale/$i" ]; then
335 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
336 fi
337 done
338 fi
339 fi
341 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
342 if [ "$GENERIC_PIXMAPS" != "no" ]; then
343 if [ -d "$_pkg/usr/share/pixmaps" ]; then
344 mkdir -p $fs/usr/share/pixmaps
345 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
346 $fs/usr/share/pixmaps 2>/dev/null
347 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
348 $fs/usr/share/pixmaps 2>/dev/null
349 fi
351 # Custom or homemade PNG pixmap can be in stuff.
352 if [ -f "$stuff/$PACKAGE.png" ]; then
353 mkdir -p $fs/usr/share/pixmaps
354 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
355 fi
356 fi
358 # Desktop entry (.desktop).
359 if [ -d "$_pkg/usr/share/applications" ]; then
360 cp -a $_pkg/usr/share/applications $fs/usr/share
361 fi
363 # Homemade desktop file(s) can be in stuff.
364 if [ -d "$stuff/applications" ]; then
365 mkdir -p $fs/usr/share
366 cp -a $stuff/applications $fs/usr/share
367 fi
368 if [ -f "$stuff/$PACKAGE.desktop" ]; then
369 mkdir -p $fs/usr/share/applications
370 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
371 fi
372 }
374 # Find and strip : --strip-all (-s) or --strip-debug on static libs as well
375 # as removing uneeded files like in Python packages.
376 strip_package()
377 {
378 gettext "Executing strip on all files..."
379 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
380 do
381 if [ -d "$dir" ]; then
382 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
383 fi
384 done
385 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
386 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
387 status
389 # Remove Python .pyc and .pyo from packages.
390 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
391 gettext "Removing Python compiled files..."
392 find $fs -type f -name "*.pyc" -delete 2>/dev/null
393 find $fs -type f -name "*.pyo" -delete 2>/dev/null
394 status
395 fi
397 # Remove Perl perllocal.pod and .packlist from packages.
398 if echo "$DEPENDS" | fgrep -q "perl"; then
399 gettext "Removing Perl compiled files..."
400 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
401 find $fs -type f -name ".packlist" -delete 2>/dev/null
402 status
403 fi
404 }
406 # Remove installed deps.
407 remove_deps() {
408 # Now remove installed build deps.
409 diff="$CACHE/installed.cook.diff"
410 if [ -s "$CACHE/installed.cook.diff" ]; then
411 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
412 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
413 gettext "Build dependencies to remove:"; echo " $nb"
414 gettext "Removing:"
415 for dep in $deps
416 do
417 echo -n " $dep"
418 echo 'y' | tazpkg remove $dep >/dev/null
419 done
420 echo -e "\n"
421 # Keep the last diff for debug and info.
422 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
423 fi
424 }
426 # The main cook function.
427 cookit() {
428 echo "Cook: $PACKAGE $VERSION"
429 separator
430 set_paths
431 [ "$QA" ] && receipt_quality
432 cd $pkgdir
433 rm -rf install taz source
435 # Disable -pipe if less than 512Mb free RAM.
436 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
437 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
438 gettext -e "Disabling -pipe compile flag: $free RAM\n"
439 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
440 CXXFLAGS="${CXXFLAGS/-pipe}" && \
441 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
442 fi
443 unset free
445 # Export flags and path to be used by make and receipt.
446 DESTDIR=$pkgdir/install
447 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
449 # Check for build deps and handle implicit depends of *-dev packages
450 # (ex: libusb-dev :: libusb).
451 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
452 touch $CACHE/installed.local $CACHE/installed.web
453 [ "$BUILD_DEPENDS" ] && gettext -e "Checking build dependencies...\n"
454 for dep in $BUILD_DEPENDS
455 do
456 implicit=${dep%-dev}
457 for i in $dep $implicit
458 do
459 if [ ! -f "$INSTALLED/$i/receipt" ]; then
460 # Try local package first. In some cases implicit doesn't exist, ex:
461 # libboost-dev exists but not libboost, so check if we got vers.
462 unset vers
463 vers=$(grep ^VERSION= $WOK/$i/receipt 2>/dev/null | cut -d '"' -f 2)
464 if [ -f "$PKGS/$i-$vers.tazpkg" ]; then
465 echo $i-$vers.tazpkg >> $CACHE/installed.local
466 else
467 # Priority to package version in wok (maybe more up-to-date)
468 # than the mirrored one.
469 if [ "$vers" ]; then
470 if fgrep -q $i-$vers $DB/packages.list; then
471 echo $i >> $CACHE/installed.web
472 else
473 # So package exists in wok but not available.
474 gettext "Missing dep (wok/pkg):"; echo " $i $vers"
475 echo $i >> $CACHE/missing.dep
476 fi
477 else
478 # Package is not in wok but may be in repo.
479 if fgrep -q $i-$vers $DB/packages.list; then
480 echo $i >> $CACHE/installed.web
481 else
482 echo "ERROR: unknown dep $i" && exit 1
483 fi
484 fi
485 fi
486 fi
487 done
488 done
490 # Get the list of installed packages
491 cd $INSTALLED && ls -1 > $CACHE/installed.list
493 # Have we a missing build dep to cook ?
494 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
495 gettext -e "Auto cook config is set : AUTO_COOK\n"
496 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
497 for i in $(uniq $CACHE/missing.dep)
498 do
499 (gettext "Building dep (wok/pkg) :"; echo " $i $vers") | \
500 tee -a $LOGS/$PACKAGE.log.$$
501 cook $i || (echo -e "ERROR: can't cook dep '$i'\n" && \
502 fgrep "remove: " $LOGS/$i.log && \
503 fgrep "Removing: " $LOGS/$i.log && echo "") | \
504 tee -a $LOGS/$PACKAGE.log.$$ && break
505 done
506 rm -f $CACHE/missing.dep
507 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
508 fi
510 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
511 # is enabled and cook fails we have ERROR in log, if no auto cook we have
512 # missing dep in cached file.
513 if fgrep -q "ERROR:" $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
514 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
515 echo "ERROR: missing dep $nb" && exit 1
516 fi
518 # Install local packages.
519 cd $PKGS
520 for i in $(uniq $CACHE/installed.local)
521 do
522 gettext "Installing dep (pkg/local):"; echo " $i"
523 tazpkg install $i >/dev/null
524 done
526 # Install web or cached packages (if mirror is set to $PKGS we only
527 # use local packages).
528 for i in $(uniq $CACHE/installed.web)
529 do
530 gettext "Installing dep (web/cache):"; echo " $i"
531 tazpkg get-install $i >/dev/null
532 done
534 # If a cook failed deps are removed.
535 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
536 [ ! -s "installed.cook.diff" ] && \
537 busybox diff installed.list installed.cook > installed.cook.diff
538 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
540 # Get source tarball and make sure we have source dir named:
541 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
542 # tarball if it exists.
543 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
544 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
545 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
546 LZMA_SRC=""
547 else
548 get_source || exit 1
549 fi
550 fi
551 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
552 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
553 extract_source || exit 1
554 if [ "$LZMA_SRC" ]; then
555 cd $pkgdir/source
556 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
557 mv tmp tmp-1 && mkdir tmp
558 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
559 fi
560 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
561 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
562 fi
563 fi
564 cd $pkgdir/source/tmp
565 # Some archives are not well done and don't extract to one dir (ex lzma).
566 files=$(ls | wc -l)
567 [ "$files" == 1 ] && mv * ../$PACKAGE-$VERSION
568 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
569 mv * ../$PACKAGE-$VERSION
570 cd .. && rm -rf tmp
571 fi
573 # Execute receipt rules.
574 if grep -q ^compile_rules $receipt; then
575 gettext -e "Executing: compile_rules\n"
576 [ -d "$src" ] && cd $src
577 compile_rules $@ || exit 1
578 # Stay compatible with _pkg
579 [ -d "$src/_pkg" ] && mv $src/_pkg $install
580 # QA: compile_rules success so valid.
581 mkdir -p $install
582 else
583 # QA: No compile_rules so no error, valid.
584 mkdir -p $install
585 fi
586 separator && echo ""
587 }
589 # Cook quality assurance.
590 cookit_quality() {
591 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
592 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
593 fi
594 # ERROR can be echoed any time in cookit()
595 if fgrep -q ERROR: $LOGS/$pkg.log; then
596 debug_info | tee -a $LOGS/$pkg.log
597 rm -f $command && exit 1
598 fi
599 }
601 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
602 # but it doesn't handle EXTRAVERSION.
603 packit() {
604 set_paths
605 echo "Pack: $PACKAGE $VERSION"
606 separator
607 if grep -q ^genpkg_rules $receipt; then
608 gettext -e "Executing: genpkg_rules\n"
609 cd $pkgdir && mkdir -p $fs
610 genpkg_rules || echo -e "\nERROR: genpkg_rules failed\n" >> \
611 $LOGS/$pkg.log
612 fi
614 # First QA check to stop now if genpkg_rules failed.
615 if fgrep -q ERROR: $LOGS/$pkg.log; then
616 exit 1
617 fi
619 cd $taz
620 for file in receipt description.txt
621 do
622 [ ! -f "../$file" ] && continue
623 gettext "Copying"; echo -n " $file..."
624 cp -f ../$file $pack && chown 0.0 $pack/$file && status
625 done
626 copy_generic_files
628 # Create files.list with redirecting find output.
629 gettext "Creating the list of files..." && cd $fs
630 find . -type f -print > ../files.list
631 find . -type l -print >> ../files.list
632 cd .. && sed -i s/'^.'/''/ files.list
633 status
635 # Strip and stuff files.
636 strip_package
638 # Md5sum of files.
639 gettext "Creating md5sum of files..."
640 while read file; do
641 [ -L "fs$file" ] && continue
642 [ -f "fs$file" ] || continue
643 case "$file" in
644 /lib/modules/*/modules.*|*.pyc) continue ;;
645 esac
646 md5sum "fs$file" | sed 's/ fs/ /'
647 done < files.list > md5sum
648 status
649 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
650 description.txt 2> /dev/null | awk \
651 '{ sz=$1 } END { print sz }')
653 # Build cpio archives.
654 gettext "Compressing the fs... "
655 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
656 rm -rf fs
657 status
658 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
659 md5sum description.txt 2> /dev/null | awk \
660 '{ sz=$1 } END { print sz }')
661 gettext "Updating receipt sizes..."
662 sed -i s/^PACKED_SIZE.*$// receipt
663 sed -i s/^UNPACKED_SIZE.*$// receipt
664 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
665 status
667 # Set extra version.
668 if [ "$EXTRAVERSION" ]; then
669 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
670 sed -i s/^EXTRAVERSION.*$// receipt
671 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
672 status
673 fi
675 # Compress.
676 gettext "Creating full cpio archive... "
677 find . -print | cpio -o -H newc --quiet > \
678 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
679 status
680 gettext "Restoring original package tree... "
681 unlzma -c fs.cpio.lzma | cpio -idm --quiet
682 status
683 rm fs.cpio.lzma && cd ..
685 # QA and give info.
686 tazpkg=$(ls *.tazpkg)
687 packit_quality
688 separator && gettext "Package:"; echo -e " $tazpkg\n"
689 }
691 # Verify package quality and consistency.
692 packit_quality() {
693 #gettext "QA: Checking for broken link..."
694 #link=$(find $fs/usr -type l -follow)
695 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
696 #status
698 # Exit if any error found in log file.
699 if fgrep -q ERROR: $LOGS/$pkg.log; then
700 rm -f $command && exit 1
701 fi
703 gettext "QA: Checking for empty package..."
704 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
705 if [ "$files" -lt 0 ] && [ "$CATEGORY" != "meta" ]; then
706 echo -e "\nERROR: empty package"
707 rm -f $command && exit 1
708 else
709 # Ls sort by name so the first file is the one we want.
710 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
711 status
712 if [ -f "$old" ]; then
713 echo -n "Removing old: $(basename $old)"
714 rm -f $old && status
715 fi
716 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
717 sed -i /^${pkg}$/d $broken
718 fi
719 }
721 #
722 # Commands
723 #
725 case "$1" in
726 usage|help|-u|-h)
727 usage ;;
728 list-wok)
729 gettext -e "\nList of packages in:"; echo " $WOK"
730 separator
731 cd $WOK && ls -1
732 separator
733 echo -n "Packages: " && ls | wc -l
734 echo "" ;;
735 search)
736 # Just a simple search function, we dont need more actually.
737 query="$2"
738 gettext -e "\nSearch results for:"; echo " $query"
739 separator
740 cd $WOK && ls -1 | grep "$query"
741 separator && echo "" ;;
742 setup)
743 # Setup a build environment
744 check_root
745 echo "Cook: setting up the environment" | log
746 gettext -e "\nSetting up your environment\n"
747 separator && cd $SLITAZ
748 init_db_files
749 gettext -e "Checking for packages to install...\n"
750 for pkg in $SETUP_PKGS
751 do
752 [ ! -f "$INSTALLED/$pkg/receipt" ] && tazpkg get-install $pkg
753 done
755 # Handle --options
756 case "$2" in
757 --wok|-w)
758 hg clone $WOK_URL wok || exit 1 ;;
759 --stable)
760 hg clone $WOK_URL-stable wok || exit 1 ;;
761 --undigest)
762 hg clone $WOK_URL-undigest wok || exit 1 ;;
763 esac
765 # SliTaz group and permissions
766 if ! grep -q ^slitaz /etc/group; then
767 gettext -e "Adding group: slitaz\n"
768 addgroup slitaz
769 fi
770 gettext -e "Setting permissions for slitaz group...\n"
771 chown -R root.slitaz $SLITAZ
772 chmod -R g+w $SLITAZ
773 separator
774 gettext -e "All done, ready to cook packages :-)\n\n" ;;
775 test)
776 # Test a cook environment.
777 echo "Cook test: testing the cook environment" | log
778 [ ! -d "$WOK" ] && exit 1
779 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
780 cook cooktest ;;
781 new)
782 # Create the package folder and an empty receipt.
783 pkg="$2"
784 [ "$pkg" ] || usage
785 echo ""
786 if [ -d "$WOK/$pkg" ]; then
787 echo -n "$pkg " && gettext "package already exists."
788 echo -e "\n" && exit 1
789 fi
790 gettext "Creating"; echo -n " $WOK/$pkg"
791 mkdir $WOK/$pkg && cd $WOK/$pkg && status
792 gettext "Preparing the package receipt..."
793 cp $DATA/receipt .
794 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
795 status && echo ""
797 # Interactive mode, asking and seding.
798 case "$3" in
799 --interactive|-x)
800 gettext -e "Entering interactive mode...\n"
801 separator
802 echo "Package : $pkg"
803 # Version.
804 echo -n "Version : " ; read anser
805 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
806 # Category.
807 echo -n "Category : " ; read anser
808 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
809 # Short description.
810 echo -n "Short desc : " ; read anser
811 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
812 # Maintainer.
813 echo -n "Maintainer : " ; read anser
814 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
815 # Web site.
816 echo -n "Web site : " ; read anser
817 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
818 echo ""
819 # Wget URL.
820 echo "Wget URL to download source tarball."
821 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
822 echo -n "Wget url : " ; read anser
823 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
824 # Ask for a stuff dir.
825 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
826 if [ "$anser" = "y" ]; then
827 echo -n "Creating the stuff directory..."
828 mkdir $WOK/$pkg/stuff && status
829 fi
830 # Ask for a description file.
831 echo -n "Are you going to write a description ? (y/N) : " ; read anser
832 if [ "$anser" = "y" ]; then
833 echo -n "Creating the description.txt file..."
834 echo "" > $WOK/$pkg/description.txt && status
835 fi
836 separator
837 gettext -e "Receipt is ready to use.\n"
838 echo "" ;;
839 esac ;;
840 list)
841 # Cook a list of packages (better use the Cooker since it will order
842 # packages before executing cook).
843 check_root
844 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
845 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
846 echo -e " $2\n" && exit 1
847 echo "Cook list starting: $2" | log
848 for pkg in $(cat $2)
849 do
850 cook $pkg || broken
851 done ;;
852 clean-wok)
853 check_root
854 gettext -e "\nCleaning all packages files..."
855 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
856 status && echo "" ;;
857 clean-src)
858 check_root
859 gettext -e "\nCleaning all packages sources..."
860 rm -rf $WOK/*/source
861 status && echo "" ;;
862 pkgdb)
863 # Create suitable packages list for TazPKG and only for built packages
864 # as well as flavors files for TazLiTo. We dont need logs since we do it
865 # manualy to ensure everything is fine before syncing the mirror.
866 [ "$2" ] && PKGS="$2"
867 [ ! -d "$PKGS" ] && \
868 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1
869 time=$(date +%s)
870 echo "cook:pkgdb" > $command
871 echo "Cook pkgdb: Creating all packages lists" | log
872 echo ""
873 gettext "Creating lists for: "; echo "$PKGS"
874 separator
875 gettext "Cook pkgdb started: "; date "+%Y-%m-%d %H:%M"
876 cd $PKGS
877 rm -f packages.*
878 gettext -e "Creating: packages.list\n"
879 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
880 gettext -e "Creating: packages.md5\n"
881 md5sum *.tazpkg > $PKGS/packages.md5
882 gettext -e "Creating lists from: "; echo "$WOK"
883 cd $WOK
884 for pkg in *
885 do
886 unset_receipt
887 . $pkg/receipt
888 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
889 # packages.desc lets us search easily in DB
890 cat >> $PKGS/packages.desc << EOT
891 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
892 EOT
893 # packages.txt used by tazpkg and tazpkg-web also to provide
894 # a human readable package list with version and description.
895 cat >> $PKGS/packages.txt << EOT
896 $PACKAGE
897 ${VERSION}$EXTRAVERSION
898 $SHORT_DESC
899 $PACKED_SIZE ($UNPACKED_SIZE installed)
901 EOT
902 # packages.equiv is used by tazpkg install to check depends.
903 for i in $PROVIDE; do
904 DEST=""
905 echo $i | fgrep -q : && DEST="${i#*:}:"
906 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
907 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
908 $PKGS/packages.equiv
909 else
910 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
911 fi
912 done
913 # files.list provides a list of all packages files.
914 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
915 $PKGS/files.list
916 fi
917 done
919 # Display list size.
920 gettext -e "Done: packages.desc\n"
921 gettext -e "Done: packages.txt\n"
922 gettext -e "Done: packages.equiv\n"
924 # files.list.lzma
925 gettext -e "Creating: files.list.lzma\n"
926 cd $PKGS && lzma e files.list files.list.lzma
927 rm -f files.list
929 # Display some info.
930 separator
931 nb=$(ls $PKGS/*.tazpkg | wc -l)
932 time=$(($(date +%s) - $time))
933 echo -e "Packages: $nb - Time: ${time}s\n"
935 # Create all flavors files at once. Do we realy need code to monitor
936 # flavors changes ? Let just build them with packages lists before
937 # syncing the mirror.
938 flavors=$SLITAZ/flavors
939 live=$SLITAZ/live
940 [ -d "$flavors" ] || exit 0
941 gettext "Creating flavors files in:"; echo " $live"
942 separator
943 gettext -e "Recharging lists to use latest packages...\n"
944 tazpkg recharge 2>&1 >/dev/null
946 # We need a custom tazlito config to set working dir to /home/slitaz.
947 if [ ! -f "$live/tazlito.conf" ]; then
948 echo "Creating configuration file: tazlito.conf"
949 cp /etc/tazlito/tazlito.conf $live
950 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
951 $live/tazlito.conf
952 fi
954 # Update flavors repo and pack.
955 cd $flavors && hg pull -u
956 mkdir -p $live && cd $live
957 echo "Starting to generate flavors..."
958 rm -f flavors.list *.flavor
959 for i in $flavors/*
960 do
961 fl=$(basename $i)
962 echo "Packing flavor: $(basename $i)"
963 tazlito pack-flavor $fl >/dev/null || exit 1
964 tazlito show-flavor $fl --brief --noheader 2> \
965 /dev/null >> flavors.list
966 done
967 cp -f *.flavor flavors.list $PKGS
968 separator && gettext "Flavors size: "; du -sh $live | awk '{print $1}'
969 echo "" && rm -f $command ;;
970 *)
971 # Just cook and generate a package.
972 check_root
973 time=$(date +%s)
974 pkg="$1"
975 [ -z "$pkg" ] && usage
976 receipt="$WOK/$pkg/receipt"
977 check_pkg_in_wok && echo ""
979 # Display and log info if cook process stopped.
980 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
981 tee -a $LOGS/$pkg.log' INT
983 # Skip blocked, 3 lines also for the Cooker.
984 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
985 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
986 fi
988 # Log and source receipt.
989 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
990 echo "cook:$pkg" > $command
991 unset inst
992 unset_receipt
993 . $receipt
995 # Handle --options
996 case "$2" in
997 --clean|-c)
998 gettext -e "Cleaning:"; echo -n " $pkg"
999 cd $WOK/$pkg && rm -rf install taz source
1000 status && echo "" && exit 0 ;;
1001 --install|-i)
1002 inst='yes' ;;
1003 --getsrc|-gs)
1004 gettext "Getting source for:"; echo " $pkg"
1005 separator && get_source
1006 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
1007 --block|-b)
1008 gettext "Blocking:"; echo -n " $pkg"
1009 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1010 status && echo "" && exit 0 ;;
1011 --unblock|-ub)
1012 gettext "Unblocking:"; echo -n " $pkg"
1013 sed -i "/^${pkg}$/"d $blocked
1014 status && echo "" && exit 0 ;;
1016 esac
1018 # Check if wanted is built now so we have separate log files.
1019 if [ "$WANTED" ]; then
1020 if grep -q "^$WANTED$" $blocked; then
1021 echo "WANTED package is blocked: $WANTED" | tee $LOGS/$pkg.log
1022 echo "" && rm -f $command && exit 1
1023 fi
1024 if grep -q "^$WANTED$" $broken; then
1025 echo "WANTED package is broken: $WANTED" | tee $LOGS/$pkg.log
1026 echo "" && rm -f $command && exit 1
1027 fi
1028 if [ ! -d "$WOK/$WANTED/install" ]; then
1029 cook "$WANTED" || exit 1
1030 fi
1031 fi
1033 # Cook and pack or exit on error and log everything.
1034 cookit $@ 2>&1 | tee $LOGS/$pkg.log
1035 remove_deps | tee -a $LOGS/$pkg.log
1036 cookit_quality
1037 packit 2>&1 | tee -a $LOGS/$pkg.log
1038 clean_log
1040 # Exit if any error in packing.
1041 if grep -q ^ERROR $LOGS/$pkg.log; then
1042 debug_info | tee -a $LOGS/$pkg.log
1043 rm -f $command && exit 1
1044 fi
1046 # Time and summary
1047 time=$(($(date +%s) - $time))
1048 summary | tee -a $LOGS/$pkg.log
1049 echo ""
1051 # Install package if requested
1052 if [ "$inst" ]; then
1053 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1054 cd $PKGS && tazpkg install \
1055 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1056 else
1057 gettext -e "Unable to install package, build has failed.\n\n"
1058 exit 1
1059 fi
1060 fi
1061 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1062 # You want automation: use the Cooker Build Bot.
1063 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
1064 rm -f $command ;;
1065 esac
1067 exit 0