cookutils view cook @ rev 135

cook: avoid error if no previews package
author Christophe Lincoln <pankso@slitaz.org>
date Wed May 11 03:34:21 2011 +0200 (2011-05-11)
parents aa0dfb561078
children c83f48dace63
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 i in $dep $implicit
407 do
408 if [ ! -f "$INSTALLED/$i/receipt" ]; then
409 # Try local package first.
410 vers=$(grep ^VERSION $WOK/$i/receipt | cut -d '"' -f 2)
411 if [ -f "$PKGS/$i-$vers.tazpkg" ]; then
412 gettext "Installing dep (pkg/local):"; echo " $i"
413 cd $PKGS && tazpkg install $i-$vers.tazpkg >/dev/null
414 else
415 gettext "Installing dep (web/cache):"; echo " $i"
416 tazpkg get-install $i >/dev/null
417 fi
418 fi
419 done
420 done
421 cd $INSTALLED && 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 # Ls sort by name so the first file is the one we want.
579 old=$(ls $PKGS/$pkg-*.tazpkg | head -n 1 2>/dev/null)
580 status
581 [ "$old" ] && echo -n "Removing old: $(basename $old)" && \
582 rm -f $old && status
583 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
584 sed -i /^${pkg}$/d $broken
585 fi
586 }
588 #
589 # Commands
590 #
592 case "$1" in
593 usage|help|-u|-h)
594 usage ;;
595 list-wok)
596 gettext -e "\nList of packages in:"; echo " $WOK"
597 separator
598 cd $WOK && ls -1
599 separator
600 echo -n "Packages: " && ls | wc -l
601 echo "" ;;
602 search)
603 # Just a simple search function, we dont need more actually.
604 query="$2"
605 gettext -e "\nSearch results for:"; echo " $query"
606 separator
607 cd $WOK && ls -1 | grep "$query"
608 separator && echo "" ;;
609 setup)
610 # Setup a build environment
611 check_root
612 echo "Cook: setting up the environment" | log
613 gettext -e "\nSetting up your environment\n"
614 separator && cd $SLITAZ
615 init_db_files
616 gettext -e "Checking for packages to install...\n"
617 for pkg in $SETUP_PKGS
618 do
619 [ ! -f "$INSTALLED/$pkg/receipt" ] && tazpkg get-install $pkg
620 done
622 # Handle --options
623 case "$2" in
624 --wok|-w)
625 [ ! -f "$INSTALLED/mercurial/receipt" ] && \
626 tazpkg get-install mercurial
627 [ -d "$WOK" ] && echo -e "A wok already exists.\n" && exit 1
628 hg clone $HG_URL ;;
629 esac
631 # SliTaz group and permissions
632 if ! grep -q ^slitaz /etc/group; then
633 gettext -e "Adding group: slitaz\n"
634 addgroup slitaz
635 fi
636 gettext -e "Setting permissions for slitaz group...\n"
637 chown -R root.slitaz $SLITAZ
638 chmod -R g+w $SLITAZ
639 separator
640 gettext -e "All done, ready to cook packages :-)\n\n" ;;
641 test)
642 # Test a cook environment.
643 echo "Cook test: testing the cook environment" | log
644 [ ! -d "$WOK" ] && exit 1
645 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
646 cook cooktest ;;
647 new)
648 # Create the package folder and an empty receipt.
649 pkg="$2"
650 [ "$pkg" ] || usage
651 [ -d "${WOK}-hg" ] && WOK=${WOK}-hg
652 echo ""
653 if [ -d "$WOK/$pkg" ]; then
654 echo -n "$pkg " && gettext "package already exists."
655 echo -e "\n" && exit 1
656 fi
657 gettext "Creating"; echo -n " $WOK/$pkg"
658 mkdir $WOK/$pkg && cd $WOK/$pkg && status
659 gettext "Preparing the package receipt..."
660 cp $DATA/receipt .
661 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
662 status && echo "" ;;
663 list)
664 # Cook a list of packages (better use the Cooker since it will order
665 # packages before executing cook).
666 check_root
667 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
668 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
669 echo -e " $2\n" && exit 1
670 echo "Cook list starting: $2" | log
671 for pkg in $(cat $2)
672 do
673 cook $pkg || broken
674 done ;;
675 clean-wok)
676 check_root
677 gettext -e "\nCleaning all packages files..."
678 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
679 status && echo "" ;;
680 clean-src)
681 check_root
682 gettext -e "\nCleaning all packages sources..."
683 rm -rf $WOK/*/source
684 status && echo "" ;;
685 pkglist)
686 # Create suitable packages list for TazPKG and only for built packages.
687 [ "$2" ] && PKGS="$2"
688 [ ! -d "$PKGS" ] && \
689 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1
690 echo "cook:pkglist" > $command
691 echo "Cook pkglist: Creating all packages lists" | log
692 gettext -e "\nCreating lists for:"; echo " $PKGS"
693 separator
694 cd $PKGS
695 rm -f packages.* files.list*
696 gettext -e "Creating: packages.list\n"
697 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
698 gettext -e "Creating: packages.md5\n"
699 md5sum *.tazpkg > $PKGS/packages.md5
700 gettext -e "Creating: packages.desc\n"
701 gettext -e "Creating: packages.equiv\n"
702 cd $WOK
703 for pkg in *
704 do
705 unset_receipt
706 . $pkg/receipt
707 # packages.desc let us search easily in DB
708 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
709 cat >> $PKGS/packages.desc << EOT
710 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
711 EOT
712 # Packages.equiv is used by tazpkg install to check depends.
713 for i in $PROVIDE; do
714 DEST=""
715 echo $i | fgrep -q : && DEST="${i#*:}:"
716 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
717 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
718 $PKGS/packages.equiv
719 else
720 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
721 fi
722 done
723 fi
724 done
725 # files.list.lzma
726 #lzma e files.list files.list.lzma
727 separator
728 nb=$(ls $PKGS/*.tazpkg | wc -l)
729 echo -e "Packages: $nb\n"
730 rm -f $command ;;
731 *)
732 # Just cook and generate a package.
733 check_root
734 time=$(date +%s)
735 pkg="$1"
736 [ -z "$pkg" ] && usage
737 receipt="$WOK/$pkg/receipt"
738 check_pkg_in_wok && echo ""
740 # Display and log info if cook process stopped.
741 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
742 tee -a $LOGS/$pkg.log' INT
744 # Skip blocked, 3 lines also for the Cooker.
745 if grep -q "^$pkg$" $blocked && [ "$2" != "--*" ]; then
746 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
747 fi
749 # Log and source receipt.
750 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
751 echo "cook:$pkg" > $command
752 unset inst
753 unset_receipt
754 . $receipt
756 # Handle --options
757 case "$2" in
758 --clean|-c)
759 gettext -e "Cleaning:"; echo -n " $pkg"
760 cd $WOK/$pkg && rm -rf install taz source
761 status && echo "" && exit 0 ;;
762 --install|-i)
763 inst='yes' ;;
764 --getsrc|-gs)
765 gettext "Getting source for:"; echo " $pkg"
766 separator && get_source
767 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
768 --block|-b)
769 gettext "Blocking:"; echo -n " $pkg"
770 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
771 status && echo "" && exit 0 ;;
772 --unblock|-ub)
773 gettext "Unblocking:"; echo -n " $pkg"
774 sed -i "/^${pkg}$/"d $blocked
775 status && echo "" && exit 0 ;;
776 esac
778 # Check if wanted is built now so we have separate log files.
779 if [ "$WANTED" ] && [ ! -d "$WOK/$WANTED/install" ]; then
780 cook "$WANTED"
781 fi
783 # Cook and pack or exit on error and log everything.
784 cookit $@ 2>&1 | tee $LOGS/$pkg.log
785 remove_deps | tee -a $LOGS/$pkg.log
786 cookit_quality
787 packit 2>&1 | tee -a $LOGS/$pkg.log
788 clean_log
790 # Exit if any error in packing.
791 if grep -q ^ERROR $LOGS/$pkg.log; then
792 debug_info | tee -a $LOGS/$pkg.log
793 rm -f $command && exit 1
794 fi
796 # Time and summary
797 time=$(($(date +%s) - $time))
798 summary | tee -a $LOGS/$pkg.log
799 echo ""
801 # Install package if requested
802 if [ "$inst" ]; then
803 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
804 cd $PKGS && tazpkg install \
805 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
806 else
807 gettext -e "Unable to install package, build has failed.\n\n"
808 exit 1
809 fi
810 fi
811 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
812 # You want automation: use the Cooker Build Bot.
813 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
814 rm -f $command ;;
815 esac
817 exit 0