cookutils view cook @ rev 229

cook: add support for *.run self executable scripts
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 27 02:20:23 2011 +0200 (2011-05-27)
parents 910c4b2ecaf7
children c93dd94cf8da
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|-x 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 *.run) /bin/sh $SRC/$TARBALL ;;
276 *) cp $SRC/$TARBALL $(pwd) ;;
277 esac
278 }
280 # Display cooked package summary.
281 summary() {
282 cd $WOK/$pkg
283 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
284 fs=$(du -sh taz/* | awk '{print $1}')
285 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
286 files=$(cat taz/$pkg-*/files.list | wc -l)
287 cookdate=$(date "+%Y-%m-%d %H:%M")
288 sec=$time
289 div=$(($time / 60))
290 [ "$div" != 0 ] && min="~ ${div}m"
291 gettext "Summary for:"; echo " $PACKAGE $VERSION"
292 separator
293 [ "$prod" ] && echo "Produced : $prod"
294 cat << EOT
295 Packed : $fs
296 Compressed : $size
297 Files : $files
298 Cook time : ${sec}s $min
299 Cook date : $cookdate
300 $(separator)
301 EOT
302 }
304 # Display debugging error info.
305 debug_info() {
306 echo -e "\nDebug information"
307 separator
308 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
309 for error in \
310 ERROR "No package" "cp: can't" "can't open" "can't cd" \
311 "error:" "fatal error:"
312 do
313 fgrep "$error" $LOGS/$pkg.log
314 done
315 separator && echo ""
316 }
318 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
319 # so some packages need to copy these files with the receipt and genpkg_rules.
320 copy_generic_files()
321 {
322 # $LOCALE is set in cook.conf
323 if [ "$LOCALE" ]; then
324 if [ -d "$_pkg/usr/share/locale" ]; then
325 mkdir -p $fs/usr/share/locale
326 for i in $LOCALE
327 do
328 if [ -d "$_pkg/usr/share/locale/$i" ]; then
329 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
330 fi
331 done
332 fi
333 fi
335 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
336 if [ "$GENERIC_PIXMAPS" != "no" ]; then
337 if [ -d "$_pkg/usr/share/pixmaps" ]; then
338 mkdir -p $fs/usr/share/pixmaps
339 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
340 $fs/usr/share/pixmaps 2>/dev/null
341 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
342 $fs/usr/share/pixmaps 2>/dev/null
343 fi
345 # Custom or homemade PNG pixmap can be in stuff.
346 if [ -f "$stuff/$PACKAGE.png" ]; then
347 mkdir -p $fs/usr/share/pixmaps
348 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
349 fi
350 fi
352 # Desktop entry (.desktop).
353 if [ -d "$_pkg/usr/share/applications" ]; then
354 cp -a $_pkg/usr/share/applications $fs/usr/share
355 fi
357 # Homemade desktop file(s) can be in stuff.
358 if [ -d "$stuff/applications" ]; then
359 mkdir -p $fs/usr/share
360 cp -a $stuff/applications $fs/usr/share
361 fi
362 if [ -f "$stuff/$PACKAGE.desktop" ]; then
363 mkdir -p $fs/usr/share/applications
364 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
365 fi
366 }
368 # Find and strip : --strip-all (-s) or --strip-debug on static libs as well
369 # as removing uneeded files like in Python packages.
370 strip_package()
371 {
372 gettext "Executing strip on all files..."
373 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
374 do
375 if [ -d "$dir" ]; then
376 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
377 fi
378 done
379 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
380 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
381 status
383 # Remove Python .pyc and .pyo from packages.
384 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
385 gettext "Removing Python compiled files..."
386 find $fs -type f -name "*.pyc" -delete 2>/dev/null
387 find $fs -type f -name "*.pyo" -delete 2>/dev/null
388 status
389 fi
391 # Remove Perl perllocal.pod and .packlist from packages.
392 if echo "$DEPENDS" | fgrep -q "perl"; then
393 gettext "Removing Perl compiled files..."
394 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
395 find $fs -type f -name ".packlist" -delete 2>/dev/null
396 status
397 fi
398 }
400 # Remove installed deps.
401 remove_deps() {
402 # Now remove installed build deps.
403 diff="$CACHE/installed.cook.diff"
404 if [ -s "$CACHE/installed.cook.diff" ]; then
405 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
406 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
407 gettext "Build dependencies to remove:"; echo " $nb"
408 gettext "Removing:"
409 for dep in $deps
410 do
411 echo -n " $dep"
412 echo 'y' | tazpkg remove $dep >/dev/null
413 done
414 echo -e "\n"
415 # Keep the last diff for debug and info.
416 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
417 fi
418 }
420 # The main cook function.
421 cookit() {
422 echo "Cook: $PACKAGE $VERSION"
423 separator
424 set_paths
425 [ "$QA" ] && receipt_quality
426 cd $pkgdir
427 rm -rf install taz source
429 # Disable -pipe if less than 512Mb free RAM.
430 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
431 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
432 gettext -e "Disabling -pipe compile flag: $free RAM\n"
433 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
434 CXXFLAGS="${CXXFLAGS/-pipe}" && \
435 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
436 fi
437 unset free
439 # Export flags and path to be used by make
440 DESTDIR=$pkgdir/install
441 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
443 # Check for build deps and handle implicit depends of *-dev packages
444 # (ex: libusb-dev :: libusb).
445 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
446 touch $CACHE/installed.local $CACHE/installed.web
447 [ "$BUILD_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 echo $i-$vers.tazpkg >> $CACHE/installed.local
460 else
461 # Priority to package version in wok (maybe more up-to-date)
462 # than the mirrored one.
463 if [ "$vers" ]; then
464 if fgrep -q $i-$vers $DB/packages.list; then
465 echo $i >> $CACHE/installed.web
466 else
467 # So package exists in wok but not available.
468 gettext "Missing dep (wok/pkg):"; echo " $i $vers"
469 echo $i >> $CACHE/missing.dep
470 fi
471 else
472 # Package is not in wok but may be in repo.
473 if fgrep -q $i-$vers $DB/packages.list; then
474 echo $i >> $CACHE/installed.web
475 else
476 echo "ERROR: unknown dep $i" && exit 1
477 fi
478 fi
479 fi
480 fi
481 done
482 done
484 # Get the list of installed packages
485 cd $INSTALLED && ls -1 > $CACHE/installed.list
487 # Have we a missing build dep to cook ?
488 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
489 gettext -e "Auto cook config is set : AUTO_COOK\n"
490 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
491 for i in $(uniq $CACHE/missing.dep)
492 do
493 (gettext "Building dep (wok/pkg) :"; echo " $i $vers") | \
494 tee -a $LOGS/$PACKAGE.log.$$
495 cook $i || (echo -e "ERROR: can't cook dep '$i'\n" && \
496 fgrep "remove: " $LOGS/$i.log && \
497 fgrep "Removing: " $LOGS/$i.log && echo "") | \
498 tee -a $LOGS/$PACKAGE.log.$$ && break
499 done
500 rm -f $CACHE/missing.dep
501 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
502 fi
504 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
505 # is enabled and cook fails we have ERROR in log, if no auto cook we have
506 # missing dep in cached file.
507 if fgrep -q "ERROR:" $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
508 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
509 echo "ERROR: missing dep $nb" && exit 1
510 fi
512 # Install local packages.
513 cd $PKGS
514 for i in $(uniq $CACHE/installed.local)
515 do
516 gettext "Installing dep (pkg/local):"; echo " $i"
517 tazpkg install $i >/dev/null
518 done
520 # Install web or cached packages (if mirror is set to $PKGS we only
521 # use local packages).
522 for i in $(uniq $CACHE/installed.web)
523 do
524 gettext "Installing dep (web/cache):"; echo " $i"
525 tazpkg get-install $i >/dev/null
526 done
528 # If a cook failed deps are removed.
529 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
530 [ ! -s "installed.cook.diff" ] && \
531 busybox diff installed.list installed.cook > installed.cook.diff
532 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
534 # Get source tarball and make sure we have source dir named:
535 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
536 # tarball if it exists.
537 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
538 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
539 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
540 LZMA_SRC=""
541 else
542 get_source || exit 1
543 fi
544 fi
545 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
546 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
547 extract_source || exit 1
548 if [ "$LZMA_SRC" ]; then
549 cd $pkgdir/source
550 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
551 mv tmp tmp-1 && mkdir tmp
552 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
553 fi
554 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
555 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
556 fi
557 fi
558 cd $pkgdir/source/tmp
559 # Some archives are not well done and don't extract to one dir (ex lzma).
560 files=$(ls | wc -l)
561 [ "$files" == 1 ] && mv * ../$PACKAGE-$VERSION
562 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
563 mv * ../$PACKAGE-$VERSION
564 cd .. && rm -rf tmp
565 fi
567 # Execute receipt rules.
568 if grep -q ^compile_rules $receipt; then
569 gettext -e "Executing: compile_rules\n"
570 [ -d "$src" ] && cd $src
571 compile_rules $@ || exit 1
572 # Stay compatible with _pkg
573 [ -d "$src/_pkg" ] && mv $src/_pkg $install
574 # QA: compile_rules success so valid.
575 mkdir -p $install
576 else
577 # QA: No compile_rules so no error, valid.
578 mkdir -p $install
579 fi
580 separator && echo ""
581 }
583 # Cook quality assurance.
584 cookit_quality() {
585 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
586 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
587 fi
588 # ERROR can be echoed any time in cookit()
589 if fgrep -q ERROR: $LOGS/$pkg.log; then
590 debug_info | tee -a $LOGS/$pkg.log
591 rm -f $command && exit 1
592 fi
593 }
595 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
596 # but it doesn't handle EXTRAVERSION.
597 packit() {
598 set_paths
599 echo "Pack: $PACKAGE $VERSION"
600 separator
601 if grep -q ^genpkg_rules $receipt; then
602 gettext -e "Executing: genpkg_rules\n"
603 cd $pkgdir
604 mkdir -p $fs && ( set -e; genpkg_rules ) || echo -e \
605 "\nERROR: genpkg_rules failed\n" >> $LOGS/$pkg.log
606 fi
608 # First QA check to stop now if genpkg_rules failed.
609 if fgrep -q ERROR: $LOGS/$pkg.log; then
610 exit 1
611 fi
613 cd $taz
614 for file in receipt description.txt
615 do
616 [ ! -f "../$file" ] && continue
617 gettext "Copying"; echo -n " $file..."
618 cp -f ../$file $pack && chown 0.0 $pack/$file && status
619 done
620 copy_generic_files
622 # Create files.list with redirecting find output.
623 gettext "Creating the list of files..." && cd $fs
624 find . -type f -print > ../files.list
625 find . -type l -print >> ../files.list
626 cd .. && sed -i s/'^.'/''/ files.list
627 status
629 # Strip and stuff files.
630 strip_package
632 # Md5sum of files.
633 gettext "Creating md5sum of files..."
634 while read file; do
635 [ -L "fs$file" ] && continue
636 [ -f "fs$file" ] || continue
637 case "$file" in
638 /lib/modules/*/modules.*|*.pyc) continue;;
639 esac
640 md5sum "fs$file" | sed 's/ fs/ /'
641 done < files.list > md5sum
642 status
643 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
644 description.txt 2> /dev/null | awk \
645 '{ sz=$1 } END { print sz }')
647 # Build cpio archives.
648 gettext "Compressing the fs... "
649 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
650 rm -rf fs
651 status
652 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
653 md5sum description.txt 2> /dev/null | awk \
654 '{ sz=$1 } END { print sz }')
655 gettext "Updating receipt sizes..."
656 sed -i s/^PACKED_SIZE.*$// receipt
657 sed -i s/^UNPACKED_SIZE.*$// receipt
658 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
659 status
661 # Set extra version.
662 if [ "$EXTRAVERSION" ]; then
663 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
664 sed -i s/^EXTRAVERSION.*$// receipt
665 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
666 status
667 fi
669 # Compress.
670 gettext "Creating full cpio archive... "
671 find . -print | cpio -o -H newc --quiet > \
672 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
673 status
674 gettext "Restoring original package tree... "
675 unlzma -c fs.cpio.lzma | cpio -idm --quiet
676 status
677 rm fs.cpio.lzma && cd ..
679 # QA and give info.
680 tazpkg=$(ls *.tazpkg)
681 packit_quality
682 separator && gettext "Package:"; echo -e " $tazpkg\n"
683 }
685 # Verify package quality and consistency.
686 packit_quality() {
687 #gettext "QA: Checking for broken link..."
688 #link=$(find $fs/usr -type l -follow)
689 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
690 #status
692 # Exit if any error found in log file.
693 if fgrep -q ERROR: $LOGS/$pkg.log; then
694 rm -f $command && exit 1
695 fi
697 gettext "QA: Checking for empty package..."
698 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
699 if [ "$files" -lt 0 ] && [ "$CATEGORY" != "meta" ]; then
700 echo -e "\nERROR: empty package"
701 rm -f $command && exit 1
702 else
703 # Ls sort by name so the first file is the one we want.
704 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
705 status
706 if [ -f "$old" ]; then
707 echo -n "Removing old: $(basename $old)"
708 rm -f $old && status
709 fi
710 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
711 sed -i /^${pkg}$/d $broken
712 fi
713 }
715 #
716 # Commands
717 #
719 case "$1" in
720 usage|help|-u|-h)
721 usage ;;
722 list-wok)
723 gettext -e "\nList of packages in:"; echo " $WOK"
724 separator
725 cd $WOK && ls -1
726 separator
727 echo -n "Packages: " && ls | wc -l
728 echo "" ;;
729 search)
730 # Just a simple search function, we dont need more actually.
731 query="$2"
732 gettext -e "\nSearch results for:"; echo " $query"
733 separator
734 cd $WOK && ls -1 | grep "$query"
735 separator && echo "" ;;
736 setup)
737 # Setup a build environment
738 check_root
739 echo "Cook: setting up the environment" | log
740 gettext -e "\nSetting up your environment\n"
741 separator && cd $SLITAZ
742 init_db_files
743 gettext -e "Checking for packages to install...\n"
744 for pkg in $SETUP_PKGS
745 do
746 [ ! -f "$INSTALLED/$pkg/receipt" ] && tazpkg get-install $pkg
747 done
749 # Handle --options
750 case "$2" in
751 --wok|-w)
752 [ ! -f "$INSTALLED/mercurial/receipt" ] && \
753 tazpkg get-install mercurial
754 [ -d "$WOK" ] && echo -e "A wok already exists.\n" && exit 1
755 hg clone $WOK_URL ;;
756 esac
758 # SliTaz group and permissions
759 if ! grep -q ^slitaz /etc/group; then
760 gettext -e "Adding group: slitaz\n"
761 addgroup slitaz
762 fi
763 gettext -e "Setting permissions for slitaz group...\n"
764 chown -R root.slitaz $SLITAZ
765 chmod -R g+w $SLITAZ
766 separator
767 gettext -e "All done, ready to cook packages :-)\n\n" ;;
768 test)
769 # Test a cook environment.
770 echo "Cook test: testing the cook environment" | log
771 [ ! -d "$WOK" ] && exit 1
772 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
773 cook cooktest ;;
774 new)
775 # Create the package folder and an empty receipt.
776 pkg="$2"
777 [ "$pkg" ] || usage
778 echo ""
779 if [ -d "$WOK/$pkg" ]; then
780 echo -n "$pkg " && gettext "package already exists."
781 echo -e "\n" && exit 1
782 fi
783 gettext "Creating"; echo -n " $WOK/$pkg"
784 mkdir $WOK/$pkg && cd $WOK/$pkg && status
785 gettext "Preparing the package receipt..."
786 cp $DATA/receipt .
787 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
788 status && echo ""
790 # Interactive mode, asking and seding.
791 case "$3" in
792 --interactive|-x)
793 gettext -e "Entering interactive mode...\n"
794 separator
795 echo "Package : $pkg"
796 # Version.
797 echo -n "Version : " ; read anser
798 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
799 # Category.
800 echo -n "Category : " ; read anser
801 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
802 # Short description.
803 echo -n "Short desc : " ; read anser
804 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
805 # Maintainer.
806 echo -n "Maintainer : " ; read anser
807 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
808 # Web site.
809 echo -n "Web site : " ; read anser
810 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
811 echo ""
812 # Wget URL.
813 echo "Wget URL to download source tarball."
814 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
815 echo -n "Wget url : " ; read anser
816 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
817 # Ask for a stuff dir.
818 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
819 if [ "$anser" = "y" ]; then
820 echo -n "Creating the stuff directory..."
821 mkdir $WOK/$pkg/stuff && status
822 fi
823 # Ask for a description file.
824 echo -n "Are you going to write a description ? (y/N) : " ; read anser
825 if [ "$anser" = "y" ]; then
826 echo -n "Creating the description.txt file..."
827 echo "" > $WOK/$pkg/description.txt && status
828 fi
829 separator
830 gettext -e "Receipt is ready to use.\n"
831 echo "" ;;
832 esac ;;
833 list)
834 # Cook a list of packages (better use the Cooker since it will order
835 # packages before executing cook).
836 check_root
837 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
838 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
839 echo -e " $2\n" && exit 1
840 echo "Cook list starting: $2" | log
841 for pkg in $(cat $2)
842 do
843 cook $pkg || broken
844 done ;;
845 clean-wok)
846 check_root
847 gettext -e "\nCleaning all packages files..."
848 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
849 status && echo "" ;;
850 clean-src)
851 check_root
852 gettext -e "\nCleaning all packages sources..."
853 rm -rf $WOK/*/source
854 status && echo "" ;;
855 pkglist)
856 # Create suitable packages list for TazPKG and only for built packages.
857 [ "$2" ] && PKGS="$2"
858 [ ! -d "$PKGS" ] && \
859 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1
860 time=$(date +%s)
861 echo "cook:pkglist" > $command
862 echo "Cook pkglist: Creating all packages lists" | log
863 gettext -e "\nCreating lists for:"; echo " $PKGS"
864 separator
865 gettext "Cook pkglist started at: "; date "+%H:%M"
866 cd $PKGS
867 rm -f packages.*
868 gettext "Creating: packages.list "
869 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
870 echo $(du -sh $PKGS/packages.list | awk '{print $1}')
871 gettext "Creating: packages.md5 "
872 md5sum *.tazpkg > $PKGS/packages.md5
873 echo $(du -sh $PKGS/packages.md5 | awk '{print $1}')
874 gettext -e "Creating lists from:"; echo " $WOK"
875 cd $WOK
876 for pkg in *
877 do
878 unset_receipt
879 . $pkg/receipt
880 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
881 # packages.desc lets us search easily in DB
882 cat >> $PKGS/packages.desc << EOT
883 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
884 EOT
885 # packages.txt used by tazpkg and tazpkg-web also to provide
886 # a human readable package list with version and description.
887 cat >> $PKGS/packages.txt << EOT
888 $PACKAGE
889 ${VERSION}$EXTRAVERSION
890 $SHORT_DESC
891 $PACKED_SIZE ($UNPACKED_SIZE installed)
893 EOT
894 # packages.equiv is used by tazpkg install to check depends.
895 for i in $PROVIDE; do
896 DEST=""
897 echo $i | fgrep -q : && DEST="${i#*:}:"
898 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
899 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
900 $PKGS/packages.equiv
901 else
902 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
903 fi
904 done
905 # files.list provides a list of all packages files.
906 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
907 $PKGS/files.list
908 fi
909 done
910 cd $PKGS
912 # Display list size.
913 gettext "Done: packages.desc "
914 echo $(du -sh $PKGS/packages.desc | awk '{print $1}')
915 gettext "Done: packages.txt "
916 echo $(du -sh $PKGS/packages.txt | awk '{print $1}')
917 gettext "Done: packages.equiv "
918 echo $(du -sh $PKGS/packages.equiv | awk '{print $1}')
920 # files.list.lzma
921 gettext "Creating: files.list.lzma "
922 lzma e files.list files.list.lzma
923 rm -f files.list
924 echo $(du -sh $PKGS/files.list.lzma | awk '{print $1}')
926 separator
927 nb=$(ls $PKGS/*.tazpkg | wc -l)
928 time=$(($(date +%s) - $time))
929 echo -e "Packages: $nb - Time: $time\n"
930 rm -f $command ;;
931 *)
932 # Just cook and generate a package.
933 check_root
934 time=$(date +%s)
935 pkg="$1"
936 [ -z "$pkg" ] && usage
937 receipt="$WOK/$pkg/receipt"
938 check_pkg_in_wok && echo ""
940 # Display and log info if cook process stopped.
941 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
942 tee -a $LOGS/$pkg.log' INT
944 # Skip blocked, 3 lines also for the Cooker.
945 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
946 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
947 fi
949 # Log and source receipt.
950 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
951 echo "cook:$pkg" > $command
952 unset inst
953 unset_receipt
954 . $receipt
956 # Handle --options
957 case "$2" in
958 --clean|-c)
959 gettext -e "Cleaning:"; echo -n " $pkg"
960 cd $WOK/$pkg && rm -rf install taz source
961 status && echo "" && exit 0 ;;
962 --install|-i)
963 inst='yes' ;;
964 --getsrc|-gs)
965 gettext "Getting source for:"; echo " $pkg"
966 separator && get_source
967 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
968 --block|-b)
969 gettext "Blocking:"; echo -n " $pkg"
970 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
971 status && echo "" && exit 0 ;;
972 --unblock|-ub)
973 gettext "Unblocking:"; echo -n " $pkg"
974 sed -i "/^${pkg}$/"d $blocked
975 status && echo "" && exit 0 ;;
977 esac
979 # Check if wanted is built now so we have separate log files.
980 if [ "$WANTED" ]; then
981 if grep -q "^$WANTED$" $blocked; then
982 echo "WANTED package is blocked: $WANTED" | tee $LOGS/$pkg.log
983 echo "" && rm -f $command && exit 1
984 fi
985 if grep -q "^$WANTED$" $broken; then
986 echo "WANTED package is broken: $WANTED" | tee $LOGS/$pkg.log
987 echo "" && rm -f $command && exit 1
988 fi
989 if [ ! -d "$WOK/$WANTED/install" ]; then
990 cook "$WANTED" || exit 1
991 fi
992 fi
994 # Cook and pack or exit on error and log everything.
995 cookit $@ 2>&1 | tee $LOGS/$pkg.log
996 remove_deps | tee -a $LOGS/$pkg.log
997 cookit_quality
998 packit 2>&1 | tee -a $LOGS/$pkg.log
999 clean_log
1001 # Exit if any error in packing.
1002 if grep -q ^ERROR $LOGS/$pkg.log; then
1003 debug_info | tee -a $LOGS/$pkg.log
1004 rm -f $command && exit 1
1005 fi
1007 # Time and summary
1008 time=$(($(date +%s) - $time))
1009 summary | tee -a $LOGS/$pkg.log
1010 echo ""
1012 # Install package if requested
1013 if [ "$inst" ]; then
1014 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1015 cd $PKGS && tazpkg install \
1016 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1017 else
1018 gettext -e "Unable to install package, build has failed.\n\n"
1019 exit 1
1020 fi
1021 fi
1022 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1023 # You want automation: use the Cooker Build Bot.
1024 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
1025 rm -f $command ;;
1026 esac
1028 exit 0