cookutils view cook @ rev 119

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