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