cookutils view cook @ rev 126

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