cookutils view cook @ rev 250

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