cookutils view cook @ rev 146

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