cookutils view cook @ rev 190

cook: add LZMA patch from Godane (quote var in [test] please)
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 20 20:20:11 2011 +0200 (2011-05-20)
parents 4ea99f129598
children fe90a7071218
line source
1 #!/bin/sh
2 #
3 # Cook - A tool to cook and generate SliTaz packages. Read the README
4 # before adding or modifing any code in cook!
5 #
6 # Copyright (C) SliTaz GNU/Linux - GNU gpl v3
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
10 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
11 [ -f "cook.conf" ] && . ./cook.conf
13 # Share DB and status with the Cooker.
14 activity="$CACHE/activity"
15 command="$CACHE/command"
16 broken="$CACHE/broken"
17 blocked="$CACHE/blocked"
19 # Old style compatibility
20 SOURCES_REPOSITORY=$SRC
22 #
23 # Functions
24 #
26 usage() {
27 cat << EOT
29 $(echo -e "\033[1m$(gettext "Usage:")\033[0m") cook [package|command] [list|--option]
31 $(echo -e "\033[1m$(gettext "Commands:")\033[0m")
32 usage|help $(gettext "Display this short usage.")
33 setup $(gettext "Setup your build environment.")
34 test $(gettext "Test environment and cook a package.")
35 list-wok $(gettext "List packages in the wok.")
36 search $(gettext "Simple packages search function.")
37 new $(gettext "Create a new package with a receipt".)
38 list $(gettext "Cook a list of packages.")
39 clean-wok $(gettext "Clean-up all packages files.")
40 clean-src $(gettext "Clean-up all packages sources.")
41 pkglist $(gettext "Create all packages.* lists.")
43 $(echo -e "\033[1m$(gettext "Options:")\033[0m")
44 --clean|-c Cook : $(gettext "clean the package in the wok.")
45 --install|-i Cook : $(gettext "cook and install the package.")
46 --getsrc|-gs Cook : $(gettext "get the package source tarball.")
47 --block|-b Cook : $(gettext "Block a package so cook will skip it.")
48 --unblock|-ub Cook : $(gettext "Unblock a blocked package.")
49 --wok|-w Setup: $(gettext "create also a wok from Hg repo.")
51 EOT
52 exit 0
53 }
55 # Be sure we're root.
56 check_root() {
57 [ $(id -u) != 0 ] && gettext -e "\nYou must be root to cook.\n\n" && exit 0
58 }
60 separator() {
61 echo "================================================================================"
62 }
64 status() {
65 echo -en "\\033[70G[ "
66 if [ $? = 0 ]; then
67 echo -en "\\033[1;32mOK"
68 else
69 echo -en "\\033[1;31mFailed"
70 fi
71 echo -e "\\033[0;39m ]"
72 }
74 # Log activities, we want first letter capitalized.
75 log() {
76 grep ^[A-Z] | \
77 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
78 }
80 # We don't want these escapes in web interface.
81 clean_log() {
82 sed -i -e s'|\[70G\[ \[1;32m| |' \
83 -e s'|\[0;39m \]||' $LOGS/$pkg.log
84 }
86 # Log broken packages.
87 broken() {
88 if ! grep -q "^$pkg$" $broken; then
89 echo "$pkg" >> $broken
90 fi
91 }
93 # Be sure package exists in wok.
94 check_pkg_in_wok() {
95 if [ ! -d "$WOK/$pkg" ]; then
96 gettext -e "\nUnable to find package in the wok:"
97 echo -e " $pkg\n" && exit 1
98 fi
99 }
101 if_empty_value() {
102 if [ -z "$value" ]; then
103 gettext "QA: empty variable:"; echo -e " ${var}=\"\"\n"
104 exit 1
105 fi
106 }
108 # Initialize files used in $CACHE
109 init_db_files() {
110 gettext "Creating directories structure in:"; echo " $SLITAZ"
111 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS
112 gettext "Creating DB files in:"; echo " $CACHE"
113 for f in $activity $command $broken $blocked
114 do
115 touch $f
116 done
117 }
119 # QA: check a receipt consistency before building.
120 receipt_quality() {
121 gettext -e "QA: checking package receipt...\n"
122 unset online
123 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
124 online="online"
125 fi
126 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
127 do
128 unset value
129 value=$(grep ^$var= $receipt | cut -d \" -f 2)
130 case "$var" in
131 PACKAGE|VERSION|SHORT_DESC)
132 if_empty_value ;;
133 CATEGORY)
134 [ -z "$value" ] && value="empty"
135 valid="base-system x-window utilities network graphics \
136 multimedia office development system-tools security games \
137 misc meta non-free"
138 if ! echo "$valid" | grep -q -w "$value"; then
139 gettext "QA: unknown category:"; echo -e " $value\n"
140 exit 1
141 fi ;;
142 WEB_SITE)
143 # We don't check WGET_URL since if dl is needed it will fail.
144 # Break also if we're not online. Here error is not fatal.
145 if_empty_value
146 [ -z "$online" ] || break
147 if ! busybox wget -s $value 2>/dev/null; then
148 gettext "QA: Unable to reach:"; echo -e " $value"
149 fi ;;
150 esac
151 done
152 }
154 # Executed before sourcing a receipt.
155 unset_receipt() {
156 unset DEPENDS BUILD_DEPENDS WANTED EXTRAVERSION WGET_URL PROVIDE TARBALL
157 }
159 # Paths used in receipt and by cook itself.
160 set_paths() {
161 pkgdir=$WOK/$PACKAGE
162 src=$pkgdir/source/$PACKAGE-$VERSION
163 taz=$pkgdir/taz
164 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
165 fs=$pack/fs
166 stuff=$pkgdir/stuff
167 install=$pkgdir/install
168 if [ "$WANTED" ]; then
169 src=$WOK/$WANTED/source/$WANTED-$VERSION
170 install=$WOK/$WANTED/install
171 wanted_stuff=$WOK/$WANTED/stuff
172 fi
173 # Old way compatibility.
174 _pkg=$install
175 }
177 # Create source tarball when URL is a SCM.
178 create_tarball() {
179 gettext "Creating tarball: "; echo "$tarball"
180 if [ "$LZMA_SRC" ]; then
181 tar -c $pkgsrc | lzma e $SRC/$tarball -si || exit 1
182 else
183 tar cjf $tarball $pkgsrc || exit 1
184 mv $tarball $SRC && rm -rf $pkgsrc
185 fi
186 }
188 # Get package source. For SCM we are in cache so clone here and create a
189 # tarball here.
190 get_source() {
191 pwd=$(pwd)
192 pkgsrc=${SOURCE:-$PACKAGE}-$VERSION
193 tarball=$pkgsrc.tar.bz2
194 [ "$LZMA_SRC" ] && tarball=$pkgsrc.tar.lzma
195 case "$WGET_URL" in
196 http://*|ftp://*)
197 # Busybox Wget is better!
198 busybox wget -c -P $SRC $WGET_URL || \
199 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
200 https://*)
201 wget -c --no-check-certificate -P $SRC $WGET_URL || \
202 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
203 hg*|mercurial*)
204 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
205 url=${WGET_URL#hg|}
206 else
207 url=${WGET_URL#mercurial|}
208 fi
209 gettext -e "Getting source from Hg...\n"
210 echo "URL: $url"
211 gettext "Cloning to: "; echo "$pwd/$pkgsrc"
212 hg clone $url $pkgsrc || (echo "ERROR: hg clone $url" && exit 1)
213 create_tarball ;;
214 git*)
215 url=${WGET_URL#git|}
216 gettext -e "Getting source from Git...\n"
217 echo "URL: $url"
218 git clone $url $pkgsrc || (echo "ERROR: git clone $url" && exit 1)
219 if [ "$BRANCH" ]; then
220 echo "Git branch: $BRANCH"
221 cd $pkgsrc && git checkout $BRANCH && cd ..
222 fi
223 create_tarball ;;
224 cvs*)
225 url=${WGET_URL#cvs|}
226 mod=$PACKAGE
227 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
228 gettext -e "Getting source from CVS...\n"
229 echo "URL: $url"
230 [ "$CVS_MODULE" ] && echo "CVS module: $mod"
231 gettext "Cloning to: "; echo "$pwd/$mod"
232 cvs -d:$url co $mod && mv $mod $pkgsrc
233 create_tarball ;;
234 svn*|subversion*)
235 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
236 url=${WGET_URL#svn|}
237 else
238 url=${WGET_URL#subversion|}
239 fi
240 gettext -e "Getting source from SVN...\n"
241 echo "URL: $url"
242 if [ "$BRANCH" ]; then
243 echo t | svn co $url -r $BRANCH $pkgsrc
244 else
245 echo t | svn co $url $pkgsrc
246 fi
247 create_tarball ;;
248 *)
249 gettext -e "\nERROR: Unable to handle:"; echo -e " $WGET_URL \n" | \
250 tee -a $LOGS/$PACKAGE.log
251 exit 1 ;;
252 esac
253 }
255 # Extract source package.
256 extract_source() {
257 if [ ! -s "$SRC/$TARBALL" ]; then
258 local url
259 url="http://mirror.slitaz.org/sources/packages"
260 url=$url/${TARBALL:0:1}/$TARBALL
261 gettext "Getting source from mirror:"; echo " $url"
262 busybox wget -c -P $SRC $url || echo -e "ERROR: wget $url"
263 fi
264 gettext "Extracting:"; echo " $TARBALL"
265 case "$TARBALL" in
266 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
267 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
268 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
269 *.tar) tar xf $SRC/$TARBALL ;;
270 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
271 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
272 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
273 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
274 esac
275 }
277 # Display cooked package summary.
278 summary() {
279 cd $WOK/$pkg
280 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
281 fs=$(du -sh taz/* | awk '{print $1}')
282 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
283 files=$(cat taz/$pkg-*/files.list | wc -l)
284 cookdate=$(date "+%Y-%m-%d %H:%M")
285 sec=$time
286 div=$(($time / 60))
287 [ "$div" != 0 ] && min="~ ${div}m"
288 gettext "Summary for:"; echo " $PACKAGE $VERSION"
289 separator
290 [ "$prod" ] && echo "Produced : $prod"
291 cat << EOT
292 Packed : $fs
293 Compressed : $size
294 Files : $files
295 Cook time : ${sec}s $min
296 Cook date : $cookdate
297 $(separator)
298 EOT
299 }
301 # Display debugging error info.
302 debug_info() {
303 echo -e "\nDebug information"
304 separator
305 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
306 for error in \
307 ERROR "No package" "cp: can't" "can't open" "can't cd" \
308 "error:" "fatal error:"
309 do
310 fgrep "$error" $LOGS/$pkg.log
311 done
312 separator && echo ""
313 }
315 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
316 # so some packages need to copy these files with the receipt and genpkg_rules.
317 copy_generic_files()
318 {
319 # $LOCALE is set in cook.conf
320 if [ "$LOCALE" ]; then
321 if [ -d "$_pkg/usr/share/locale" ]; then
322 mkdir -p $fs/usr/share/locale
323 for i in $LOCALE
324 do
325 if [ -d "$_pkg/usr/share/locale/$i" ]; then
326 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
327 fi
328 done
329 fi
330 fi
332 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
333 if [ "$GENERIC_PIXMAPS" != "no" ]; then
334 if [ -d "$_pkg/usr/share/pixmaps" ]; then
335 mkdir -p $fs/usr/share/pixmaps
336 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
337 $fs/usr/share/pixmaps 2>/dev/null
338 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
339 $fs/usr/share/pixmaps 2>/dev/null
340 fi
342 # Custom or homemade PNG pixmap can be in stuff.
343 if [ -f "$stuff/$PACKAGE.png" ]; then
344 mkdir -p $fs/usr/share/pixmaps
345 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
346 fi
347 fi
349 # Desktop entry (.desktop).
350 if [ -d "$_pkg/usr/share/applications" ]; then
351 cp -a $_pkg/usr/share/applications $fs/usr/share
352 fi
354 # Homemade desktop file(s) can be in stuff.
355 if [ -d "$stuff/applications" ]; then
356 mkdir -p $fs/usr/share
357 cp -a $stuff/applications $fs/usr/share
358 fi
359 if [ -f "$stuff/$PACKAGE.desktop" ]; then
360 mkdir -p $fs/usr/share/applications
361 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
362 fi
363 }
365 # Find and strip : --strip-all (-s) or --strip-debug on static libs as well
366 # as removing uneeded files like in Python packages.
367 strip_package()
368 {
369 gettext "Executing strip on all files..."
370 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
371 do
372 if [ -d "$dir" ]; then
373 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
374 fi
375 done
376 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
377 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
378 status
380 # Remove Python .pyc and .pyo from packages.
381 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
382 gettext "Removing Python compiled files..."
383 find $fs -type f -name "*.pyc" -delete 2>/dev/null
384 find $fs -type f -name "*.pyo" -delete 2>/dev/null
385 status
386 fi
388 # Remove Perl perllocal.pod and .packlist from packages.
389 if echo "$DEPENDS" | fgrep -q "perl"; then
390 gettext "Removing Perl compiled files..."
391 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
392 find $fs -type f -name ".packlist" -delete 2>/dev/null
393 status
394 fi
395 }
397 # Remove installed deps.
398 remove_deps() {
399 # Now remove installed build deps.
400 diff="$CACHE/installed.cook.diff"
401 if [ -s "$CACHE/installed.cook.diff" ]; then
402 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
403 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
404 gettext "Build dependencies to remove:"; echo " $nb"
405 gettext "Removing:"
406 for dep in $deps
407 do
408 echo -n " $dep"
409 yes | tazpkg remove $dep >/dev/null
410 done
411 echo -e "\n"
412 # Keep the last diff for debug and info.
413 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
414 fi
415 }
417 # The main cook function.
418 cookit() {
419 echo "Cook: $PACKAGE $VERSION"
420 separator
421 set_paths
422 [ "$QA" ] && receipt_quality
423 cd $pkgdir
424 rm -rf install taz source
426 # Disable -pipe if less than 512Mb free RAM.
427 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
428 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
429 gettext -e "Disabling -pipe compile flag: $free RAM\n"
430 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
431 CXXFLAGS="${CXXFLAGS/-pipe}" && \
432 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
433 fi
434 unset free
436 # Export flags and path to be used by make
437 DESTDIR=$pkgdir/install
438 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS BUILD_HOST CONFIG_SITE
439 local LC_ALL=POSIX LANG=POSIX
441 # Check for build deps and handle implicit depends of *-dev packages
442 # (ex: libusb-dev :: libusb).
443 cd $INSTALLED && ls -1 > $CACHE/installed.list
444 [ "$DEPENDS" ] && gettext -e "Checking build dependencies...\n"
445 for dep in $BUILD_DEPENDS
446 do
447 implicit=${dep%-dev}
448 for i in $dep $implicit
449 do
450 if [ ! -f "$INSTALLED/$i/receipt" ]; then
451 # Try local package first. In some cases implicit doesn't exist, ex:
452 # libboost-dev exists but not libboost, so check if we got vers.
453 unset vers
454 vers=$(grep ^VERSION $WOK/$i/receipt 2>/dev/null | cut -d '"' -f 2)
455 if [ -f "$PKGS/$i-$vers.tazpkg" ]; then
456 gettext "Installing dep (pkg/local):"; echo " $i"
457 cd $PKGS && tazpkg install $i-$vers.tazpkg >/dev/null
458 else
459 if [ "$vers" ]; then
460 gettext "Installing dep (web/cache):"; echo " $i"
461 tazpkg get-install $i >/dev/null
462 fi
463 fi
464 fi
465 done
466 done
467 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
469 # If a cook failed deps are not removed since we exit 1.
470 [ ! -s "installed.cook.diff" ] && \
471 busybox diff installed.list installed.cook > installed.cook.diff
472 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
474 # Get source tarball and make sure we have source dir named:
475 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
476 # tarball if it exists.
477 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
478 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
479 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
480 LZMA_SRC=""
481 else
482 get_source || exit 1
483 fi
484 fi
485 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
486 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
487 extract_source || exit 1
488 if [ "$LZMA_SRC" ]; then
489 cd $pkgdir/source
490 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
491 mv tmp tmp-1 && mkdir tmp
492 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
493 fi
494 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
495 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
496 fi
497 fi
498 cd $pkgdir/source/tmp
499 # Some archives are not well done and don't extract to one dir (ex lzma).
500 files=$(ls | wc -l)
501 [ "$files" == 1 ] && mv * ../$PACKAGE-$VERSION
502 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
503 mv * ../$PACKAGE-$VERSION
504 cd .. && rm -rf tmp
505 fi
507 # Execute receipt rules.
508 if grep -q ^compile_rules $receipt; then
509 gettext -e "Executing: compile_rules\n"
510 [ -d "$src" ] && cd $src
511 compile_rules $@ || exit 1
512 # Stay compatible with _pkg
513 [ -d "$src/_pkg" ] && mv $src/_pkg $install
514 # QA: compile_rules success so valid.
515 mkdir -p $install
516 else
517 # QA: No compile_rules so no error, valid.
518 mkdir -p $install
519 fi
520 separator && echo ""
521 }
523 # Cook quality assurance.
524 cookit_quality() {
525 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
526 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
527 fi
528 # ERROR can be echoed any time in cookit()
529 if fgrep -q ERROR: $LOGS/$pkg.log; then
530 debug_info | tee -a $LOGS/$pkg.log
531 rm -f $command && exit 1
532 fi
533 }
535 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
536 # but it doesn't handle EXTRAVERSION.
537 packit() {
538 set_paths
539 echo "Pack: $PACKAGE $VERSION"
540 separator
541 if grep -q ^genpkg_rules $receipt; then
542 gettext -e "Executing: genpkg_rules\n"
543 cd $pkgdir
544 mkdir -p $fs && ( set -e; genpkg_rules ) || echo -e \
545 "\nERROR: genpkg_rules failed\n" >> $LOGS/$pkg.log
546 fi
548 # First QA check to stop now if genpkg_rules failed.
549 if fgrep -q ERROR: $LOGS/$pkg.log; then
550 exit 1
551 fi
553 cd $taz
554 for file in receipt description.txt
555 do
556 [ ! -f "../$file" ] && continue
557 gettext "Copying"; echo -n " $file..."
558 cp -f ../$file $pack && chown 0.0 $pack/$file && status
559 done
560 copy_generic_files
562 # Create files.list with redirecting find output.
563 gettext "Creating the list of files..." && cd $fs
564 find . -type f -print > ../files.list
565 find . -type l -print >> ../files.list
566 cd .. && sed -i s/'^.'/''/ files.list
567 status
569 # Strip and stuff files.
570 strip_package
572 # Md5sum of files.
573 gettext "Creating md5sum of files..."
574 while read file; do
575 [ -L "fs$file" ] && continue
576 [ -f "fs$file" ] || continue
577 case "$file" in
578 /lib/modules/*/modules.*|*.pyc) continue;;
579 esac
580 md5sum "fs$file" | sed 's/ fs/ /'
581 done < files.list > md5sum
582 status
583 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
584 description.txt 2> /dev/null | awk \
585 '{ sz=$1 } END { print sz }')
587 # Build cpio archives.
588 gettext "Compressing the fs... "
589 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
590 rm -rf fs
591 status
592 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
593 md5sum description.txt 2> /dev/null | awk \
594 '{ sz=$1 } END { print sz }')
595 gettext "Updating receipt sizes..."
596 sed -i s/^PACKED_SIZE.*$// receipt
597 sed -i s/^UNPACKED_SIZE.*$// receipt
598 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
599 status
601 # Set extra version.
602 if [ "$EXTRAVERSION" ]; then
603 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
604 sed -i s/^EXTRAVERSION.*$// receipt
605 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
606 status
607 fi
609 # Compress.
610 gettext "Creating full cpio archive... "
611 find . -print | cpio -o -H newc --quiet > \
612 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
613 status
614 gettext "Restoring original package tree... "
615 unlzma -c fs.cpio.lzma | cpio -idm --quiet
616 status
617 rm fs.cpio.lzma && cd ..
619 # QA and give info.
620 tazpkg=$(ls *.tazpkg)
621 packit_quality
622 separator && gettext "Package:"; echo -e " $tazpkg\n"
623 }
625 # Verify package quality and consistency.
626 packit_quality() {
627 #gettext "QA: Checking for broken link..."
628 #link=$(find $fs/usr -type l -follow)
629 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
630 #status
632 # Exit if any error found in log file.
633 if fgrep -q ERROR: $LOGS/$pkg.log; then
634 rm -f $command && exit 1
635 fi
637 gettext "QA: Checking for empty package..."
638 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
639 if [ "$files" -lt 0 ] && [ "$CATEGORY" != "meta" ]; then
640 echo -e "\nERROR: empty package"
641 rm -f $command && exit 1
642 else
643 # Ls sort by name so the first file is the one we want.
644 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
645 status
646 if [ -f "$old" ]; then
647 echo -n "Removing old: $(basename $old)"
648 rm -f $old && status
649 fi
650 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
651 sed -i /^${pkg}$/d $broken
652 fi
653 }
655 #
656 # Commands
657 #
659 case "$1" in
660 usage|help|-u|-h)
661 usage ;;
662 list-wok)
663 gettext -e "\nList of packages in:"; echo " $WOK"
664 separator
665 cd $WOK && ls -1
666 separator
667 echo -n "Packages: " && ls | wc -l
668 echo "" ;;
669 search)
670 # Just a simple search function, we dont need more actually.
671 query="$2"
672 gettext -e "\nSearch results for:"; echo " $query"
673 separator
674 cd $WOK && ls -1 | grep "$query"
675 separator && echo "" ;;
676 setup)
677 # Setup a build environment
678 check_root
679 echo "Cook: setting up the environment" | log
680 gettext -e "\nSetting up your environment\n"
681 separator && cd $SLITAZ
682 init_db_files
683 gettext -e "Checking for packages to install...\n"
684 for pkg in $SETUP_PKGS
685 do
686 [ ! -f "$INSTALLED/$pkg/receipt" ] && tazpkg get-install $pkg
687 done
689 # Handle --options
690 case "$2" in
691 --wok|-w)
692 [ ! -f "$INSTALLED/mercurial/receipt" ] && \
693 tazpkg get-install mercurial
694 [ -d "$WOK" ] && echo -e "A wok already exists.\n" && exit 1
695 hg clone $WOK_URL ;;
696 esac
698 # SliTaz group and permissions
699 if ! grep -q ^slitaz /etc/group; then
700 gettext -e "Adding group: slitaz\n"
701 addgroup slitaz
702 fi
703 gettext -e "Setting permissions for slitaz group...\n"
704 chown -R root.slitaz $SLITAZ
705 chmod -R g+w $SLITAZ
706 separator
707 gettext -e "All done, ready to cook packages :-)\n\n" ;;
708 test)
709 # Test a cook environment.
710 echo "Cook test: testing the cook environment" | log
711 [ ! -d "$WOK" ] && exit 1
712 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
713 cook cooktest ;;
714 new)
715 # Create the package folder and an empty receipt.
716 pkg="$2"
717 [ "$pkg" ] || usage
718 echo ""
719 if [ -d "$WOK/$pkg" ]; then
720 echo -n "$pkg " && gettext "package already exists."
721 echo -e "\n" && exit 1
722 fi
723 gettext "Creating"; echo -n " $WOK/$pkg"
724 mkdir $WOK/$pkg && cd $WOK/$pkg && status
725 gettext "Preparing the package receipt..."
726 cp $DATA/receipt .
727 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
728 status && echo "" ;;
729 list)
730 # Cook a list of packages (better use the Cooker since it will order
731 # packages before executing cook).
732 check_root
733 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
734 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
735 echo -e " $2\n" && exit 1
736 echo "Cook list starting: $2" | log
737 for pkg in $(cat $2)
738 do
739 cook $pkg || broken
740 done ;;
741 clean-wok)
742 check_root
743 gettext -e "\nCleaning all packages files..."
744 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
745 status && echo "" ;;
746 clean-src)
747 check_root
748 gettext -e "\nCleaning all packages sources..."
749 rm -rf $WOK/*/source
750 status && echo "" ;;
751 pkglist)
752 # Create suitable packages list for TazPKG and only for built packages.
753 [ "$2" ] && PKGS="$2"
754 [ ! -d "$PKGS" ] && \
755 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1
756 echo "cook:pkglist" > $command
757 echo "Cook pkglist: Creating all packages lists" | log
758 gettext -e "\nCreating lists for:"; echo " $PKGS"
759 separator
760 cd $PKGS
761 rm -f packages.* files.*
762 gettext -e "Creating: packages.list\n"
763 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
764 gettext -e "Creating: packages.md5\n"
765 md5sum *.tazpkg > $PKGS/packages.md5
766 gettext -e "Creating: packages.desc\n"
767 gettext -e "Creating: packages.equiv\n"
768 cd $WOK
769 for pkg in *
770 do
771 unset_receipt
772 . $pkg/receipt
773 # packages.desc lets us search easily in DB
774 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
775 cat >> $PKGS/packages.desc << EOT
776 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
777 EOT
778 # Packages.equiv is used by tazpkg install to check depends.
779 for i in $PROVIDE; do
780 DEST=""
781 echo $i | fgrep -q : && DEST="${i#*:}:"
782 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
783 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
784 $PKGS/packages.equiv
785 else
786 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
787 fi
788 done
789 fi
790 done
791 cd $PKGS
793 # packages.txt (redundancy list, all info is in pkgs desc).
794 touch packages.txt
796 # files.list.lzma
797 gettext -e "Creating: files.list.lzma\n"
798 touch files.list
799 lzma e files.list files.list.lzma
801 separator
802 nb=$(ls $PKGS/*.tazpkg | wc -l)
803 echo -e "Packages: $nb\n"
804 rm -f $command ;;
805 *)
806 # Just cook and generate a package.
807 check_root
808 time=$(date +%s)
809 pkg="$1"
810 [ -z "$pkg" ] && usage
811 receipt="$WOK/$pkg/receipt"
812 check_pkg_in_wok && echo ""
814 # Display and log info if cook process stopped.
815 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
816 tee -a $LOGS/$pkg.log' INT
818 # Skip blocked, 3 lines also for the Cooker.
819 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
820 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
821 fi
823 # Log and source receipt.
824 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
825 echo "cook:$pkg" > $command
826 unset inst
827 unset_receipt
828 . $receipt
830 # Handle --options
831 case "$2" in
832 --clean|-c)
833 gettext -e "Cleaning:"; echo -n " $pkg"
834 cd $WOK/$pkg && rm -rf install taz source
835 status && echo "" && exit 0 ;;
836 --install|-i)
837 inst='yes' ;;
838 --getsrc|-gs)
839 gettext "Getting source for:"; echo " $pkg"
840 separator && get_source
841 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
842 --block|-b)
843 gettext "Blocking:"; echo -n " $pkg"
844 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
845 status && echo "" && exit 0 ;;
846 --unblock|-ub)
847 gettext "Unblocking:"; echo -n " $pkg"
848 sed -i "/^${pkg}$/"d $blocked
849 status && echo "" && exit 0 ;;
850 esac
852 # Check if wanted is built now so we have separate log files.
853 if [ "$WANTED" ] && [ ! -d "$WOK/$WANTED/install" ]; then
854 if ! grep -q "^$WANTED$" $broken; then
855 cook "$WANTED"
856 fi
857 fi
859 # Cook and pack or exit on error and log everything.
860 cookit $@ 2>&1 | tee $LOGS/$pkg.log
861 remove_deps | tee -a $LOGS/$pkg.log
862 cookit_quality
863 packit 2>&1 | tee -a $LOGS/$pkg.log
864 clean_log
866 # Exit if any error in packing.
867 if grep -q ^ERROR $LOGS/$pkg.log; then
868 debug_info | tee -a $LOGS/$pkg.log
869 rm -f $command && exit 1
870 fi
872 # Time and summary
873 time=$(($(date +%s) - $time))
874 summary | tee -a $LOGS/$pkg.log
875 echo ""
877 # Install package if requested
878 if [ "$inst" ]; then
879 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
880 cd $PKGS && tazpkg install \
881 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
882 else
883 gettext -e "Unable to install package, build has failed.\n\n"
884 exit 1
885 fi
886 fi
887 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
888 # You want automation: use the Cooker Build Bot.
889 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
890 rm -f $command ;;
891 esac
893 exit 0