cookutils view cook @ rev 244

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