cookutils view cook @ rev 207

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