cookutils view cook @ rev 178

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