cookutils view cook @ rev 191

cook: add file support (Thanks Godane)
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 20 20:23:05 2011 +0200 (2011-05-20)
parents 029e2d5bbfc7
children bb96f5903b92
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 *) cp $SRC/$TARBALL $(pwd) ;;
275 esac
276 }
278 # Display cooked package summary.
279 summary() {
280 cd $WOK/$pkg
281 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
282 fs=$(du -sh taz/* | awk '{print $1}')
283 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
284 files=$(cat taz/$pkg-*/files.list | wc -l)
285 cookdate=$(date "+%Y-%m-%d %H:%M")
286 sec=$time
287 div=$(($time / 60))
288 [ "$div" != 0 ] && min="~ ${div}m"
289 gettext "Summary for:"; echo " $PACKAGE $VERSION"
290 separator
291 [ "$prod" ] && echo "Produced : $prod"
292 cat << EOT
293 Packed : $fs
294 Compressed : $size
295 Files : $files
296 Cook time : ${sec}s $min
297 Cook date : $cookdate
298 $(separator)
299 EOT
300 }
302 # Display debugging error info.
303 debug_info() {
304 echo -e "\nDebug information"
305 separator
306 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
307 for error in \
308 ERROR "No package" "cp: can't" "can't open" "can't cd" \
309 "error:" "fatal error:"
310 do
311 fgrep "$error" $LOGS/$pkg.log
312 done
313 separator && echo ""
314 }
316 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
317 # so some packages need to copy these files with the receipt and genpkg_rules.
318 copy_generic_files()
319 {
320 # $LOCALE is set in cook.conf
321 if [ "$LOCALE" ]; then
322 if [ -d "$_pkg/usr/share/locale" ]; then
323 mkdir -p $fs/usr/share/locale
324 for i in $LOCALE
325 do
326 if [ -d "$_pkg/usr/share/locale/$i" ]; then
327 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
328 fi
329 done
330 fi
331 fi
333 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
334 if [ "$GENERIC_PIXMAPS" != "no" ]; then
335 if [ -d "$_pkg/usr/share/pixmaps" ]; then
336 mkdir -p $fs/usr/share/pixmaps
337 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
338 $fs/usr/share/pixmaps 2>/dev/null
339 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
340 $fs/usr/share/pixmaps 2>/dev/null
341 fi
343 # Custom or homemade PNG pixmap can be in stuff.
344 if [ -f "$stuff/$PACKAGE.png" ]; then
345 mkdir -p $fs/usr/share/pixmaps
346 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
347 fi
348 fi
350 # Desktop entry (.desktop).
351 if [ -d "$_pkg/usr/share/applications" ]; then
352 cp -a $_pkg/usr/share/applications $fs/usr/share
353 fi
355 # Homemade desktop file(s) can be in stuff.
356 if [ -d "$stuff/applications" ]; then
357 mkdir -p $fs/usr/share
358 cp -a $stuff/applications $fs/usr/share
359 fi
360 if [ -f "$stuff/$PACKAGE.desktop" ]; then
361 mkdir -p $fs/usr/share/applications
362 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
363 fi
364 }
366 # Find and strip : --strip-all (-s) or --strip-debug on static libs as well
367 # as removing uneeded files like in Python packages.
368 strip_package()
369 {
370 gettext "Executing strip on all files..."
371 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
372 do
373 if [ -d "$dir" ]; then
374 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
375 fi
376 done
377 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
378 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
379 status
381 # Remove Python .pyc and .pyo from packages.
382 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
383 gettext "Removing Python compiled files..."
384 find $fs -type f -name "*.pyc" -delete 2>/dev/null
385 find $fs -type f -name "*.pyo" -delete 2>/dev/null
386 status
387 fi
389 # Remove Perl perllocal.pod and .packlist from packages.
390 if echo "$DEPENDS" | fgrep -q "perl"; then
391 gettext "Removing Perl compiled files..."
392 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
393 find $fs -type f -name ".packlist" -delete 2>/dev/null
394 status
395 fi
396 }
398 # Remove installed deps.
399 remove_deps() {
400 # Now remove installed build deps.
401 diff="$CACHE/installed.cook.diff"
402 if [ -s "$CACHE/installed.cook.diff" ]; then
403 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
404 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
405 gettext "Build dependencies to remove:"; echo " $nb"
406 gettext "Removing:"
407 for dep in $deps
408 do
409 echo -n " $dep"
410 yes | tazpkg remove $dep >/dev/null
411 done
412 echo -e "\n"
413 # Keep the last diff for debug and info.
414 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
415 fi
416 }
418 # The main cook function.
419 cookit() {
420 echo "Cook: $PACKAGE $VERSION"
421 separator
422 set_paths
423 [ "$QA" ] && receipt_quality
424 cd $pkgdir
425 rm -rf install taz source
427 # Disable -pipe if less than 512Mb free RAM.
428 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
429 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
430 gettext -e "Disabling -pipe compile flag: $free RAM\n"
431 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
432 CXXFLAGS="${CXXFLAGS/-pipe}" && \
433 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
434 fi
435 unset free
437 # Export flags and path to be used by make
438 DESTDIR=$pkgdir/install
439 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS BUILD_HOST CONFIG_SITE
440 local LC_ALL=POSIX LANG=POSIX
442 # Check for build deps and handle implicit depends of *-dev packages
443 # (ex: libusb-dev :: libusb).
444 cd $INSTALLED && ls -1 > $CACHE/installed.list
445 [ "$DEPENDS" ] && gettext -e "Checking build dependencies...\n"
446 for dep in $BUILD_DEPENDS
447 do
448 implicit=${dep%-dev}
449 for i in $dep $implicit
450 do
451 if [ ! -f "$INSTALLED/$i/receipt" ]; then
452 # Try local package first. In some cases implicit doesn't exist, ex:
453 # libboost-dev exists but not libboost, so check if we got vers.
454 unset vers
455 vers=$(grep ^VERSION $WOK/$i/receipt 2>/dev/null | cut -d '"' -f 2)
456 if [ -f "$PKGS/$i-$vers.tazpkg" ]; then
457 gettext "Installing dep (pkg/local):"; echo " $i"
458 cd $PKGS && tazpkg install $i-$vers.tazpkg >/dev/null
459 else
460 if [ "$vers" ]; then
461 gettext "Installing dep (web/cache):"; echo " $i"
462 tazpkg get-install $i >/dev/null
463 fi
464 fi
465 fi
466 done
467 done
468 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
470 # If a cook failed deps are not removed since we exit 1.
471 [ ! -s "installed.cook.diff" ] && \
472 busybox diff installed.list installed.cook > installed.cook.diff
473 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
475 # Get source tarball and make sure we have source dir named:
476 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
477 # tarball if it exists.
478 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
479 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
480 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
481 LZMA_SRC=""
482 else
483 get_source || exit 1
484 fi
485 fi
486 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
487 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
488 extract_source || exit 1
489 if [ "$LZMA_SRC" ]; then
490 cd $pkgdir/source
491 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
492 mv tmp tmp-1 && mkdir tmp
493 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
494 fi
495 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
496 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
497 fi
498 fi
499 cd $pkgdir/source/tmp
500 # Some archives are not well done and don't extract to one dir (ex lzma).
501 files=$(ls | wc -l)
502 [ "$files" == 1 ] && mv * ../$PACKAGE-$VERSION
503 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
504 mv * ../$PACKAGE-$VERSION
505 cd .. && rm -rf tmp
506 fi
508 # Execute receipt rules.
509 if grep -q ^compile_rules $receipt; then
510 gettext -e "Executing: compile_rules\n"
511 [ -d "$src" ] && cd $src
512 compile_rules $@ || exit 1
513 # Stay compatible with _pkg
514 [ -d "$src/_pkg" ] && mv $src/_pkg $install
515 # QA: compile_rules success so valid.
516 mkdir -p $install
517 else
518 # QA: No compile_rules so no error, valid.
519 mkdir -p $install
520 fi
521 separator && echo ""
522 }
524 # Cook quality assurance.
525 cookit_quality() {
526 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
527 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
528 fi
529 # ERROR can be echoed any time in cookit()
530 if fgrep -q ERROR: $LOGS/$pkg.log; then
531 debug_info | tee -a $LOGS/$pkg.log
532 rm -f $command && exit 1
533 fi
534 }
536 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
537 # but it doesn't handle EXTRAVERSION.
538 packit() {
539 set_paths
540 echo "Pack: $PACKAGE $VERSION"
541 separator
542 if grep -q ^genpkg_rules $receipt; then
543 gettext -e "Executing: genpkg_rules\n"
544 cd $pkgdir
545 mkdir -p $fs && ( set -e; genpkg_rules ) || echo -e \
546 "\nERROR: genpkg_rules failed\n" >> $LOGS/$pkg.log
547 fi
549 # First QA check to stop now if genpkg_rules failed.
550 if fgrep -q ERROR: $LOGS/$pkg.log; then
551 exit 1
552 fi
554 cd $taz
555 for file in receipt description.txt
556 do
557 [ ! -f "../$file" ] && continue
558 gettext "Copying"; echo -n " $file..."
559 cp -f ../$file $pack && chown 0.0 $pack/$file && status
560 done
561 copy_generic_files
563 # Create files.list with redirecting find output.
564 gettext "Creating the list of files..." && cd $fs
565 find . -type f -print > ../files.list
566 find . -type l -print >> ../files.list
567 cd .. && sed -i s/'^.'/''/ files.list
568 status
570 # Strip and stuff files.
571 strip_package
573 # Md5sum of files.
574 gettext "Creating md5sum of files..."
575 while read file; do
576 [ -L "fs$file" ] && continue
577 [ -f "fs$file" ] || continue
578 case "$file" in
579 /lib/modules/*/modules.*|*.pyc) continue;;
580 esac
581 md5sum "fs$file" | sed 's/ fs/ /'
582 done < files.list > md5sum
583 status
584 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
585 description.txt 2> /dev/null | awk \
586 '{ sz=$1 } END { print sz }')
588 # Build cpio archives.
589 gettext "Compressing the fs... "
590 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
591 rm -rf fs
592 status
593 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
594 md5sum description.txt 2> /dev/null | awk \
595 '{ sz=$1 } END { print sz }')
596 gettext "Updating receipt sizes..."
597 sed -i s/^PACKED_SIZE.*$// receipt
598 sed -i s/^UNPACKED_SIZE.*$// receipt
599 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
600 status
602 # Set extra version.
603 if [ "$EXTRAVERSION" ]; then
604 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
605 sed -i s/^EXTRAVERSION.*$// receipt
606 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
607 status
608 fi
610 # Compress.
611 gettext "Creating full cpio archive... "
612 find . -print | cpio -o -H newc --quiet > \
613 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
614 status
615 gettext "Restoring original package tree... "
616 unlzma -c fs.cpio.lzma | cpio -idm --quiet
617 status
618 rm fs.cpio.lzma && cd ..
620 # QA and give info.
621 tazpkg=$(ls *.tazpkg)
622 packit_quality
623 separator && gettext "Package:"; echo -e " $tazpkg\n"
624 }
626 # Verify package quality and consistency.
627 packit_quality() {
628 #gettext "QA: Checking for broken link..."
629 #link=$(find $fs/usr -type l -follow)
630 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
631 #status
633 # Exit if any error found in log file.
634 if fgrep -q ERROR: $LOGS/$pkg.log; then
635 rm -f $command && exit 1
636 fi
638 gettext "QA: Checking for empty package..."
639 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
640 if [ "$files" -lt 0 ] && [ "$CATEGORY" != "meta" ]; then
641 echo -e "\nERROR: empty package"
642 rm -f $command && exit 1
643 else
644 # Ls sort by name so the first file is the one we want.
645 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
646 status
647 if [ -f "$old" ]; then
648 echo -n "Removing old: $(basename $old)"
649 rm -f $old && status
650 fi
651 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
652 sed -i /^${pkg}$/d $broken
653 fi
654 }
656 #
657 # Commands
658 #
660 case "$1" in
661 usage|help|-u|-h)
662 usage ;;
663 list-wok)
664 gettext -e "\nList of packages in:"; echo " $WOK"
665 separator
666 cd $WOK && ls -1
667 separator
668 echo -n "Packages: " && ls | wc -l
669 echo "" ;;
670 search)
671 # Just a simple search function, we dont need more actually.
672 query="$2"
673 gettext -e "\nSearch results for:"; echo " $query"
674 separator
675 cd $WOK && ls -1 | grep "$query"
676 separator && echo "" ;;
677 setup)
678 # Setup a build environment
679 check_root
680 echo "Cook: setting up the environment" | log
681 gettext -e "\nSetting up your environment\n"
682 separator && cd $SLITAZ
683 init_db_files
684 gettext -e "Checking for packages to install...\n"
685 for pkg in $SETUP_PKGS
686 do
687 [ ! -f "$INSTALLED/$pkg/receipt" ] && tazpkg get-install $pkg
688 done
690 # Handle --options
691 case "$2" in
692 --wok|-w)
693 [ ! -f "$INSTALLED/mercurial/receipt" ] && \
694 tazpkg get-install mercurial
695 [ -d "$WOK" ] && echo -e "A wok already exists.\n" && exit 1
696 hg clone $WOK_URL ;;
697 esac
699 # SliTaz group and permissions
700 if ! grep -q ^slitaz /etc/group; then
701 gettext -e "Adding group: slitaz\n"
702 addgroup slitaz
703 fi
704 gettext -e "Setting permissions for slitaz group...\n"
705 chown -R root.slitaz $SLITAZ
706 chmod -R g+w $SLITAZ
707 separator
708 gettext -e "All done, ready to cook packages :-)\n\n" ;;
709 test)
710 # Test a cook environment.
711 echo "Cook test: testing the cook environment" | log
712 [ ! -d "$WOK" ] && exit 1
713 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
714 cook cooktest ;;
715 new)
716 # Create the package folder and an empty receipt.
717 pkg="$2"
718 [ "$pkg" ] || usage
719 echo ""
720 if [ -d "$WOK/$pkg" ]; then
721 echo -n "$pkg " && gettext "package already exists."
722 echo -e "\n" && exit 1
723 fi
724 gettext "Creating"; echo -n " $WOK/$pkg"
725 mkdir $WOK/$pkg && cd $WOK/$pkg && status
726 gettext "Preparing the package receipt..."
727 cp $DATA/receipt .
728 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
729 status && echo "" ;;
730 list)
731 # Cook a list of packages (better use the Cooker since it will order
732 # packages before executing cook).
733 check_root
734 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
735 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
736 echo -e " $2\n" && exit 1
737 echo "Cook list starting: $2" | log
738 for pkg in $(cat $2)
739 do
740 cook $pkg || broken
741 done ;;
742 clean-wok)
743 check_root
744 gettext -e "\nCleaning all packages files..."
745 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
746 status && echo "" ;;
747 clean-src)
748 check_root
749 gettext -e "\nCleaning all packages sources..."
750 rm -rf $WOK/*/source
751 status && echo "" ;;
752 pkglist)
753 # Create suitable packages list for TazPKG and only for built packages.
754 [ "$2" ] && PKGS="$2"
755 [ ! -d "$PKGS" ] && \
756 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1
757 echo "cook:pkglist" > $command
758 echo "Cook pkglist: Creating all packages lists" | log
759 gettext -e "\nCreating lists for:"; echo " $PKGS"
760 separator
761 cd $PKGS
762 rm -f packages.* files.*
763 gettext -e "Creating: packages.list\n"
764 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
765 gettext -e "Creating: packages.md5\n"
766 md5sum *.tazpkg > $PKGS/packages.md5
767 gettext -e "Creating: packages.desc\n"
768 gettext -e "Creating: packages.equiv\n"
769 cd $WOK
770 for pkg in *
771 do
772 unset_receipt
773 . $pkg/receipt
774 # packages.desc lets us search easily in DB
775 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
776 cat >> $PKGS/packages.desc << EOT
777 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
778 EOT
779 # Packages.equiv is used by tazpkg install to check depends.
780 for i in $PROVIDE; do
781 DEST=""
782 echo $i | fgrep -q : && DEST="${i#*:}:"
783 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
784 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
785 $PKGS/packages.equiv
786 else
787 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
788 fi
789 done
790 fi
791 done
792 cd $PKGS
794 # packages.txt (redundancy list, all info is in pkgs desc).
795 touch packages.txt
797 # files.list.lzma
798 gettext -e "Creating: files.list.lzma\n"
799 touch files.list
800 lzma e files.list files.list.lzma
802 separator
803 nb=$(ls $PKGS/*.tazpkg | wc -l)
804 echo -e "Packages: $nb\n"
805 rm -f $command ;;
806 *)
807 # Just cook and generate a package.
808 check_root
809 time=$(date +%s)
810 pkg="$1"
811 [ -z "$pkg" ] && usage
812 receipt="$WOK/$pkg/receipt"
813 check_pkg_in_wok && echo ""
815 # Display and log info if cook process stopped.
816 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
817 tee -a $LOGS/$pkg.log' INT
819 # Skip blocked, 3 lines also for the Cooker.
820 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
821 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
822 fi
824 # Log and source receipt.
825 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
826 echo "cook:$pkg" > $command
827 unset inst
828 unset_receipt
829 . $receipt
831 # Handle --options
832 case "$2" in
833 --clean|-c)
834 gettext -e "Cleaning:"; echo -n " $pkg"
835 cd $WOK/$pkg && rm -rf install taz source
836 status && echo "" && exit 0 ;;
837 --install|-i)
838 inst='yes' ;;
839 --getsrc|-gs)
840 gettext "Getting source for:"; echo " $pkg"
841 separator && get_source
842 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
843 --block|-b)
844 gettext "Blocking:"; echo -n " $pkg"
845 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
846 status && echo "" && exit 0 ;;
847 --unblock|-ub)
848 gettext "Unblocking:"; echo -n " $pkg"
849 sed -i "/^${pkg}$/"d $blocked
850 status && echo "" && exit 0 ;;
851 esac
853 # Check if wanted is built now so we have separate log files.
854 if [ "$WANTED" ] && [ ! -d "$WOK/$WANTED/install" ]; then
855 if ! grep -q "^$WANTED$" $broken; then
856 cook "$WANTED"
857 fi
858 fi
860 # Cook and pack or exit on error and log everything.
861 cookit $@ 2>&1 | tee $LOGS/$pkg.log
862 remove_deps | tee -a $LOGS/$pkg.log
863 cookit_quality
864 packit 2>&1 | tee -a $LOGS/$pkg.log
865 clean_log
867 # Exit if any error in packing.
868 if grep -q ^ERROR $LOGS/$pkg.log; then
869 debug_info | tee -a $LOGS/$pkg.log
870 rm -f $command && exit 1
871 fi
873 # Time and summary
874 time=$(($(date +%s) - $time))
875 summary | tee -a $LOGS/$pkg.log
876 echo ""
878 # Install package if requested
879 if [ "$inst" ]; then
880 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
881 cd $PKGS && tazpkg install \
882 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
883 else
884 gettext -e "Unable to install package, build has failed.\n\n"
885 exit 1
886 fi
887 fi
888 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
889 # You want automation: use the Cooker Build Bot.
890 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
891 rm -f $command ;;
892 esac
894 exit 0