cookutils view cook @ rev 145

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