cookutils view cook @ rev 170

log removed packages
author Christophe Lincoln <pankso@slitaz.org>
date Mon May 16 15:36:42 2011 +0200 (2011-05-16)
parents 6f2181852647
children 18a92a268c5c
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 if [ "$LZMA_SRC" ]; then
178 tar -c $pkgsrc | lzma e $SRC/$tarball -si || exit 1
179 else
180 tar cjf $tarball $pkgsrc || exit 1
181 mv $tarball $SRC && rm -rf $pkgsrc
182 fi
183 }
185 # Get package source. For SCM we are in cache so clone here and create a
186 # tarball here.
187 get_source() {
188 pwd=$(pwd)
189 pkgsrc=${SOURCE:-$PACKAGE}-$VERSION
190 tarball=$pkgsrc.tar.bz2
191 [ "$LZMA_SRC" ] && tarball=$pkgsrc.tar.lzma
192 case "$WGET_URL" in
193 http://*|ftp://*)
194 # Busybox Wget is better!
195 busybox wget -c -P $SRC $WGET_URL || \
196 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
197 https://*)
198 wget -c --no-check-certificate -P $SRC $WGET_URL || \
199 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
200 hg*|mercurial*)
201 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
202 url=${WGET_URL#hg|}
203 else
204 url=${WGET_URL#mercurial|}
205 fi
206 gettext -e "Getting source from Hg...\n"
207 echo "URL: $url"
208 gettext "Cloning to: "; echo "$pwd/$pkgsrc"
209 hg clone $url $pkgsrc || (echo "ERROR: hg clone $url" && exit 1)
210 create_tarball ;;
211 git*)
212 url=${WGET_URL#git|}
213 gettext -e "Getting source from Git...\n"
214 echo "URL: $url"
215 git clone $url $pkgsrc || (echo "ERROR: git clone $url" && exit 1)
216 if [ "$BRANCH" ]; then
217 echo "Git branch: $BRANCH"
218 cd $pkgsrc && git checkout $BRANCH && cd ..
219 fi
220 create_tarball ;;
221 cvs*)
222 url=${WGET_URL#cvs|}
223 mod=$PACKAGE
224 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
225 gettext -e "Getting source from CVS...\n"
226 echo "URL: $url"
227 [ "$CVS_MODULE" ] && echo "CVS module: $mod"
228 gettext "Cloning to: "; echo "$pwd/$mod"
229 cvs -d:$url co $mod && mv $mod $pkgsrc
230 create_tarball ;;
231 svn*|subversion*)
232 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
233 url=${WGET_URL#svn|}
234 else
235 url=${WGET_URL#subversion|}
236 fi
237 gettext -e "Getting source from SVN...\n"
238 echo "URL: $url"
239 if [ "$BRANCH" ]; then
240 echo t | svn co $url -r $BRANCH $pkgsrc
241 else
242 echo t | svn co $url $pkgsrc
243 fi
244 create_tarball ;;
245 *)
246 gettext -e "\nERROR: Unable to handle:"; echo -e " $WGET_URL \n" | \
247 tee -a $LOGS/$PACKAGE.log
248 exit 1 ;;
249 esac
250 }
252 # Extract source package.
253 extract_source() {
254 gettext "Extracting:"; echo " $TARBALL"
255 case "$TARBALL" in
256 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
257 *.tar.bz2|*.tbz) tar xjf $SRC/$TARBALL 2>/dev/null ;;
258 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
259 *.tar) tar xf $SRC/$TARBALL ;;
260 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
261 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
262 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
263 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
264 esac
265 }
267 # Display cooked package summary.
268 summary() {
269 cd $WOK/$pkg
270 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
271 fs=$(du -sh taz/* | awk '{print $1}')
272 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
273 files=$(cat taz/$pkg-*/files.list | wc -l)
274 cookdate=$(date "+%Y-%m-%d %H:%M")
275 sec=$time
276 div=$(($time / 60))
277 [ "$div" != 0 ] && min="~ ${div}m"
278 gettext "Summary for:"; echo " $PACKAGE $VERSION"
279 separator
280 [ "$prod" ] && echo "Produced : $prod"
281 cat << EOT
282 Packed : $fs
283 Compressed : $size
284 Files : $files
285 Cook time : ${sec}s $min
286 Cook date : $cookdate
287 $(separator)
288 EOT
289 }
291 # Display debugging error info.
292 debug_info() {
293 echo -e "\nDebug information"
294 separator
295 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
296 for error in \
297 ERROR "No package" "cp: can't" "can't open" "can't cd" \
298 "error:" "fatal error:"
299 do
300 fgrep "$error" $LOGS/$pkg.log
301 done
302 separator && echo ""
303 }
305 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
306 # so some packages need to copy these files with the receipt and genpkg_rules.
307 copy_generic_files()
308 {
309 # $LOCALE is set in cook.conf
310 if [ "$LOCALE" ]; then
311 if [ -d "$_pkg/usr/share/locale" ]; then
312 mkdir -p $fs/usr/share/locale
313 for i in $LOCALE
314 do
315 if [ -d "$_pkg/usr/share/locale/$i" ]; then
316 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
317 fi
318 done
319 fi
320 fi
322 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
323 if [ "$GENERIC_PIXMAPS" != "no" ]; then
324 if [ -d "$_pkg/usr/share/pixmaps" ]; then
325 mkdir -p $fs/usr/share/pixmaps
326 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
327 $fs/usr/share/pixmaps 2>/dev/null
328 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
329 $fs/usr/share/pixmaps 2>/dev/null
330 fi
332 # Custom or homemade PNG pixmap can be in stuff.
333 if [ -f "$stuff/$PACKAGE.png" ]; then
334 mkdir -p $fs/usr/share/pixmaps
335 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
336 fi
337 fi
339 # Desktop entry (.desktop).
340 if [ -d "$_pkg/usr/share/applications" ]; then
341 cp -a $_pkg/usr/share/applications $fs/usr/share
342 fi
344 # Homemade desktop file(s) can be in stuff.
345 if [ -d "$stuff/applications" ]; then
346 mkdir -p $fs/usr/share
347 cp -a $stuff/applications $fs/usr/share
348 fi
349 if [ -f "$stuff/$PACKAGE.desktop" ]; then
350 mkdir -p $fs/usr/share/applications
351 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
352 fi
353 }
355 # Find and strip : --strip-all (-s) or --strip-debug on static libs as well
356 # as removing uneeded files like in Python packages.
357 strip_package()
358 {
359 gettext "Executing strip on all files..."
360 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
361 do
362 if [ -d "$dir" ]; then
363 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
364 fi
365 done
366 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
367 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
368 status
370 # Remove Python .pyc and .pyo from packages.
371 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
372 gettext "Removing Python compiled files..."
373 find $fs -type f -name "*.pyc" -delete 2>/dev/null
374 find $fs -type f -name "*.pyo" -delete 2>/dev/null
375 status
376 fi
378 # Remove Perl perllocal.pod and .packlist from packages.
379 if echo "$DEPENDS" | fgrep -q "perl"; then
380 gettext "Removing Perl compiled files..."
381 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
382 find $fs -type f -name ".packlist" -delete 2>/dev/null
383 status
384 fi
385 }
387 # Remove installed deps.
388 remove_deps() {
389 # Now remove installed build deps.
390 diff="$CACHE/installed.cook.diff"
391 if [ -s "$CACHE/installed.cook.diff" ]; then
392 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
393 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
394 gettext "Build dependencies to remove:"; echo " $nb"
395 gettext "Removing:"
396 for dep in $deps
397 do
398 echo -n " $dep"
399 yes | tazpkg remove $dep >/dev/null
400 done
401 echo -e "\n"
402 # Keep the last diff for debug and info.
403 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
404 fi
405 }
407 # The main cook function.
408 cookit() {
409 echo "Cook: $PACKAGE $VERSION"
410 separator
411 set_paths
412 [ "$QA" ] && receipt_quality
413 cd $pkgdir
414 rm -rf install taz source
416 # Disable -pipe if less than 512Mb free RAM.
417 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
418 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
419 gettext -e "Disabling -pipe compile flag: $free RAM\n"
420 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
421 CXXFLAGS="${CXXFLAGS/-pipe}" && \
422 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
423 fi
424 unset free
426 # Export flags and path to be used by make
427 DESTDIR=$pkgdir/install
428 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS BUILD_HOST CONFIG_SITE
429 local LC_ALL=POSIX LANG=POSIX
431 # Check for build deps and handle implicit depends of *-dev packages
432 # (ex: libusb-dev :: libusb).
433 cd $INSTALLED && ls -1 > $CACHE/installed.list
434 [ "$DEPENDS" ] && gettext -e "Checking build dependencies...\n"
435 for dep in $BUILD_DEPENDS
436 do
437 implicit=${dep%-dev}
438 for i in $dep $implicit
439 do
440 if [ ! -f "$INSTALLED/$i/receipt" ]; then
441 # Try local package first.
442 vers=$(grep ^VERSION $WOK/$i/receipt | cut -d '"' -f 2)
443 if [ -f "$PKGS/$i-$vers.tazpkg" ]; then
444 gettext "Installing dep (pkg/local):"; echo " $i"
445 cd $PKGS && tazpkg install $i-$vers.tazpkg >/dev/null
446 else
447 gettext "Installing dep (web/cache):"; echo " $i"
448 tazpkg get-install $i >/dev/null
449 fi
450 fi
451 done
452 done
453 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
455 # If a cook failed deps are not removed since we exit 1.
456 [ ! -s "installed.cook.diff" ] && \
457 busybox diff installed.list installed.cook > installed.cook.diff
458 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
460 # Get source tarball and make sure we have source dir named:
461 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
462 # tarball if it exists.
463 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
464 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
465 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
466 else
467 get_source || exit 1
468 fi
469 fi
470 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
471 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
472 extract_source || exit 1
473 # Some archives are not well done and don't extract to one dir (ex lzma).
474 files=$(ls | wc -l)
475 [ "$files" == 1 ] && mv * ../$PACKAGE-$VERSION
476 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
477 mv * ../$PACKAGE-$VERSION
478 cd .. && rm -rf tmp
479 fi
481 # Execute receipt rules.
482 if grep -q ^compile_rules $receipt; then
483 gettext -e "Executing: compile_rules\n"
484 [ -d "$src" ] && cd $src
485 compile_rules $@ || exit 1
486 # Stay compatible with _pkg
487 [ -d "$src/_pkg" ] && mv $src/_pkg $install
488 # QA: compile_rules success so valid.
489 mkdir -p $install
490 else
491 # QA: No compile_rules so no error, valid.
492 mkdir -p $install
493 fi
494 separator && echo ""
495 }
497 # Cook quality assurance.
498 cookit_quality() {
499 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
500 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
501 fi
502 # ERROR can be echoed any time in cookit()
503 if fgrep -q ERROR: $LOGS/$pkg.log; then
504 debug_info | tee -a $LOGS/$pkg.log
505 rm -f $command && exit 1
506 fi
507 }
509 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
510 # but it doesn't handle EXTRAVERSION.
511 packit() {
512 set_paths
513 echo "Pack: $PACKAGE $VERSION"
514 separator
515 if grep -q ^genpkg_rules $receipt; then
516 gettext -e "Executing: genpkg_rules\n"
517 cd $pkgdir
518 mkdir -p $fs && genpkg_rules || echo -e \
519 "\nERROR: genpkg_rules failed\n" >> $LOGS/$pkg.log
520 fi
522 # First QA check to stop now if genpkg_rules failed.
523 if fgrep -q ERROR: $LOGS/$pkg.log; then
524 exit 1
525 fi
527 cd $taz
528 for file in receipt description.txt
529 do
530 [ ! -f "../$file" ] && continue
531 gettext "Copying"; echo -n " $file..."
532 cp -f ../$file $pack && chown 0.0 $pack/$file && status
533 done
534 copy_generic_files
536 # Create files.list with redirecting find output.
537 gettext "Creating the list of files..." && cd $fs
538 find . -type f -print > ../files.list
539 find . -type l -print >> ../files.list
540 cd .. && sed -i s/'^.'/''/ files.list
541 status
543 # Strip and stuff files.
544 strip_package
546 # Md5sum of files.
547 gettext "Creating md5sum of files..."
548 while read file; do
549 [ -L "fs$file" ] && continue
550 [ -f "fs$file" ] || continue
551 case "$file" in
552 /lib/modules/*/modules.*|*.pyc) continue;;
553 esac
554 md5sum "fs$file" | sed 's/ fs/ /'
555 done < files.list > md5sum
556 status
557 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
558 description.txt 2> /dev/null | awk \
559 '{ sz=$1 } END { print sz }')
561 # Build cpio archives.
562 gettext "Compressing the fs... "
563 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
564 rm -rf fs
565 status
566 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
567 md5sum description.txt 2> /dev/null | awk \
568 '{ sz=$1 } END { print sz }')
569 gettext "Updating receipt sizes..."
570 sed -i s/^PACKED_SIZE.*$// receipt
571 sed -i s/^UNPACKED_SIZE.*$// receipt
572 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
573 status
575 # Set extra version.
576 if [ "$EXTRAVERSION" ]; then
577 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
578 sed -i s/^EXTRAVERSION.*$// receipt
579 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
580 status
581 fi
583 # Compress.
584 gettext "Creating full cpio archive... "
585 find . -print | cpio -o -H newc --quiet > \
586 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
587 status
588 gettext "Restoring original package tree... "
589 unlzma -c fs.cpio.lzma | cpio -idm --quiet
590 status
591 rm fs.cpio.lzma && cd ..
593 # QA and give info.
594 tazpkg=$(ls *.tazpkg)
595 packit_quality
596 separator && gettext "Package:"; echo -e " $tazpkg\n"
597 }
599 # Verify package quality and consistency.
600 packit_quality() {
601 #gettext "QA: Checking for broken link..."
602 #link=$(find $fs/usr -type l -follow)
603 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
604 #status
606 # Exit if any error found in log file.
607 if fgrep -q ERROR: $LOGS/$pkg.log; then
608 rm -f $command && exit 1
609 fi
611 gettext "QA: Checking for empty package..."
612 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
613 if [ "$files" -lt 0 ] && [ "$CATEGORY" != "meta" ]; then
614 echo -e "\nERROR: empty package"
615 rm -f $command && exit 1
616 else
617 # Ls sort by name so the first file is the one we want.
618 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
619 status
620 if [ -f "$old" ]; then
621 echo -n "Removing old: $(basename $old)"
622 rm -f $old && status
623 fi
624 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
625 sed -i /^${pkg}$/d $broken
626 fi
627 }
629 #
630 # Commands
631 #
633 case "$1" in
634 usage|help|-u|-h)
635 usage ;;
636 list-wok)
637 gettext -e "\nList of packages in:"; echo " $WOK"
638 separator
639 cd $WOK && ls -1
640 separator
641 echo -n "Packages: " && ls | wc -l
642 echo "" ;;
643 search)
644 # Just a simple search function, we dont need more actually.
645 query="$2"
646 gettext -e "\nSearch results for:"; echo " $query"
647 separator
648 cd $WOK && ls -1 | grep "$query"
649 separator && echo "" ;;
650 setup)
651 # Setup a build environment
652 check_root
653 echo "Cook: setting up the environment" | log
654 gettext -e "\nSetting up your environment\n"
655 separator && cd $SLITAZ
656 init_db_files
657 gettext -e "Checking for packages to install...\n"
658 for pkg in $SETUP_PKGS
659 do
660 [ ! -f "$INSTALLED/$pkg/receipt" ] && tazpkg get-install $pkg
661 done
663 # Handle --options
664 case "$2" in
665 --wok|-w)
666 [ ! -f "$INSTALLED/mercurial/receipt" ] && \
667 tazpkg get-install mercurial
668 [ -d "$WOK" ] && echo -e "A wok already exists.\n" && exit 1
669 hg clone $HG_URL ;;
670 esac
672 # SliTaz group and permissions
673 if ! grep -q ^slitaz /etc/group; then
674 gettext -e "Adding group: slitaz\n"
675 addgroup slitaz
676 fi
677 gettext -e "Setting permissions for slitaz group...\n"
678 chown -R root.slitaz $SLITAZ
679 chmod -R g+w $SLITAZ
680 separator
681 gettext -e "All done, ready to cook packages :-)\n\n" ;;
682 test)
683 # Test a cook environment.
684 echo "Cook test: testing the cook environment" | log
685 [ ! -d "$WOK" ] && exit 1
686 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
687 cook cooktest ;;
688 new)
689 # Create the package folder and an empty receipt.
690 pkg="$2"
691 [ "$pkg" ] || usage
692 echo ""
693 if [ -d "$WOK/$pkg" ]; then
694 echo -n "$pkg " && gettext "package already exists."
695 echo -e "\n" && exit 1
696 fi
697 gettext "Creating"; echo -n " $WOK/$pkg"
698 mkdir $WOK/$pkg && cd $WOK/$pkg && status
699 gettext "Preparing the package receipt..."
700 cp $DATA/receipt .
701 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
702 status && echo "" ;;
703 list)
704 # Cook a list of packages (better use the Cooker since it will order
705 # packages before executing cook).
706 check_root
707 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
708 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
709 echo -e " $2\n" && exit 1
710 echo "Cook list starting: $2" | log
711 for pkg in $(cat $2)
712 do
713 cook $pkg || broken
714 done ;;
715 clean-wok)
716 check_root
717 gettext -e "\nCleaning all packages files..."
718 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
719 status && echo "" ;;
720 clean-src)
721 check_root
722 gettext -e "\nCleaning all packages sources..."
723 rm -rf $WOK/*/source
724 status && echo "" ;;
725 pkglist)
726 # Create suitable packages list for TazPKG and only for built packages.
727 [ "$2" ] && PKGS="$2"
728 [ ! -d "$PKGS" ] && \
729 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1
730 echo "cook:pkglist" > $command
731 echo "Cook pkglist: Creating all packages lists" | log
732 gettext -e "\nCreating lists for:"; echo " $PKGS"
733 separator
734 cd $PKGS
735 rm -f packages.* files.*
736 gettext -e "Creating: packages.list\n"
737 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
738 gettext -e "Creating: packages.md5\n"
739 md5sum *.tazpkg > $PKGS/packages.md5
740 gettext -e "Creating: packages.desc\n"
741 gettext -e "Creating: packages.equiv\n"
742 cd $WOK
743 for pkg in *
744 do
745 unset_receipt
746 . $pkg/receipt
747 # packages.desc lets us search easily in DB
748 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
749 cat >> $PKGS/packages.desc << EOT
750 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
751 EOT
752 # Packages.equiv is used by tazpkg install to check depends.
753 for i in $PROVIDE; do
754 DEST=""
755 echo $i | fgrep -q : && DEST="${i#*:}:"
756 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
757 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
758 $PKGS/packages.equiv
759 else
760 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
761 fi
762 done
763 fi
764 done
765 cd $PKGS
767 # packages.txt (redundancy list, all info is in pkgs desc).
768 touch packages.txt
770 # files.list.lzma
771 gettext -e "Creating: files.list.lzma\n"
772 touch files.list
773 lzma e files.list files.list.lzma
775 separator
776 nb=$(ls $PKGS/*.tazpkg | wc -l)
777 echo -e "Packages: $nb\n"
778 rm -f $command ;;
779 *)
780 # Just cook and generate a package.
781 check_root
782 time=$(date +%s)
783 pkg="$1"
784 [ -z "$pkg" ] && usage
785 receipt="$WOK/$pkg/receipt"
786 check_pkg_in_wok && echo ""
788 # Display and log info if cook process stopped.
789 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
790 tee -a $LOGS/$pkg.log' INT
792 # Skip blocked, 3 lines also for the Cooker.
793 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
794 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
795 fi
797 # Log and source receipt.
798 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
799 echo "cook:$pkg" > $command
800 unset inst
801 unset_receipt
802 . $receipt
804 # Handle --options
805 case "$2" in
806 --clean|-c)
807 gettext -e "Cleaning:"; echo -n " $pkg"
808 cd $WOK/$pkg && rm -rf install taz source
809 status && echo "" && exit 0 ;;
810 --install|-i)
811 inst='yes' ;;
812 --getsrc|-gs)
813 gettext "Getting source for:"; echo " $pkg"
814 separator && get_source
815 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
816 --block|-b)
817 gettext "Blocking:"; echo -n " $pkg"
818 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
819 status && echo "" && exit 0 ;;
820 --unblock|-ub)
821 gettext "Unblocking:"; echo -n " $pkg"
822 sed -i "/^${pkg}$/"d $blocked
823 status && echo "" && exit 0 ;;
824 esac
826 # Check if wanted is built now so we have separate log files.
827 if [ "$WANTED" ] && [ ! -d "$WOK/$WANTED/install" ]; then
828 if ! grep -q "^$WANTED$" $broken; then
829 cook "$WANTED"
830 fi
831 fi
833 # Cook and pack or exit on error and log everything.
834 cookit $@ 2>&1 | tee $LOGS/$pkg.log
835 remove_deps | tee -a $LOGS/$pkg.log
836 cookit_quality
837 packit 2>&1 | tee -a $LOGS/$pkg.log
838 clean_log
840 # Exit if any error in packing.
841 if grep -q ^ERROR $LOGS/$pkg.log; then
842 debug_info | tee -a $LOGS/$pkg.log
843 rm -f $command && exit 1
844 fi
846 # Time and summary
847 time=$(($(date +%s) - $time))
848 summary | tee -a $LOGS/$pkg.log
849 echo ""
851 # Install package if requested
852 if [ "$inst" ]; then
853 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
854 cd $PKGS && tazpkg install \
855 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
856 else
857 gettext -e "Unable to install package, build has failed.\n\n"
858 exit 1
859 fi
860 fi
861 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
862 # You want automation: use the Cooker Build Bot.
863 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
864 rm -f $command ;;
865 esac
867 exit 0