cookutils view cook @ rev 121

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