cookutils view cook @ rev 278

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