cookutils view cook @ rev 172

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