cookutils view cook @ rev 285

cook: add aufs_chroot jail
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Feb 13 15:51:04 2012 +0100 (2012-02-13)
parents b049254bc104
children 031bdfdd0969
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 pkgdb $(gettext "Create packages DB lists and flavors.")
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 New : $(gettext "create a receipt interactively.")
50 --wok|-w Setup: $(gettext "clone the cooking wok from Hg repo.")
51 --stable Setup: $(gettext "clone the stable wok from Hg repo.")
52 --undigest Setup: $(gettext "clone the undigest wok from Hg repo.")
53 --flavors Pkgdb: $(gettext "create up-to-date flavors files.")
55 EOT
56 exit 0
57 }
59 # Be sure we're root.
60 check_root() {
61 [ $(id -u) != 0 ] && gettext -e "\nYou must be root to cook.\n\n" && exit 0
62 }
64 separator() {
65 echo "================================================================================"
66 }
68 status() {
69 echo -en "\\033[70G[ "
70 if [ $? = 0 ]; then
71 echo -en "\\033[1;32mOK"
72 else
73 echo -en "\\033[1;31mFailed"
74 fi
75 echo -e "\\033[0;39m ]"
76 }
78 # Log activities, we want first letter capitalized.
79 log() {
80 grep ^[A-Z] | \
81 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
82 }
84 # We don't want these escapes in web interface.
85 clean_log() {
86 sed -i -e s'|\[70G\[ \[1;32m| |' \
87 -e s'|\[0;39m \]||' $LOGS/$pkg.log
88 }
90 # Log broken packages.
91 broken() {
92 if ! grep -q "^$pkg$" $broken; then
93 echo "$pkg" >> $broken
94 fi
95 }
97 # Be sure package exists in wok.
98 check_pkg_in_wok() {
99 if [ ! -d "$WOK/$pkg" ]; then
100 gettext -e "\nUnable to find package in the wok:"
101 echo -e " $pkg\n" && exit 1
102 fi
103 }
105 if_empty_value() {
106 if [ -z "$value" ]; then
107 gettext "QA: empty variable:"; echo -e " ${var}=\"\"\n"
108 exit 1
109 fi
110 }
112 # Initialize files used in $CACHE
113 init_db_files() {
114 gettext "Creating directories structure in:"; echo " $SLITAZ"
115 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS
116 gettext "Creating DB files in:"; echo " $CACHE"
117 for f in $activity $command $broken $blocked
118 do
119 touch $f
120 done
121 }
123 # QA: check a receipt consistency before building.
124 receipt_quality() {
125 gettext -e "QA: checking package receipt...\n"
126 unset online
127 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
128 online="online"
129 fi
130 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
131 do
132 unset value
133 value="$(. $receipt ; eval echo \$$var)"
134 case "$var" in
135 PACKAGE|VERSION|SHORT_DESC)
136 if_empty_value ;;
137 CATEGORY)
138 [ -z "$value" ] && value="empty"
139 valid="base-system x-window utilities network graphics \
140 multimedia office development system-tools security games \
141 misc meta non-free"
142 if ! echo "$valid" | grep -q -w "$value"; then
143 gettext "QA: unknown category:"; echo -e " $value\n"
144 exit 1
145 fi ;;
146 WEB_SITE)
147 # We don't check WGET_URL since if dl is needed it will fail.
148 # Break also if we're not online. Here error is not fatal.
149 if_empty_value
150 [ -z "$online" ] || break
151 if ! busybox wget -T 12 -s $value 2>/dev/null; then
152 gettext "QA: Unable to reach:"; echo -e " $value"
153 fi ;;
154 esac
155 done
156 }
158 # Executed before sourcing a receipt.
159 unset_receipt() {
160 unset DEPENDS BUILD_DEPENDS WANTED EXTRAVERSION WGET_URL PROVIDE TARBALL
161 }
163 # Paths used in receipt and by cook itself.
164 set_paths() {
165 pkgdir=$WOK/$PACKAGE
166 src=$pkgdir/source/$PACKAGE-$VERSION
167 taz=$pkgdir/taz
168 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
169 fs=$pack/fs
170 stuff=$pkgdir/stuff
171 install=$pkgdir/install
172 if [ "$WANTED" ]; then
173 src=$WOK/$WANTED/source/$WANTED-$VERSION
174 install=$WOK/$WANTED/install
175 wanted_stuff=$WOK/$WANTED/stuff
176 fi
177 # Kernel version is set from linux-api-headers since it is part of toolchain.
178 if [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
179 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d '"' -f 2)
180 fi
181 # Old way compatibility.
182 _pkg=$install
183 }
185 # Create source tarball when URL is a SCM.
186 create_tarball() {
187 gettext "Creating tarball: "; echo "$tarball"
188 if [ "$LZMA_SRC" ]; then
189 tar -c $pkgsrc | lzma e $SRC/$tarball -si || exit 1
190 else
191 tar cjf $tarball $pkgsrc || exit 1
192 mv $tarball $SRC && rm -rf $pkgsrc
193 fi
194 }
196 # Get package source. For SCM we are in cache so clone here and create a
197 # tarball here.
198 get_source() {
199 pwd=$(pwd)
200 pkgsrc=${SOURCE:-$PACKAGE}-$VERSION
201 tarball=$pkgsrc.tar.bz2
202 [ "$LZMA_SRC" ] && tarball=$pkgsrc.tar.lzma
203 case "$WGET_URL" in
204 http://*|ftp://*)
205 # Busybox Wget is better!
206 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
207 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
208 https://*)
209 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
210 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
211 hg*|mercurial*)
212 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
213 url=${WGET_URL#hg|}
214 else
215 url=${WGET_URL#mercurial|}
216 fi
217 gettext -e "Getting source from Hg...\n"
218 echo "URL: $url"
219 gettext "Cloning to: "; echo "$pwd/$pkgsrc"
220 if [ "$BRANCH" ]; then
221 echo "Hg branch: $BRANCH"
222 hg clone $url --rev $BRANCH $pkgsrc || \
223 (echo "ERROR: hg clone $url --rev $BRANCH" && exit 1)
224 else
225 hg clone $url $pkgsrc || (echo "ERROR: hg clone $url" && exit 1)
226 fi
227 rm -rf $pkgsrc/.hg
228 create_tarball ;;
229 git*)
230 url=${WGET_URL#git|}
231 gettext -e "Getting source from Git...\n"
232 echo "URL: $url"
233 git clone $url $pkgsrc || (echo "ERROR: git clone $url" && exit 1)
234 if [ "$BRANCH" ]; then
235 echo "Git branch: $BRANCH"
236 cd $pkgsrc && git checkout $BRANCH && cd ..
237 fi
238 create_tarball ;;
239 cvs*)
240 url=${WGET_URL#cvs|}
241 mod=$PACKAGE
242 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
243 gettext -e "Getting source from CVS...\n"
244 echo "URL: $url"
245 [ "$CVS_MODULE" ] && echo "CVS module: $mod"
246 gettext "Cloning to: "; echo "$pwd/$mod"
247 cvs -d:$url co $mod && mv $mod $pkgsrc
248 create_tarball ;;
249 svn*|subversion*)
250 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
251 url=${WGET_URL#svn|}
252 else
253 url=${WGET_URL#subversion|}
254 fi
255 gettext -e "Getting source from SVN...\n"
256 echo "URL: $url"
257 if [ "$BRANCH" ]; then
258 echo t | svn co $url -r $BRANCH $pkgsrc
259 else
260 echo t | svn co $url $pkgsrc
261 fi
262 create_tarball ;;
263 *)
264 gettext -e "\nERROR: Unable to handle:"; echo -e " $WGET_URL \n" | \
265 tee -a $LOGS/$PACKAGE.log
266 exit 1 ;;
267 esac
268 }
270 # Extract source package.
271 extract_source() {
272 if [ ! -s "$SRC/$TARBALL" ]; then
273 local url
274 url="http://mirror.slitaz.org/sources/packages"
275 url=$url/${TARBALL:0:1}/$TARBALL
276 gettext "Getting source from mirror:"; echo " $url"
277 busybox wget -c -P $SRC $url || echo -e "ERROR: wget $url"
278 fi
279 gettext "Extracting:"; echo " $TARBALL"
280 case "$TARBALL" in
281 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
282 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
283 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
284 *.tar) tar xf $SRC/$TARBALL ;;
285 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
286 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
287 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
288 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
289 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
290 *) cp $SRC/$TARBALL $(pwd) ;;
291 esac
292 }
294 # Display cooked package summary.
295 summary() {
296 cd $WOK/$pkg
297 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
298 fs=$(du -sh taz/* | awk '{print $1}')
299 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
300 files=$(cat taz/$pkg-*/files.list | wc -l)
301 cookdate=$(date "+%Y-%m-%d %H:%M")
302 sec=$time
303 div=$(( ($time + 30) / 60))
304 [ "$div" != 0 ] && min="~ ${div}m"
305 gettext "Summary for:"; echo " $PACKAGE $VERSION"
306 separator
307 [ "$prod" ] && echo "Produced : $prod"
308 cat << EOT
309 Packed : $fs
310 Compressed : $size
311 Files : $files
312 Cook time : ${sec}s $min
313 Cook date : $cookdate
314 $(separator)
315 EOT
316 }
318 # Display debugging error info.
319 debug_info() {
320 echo -e "\nDebug information"
321 separator
322 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
323 for error in \
324 ERROR "No package" "cp: can't" "can't open" "can't cd" \
325 "error:" "fatal error:"
326 do
327 fgrep "$error" $LOGS/$pkg.log
328 done
329 separator && echo ""
330 }
332 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
333 # so some packages need to copy these files with the receipt and genpkg_rules.
334 copy_generic_files()
335 {
336 # $LOCALE is set in cook.conf
337 if [ "$LOCALE" ]; then
338 if [ -d "$install/usr/share/locale" ]; then
339 mkdir -p $fs/usr/share/locale
340 for i in $LOCALE
341 do
342 if [ -d "$install/usr/share/locale/$i" ]; then
343 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
344 fi
345 done
346 fi
347 fi
349 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
350 if [ "$GENERIC_PIXMAPS" != "no" ]; then
351 if [ -d "$install/usr/share/pixmaps" ]; then
352 mkdir -p $fs/usr/share/pixmaps
353 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
354 $fs/usr/share/pixmaps 2>/dev/null || continue
355 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
356 $fs/usr/share/pixmaps 2>/dev/null || continue
357 fi
359 # Custom or homemade PNG pixmap can be in stuff.
360 if [ -f "$stuff/$PACKAGE.png" ]; then
361 mkdir -p $fs/usr/share/pixmaps
362 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
363 fi
364 fi
366 # Desktop entry (.desktop).
367 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
368 if [ "$GENERIC_MENUS" != "no" ]; then
369 if [ -d "$install/usr/share/applications" ] && [ "$WANTED" == "" ]; then
370 cp -a $install/usr/share/applications $fs/usr/share
371 fi
372 fi
374 # Homemade desktop file(s) can be in stuff.
375 if [ -d "$stuff/applications" ]; then
376 mkdir -p $fs/usr/share
377 cp -a $stuff/applications $fs/usr/share
378 fi
379 if [ -f "$stuff/$PACKAGE.desktop" ]; then
380 mkdir -p $fs/usr/share/applications
381 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
382 fi
383 }
385 # Find and strip : --strip-all (-s) or --strip-debug on static libs as well
386 # as removing uneeded files like in Python packages.
387 strip_package()
388 {
389 gettext "Executing strip on all files..."
390 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
391 do
392 if [ -d "$dir" ]; then
393 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
394 fi
395 done
396 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
397 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
398 status
400 # Remove Python .pyc and .pyo from packages.
401 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
402 gettext "Removing Python compiled files..."
403 find $fs -type f -name "*.pyc" -delete 2>/dev/null
404 find $fs -type f -name "*.pyo" -delete 2>/dev/null
405 status
406 fi
408 # Remove Perl perllocal.pod and .packlist from packages.
409 if echo "$DEPENDS" | fgrep -q "perl"; then
410 gettext "Removing Perl compiled files..."
411 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
412 find $fs -type f -name ".packlist" -delete 2>/dev/null
413 status
414 fi
415 }
417 # Remove installed deps.
418 remove_deps() {
419 # Now remove installed build deps.
420 diff="$CACHE/installed.cook.diff"
421 if [ -s "$CACHE/installed.cook.diff" ]; then
422 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
423 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
424 gettext "Build dependencies to remove:"; echo " $nb"
425 gettext "Removing:"
426 for dep in $deps
427 do
428 echo -n " $dep"
429 echo 'y' | tazpkg remove $dep >/dev/null
430 done
431 echo -e "\n"
432 # Keep the last diff for debug and info.
433 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
434 fi
435 }
437 # The main cook function.
438 cookit() {
439 echo "Cook: $PACKAGE $VERSION"
440 separator
441 set_paths
442 [ "$QA" ] && receipt_quality
443 cd $pkgdir
444 rm -rf install taz source
446 # Disable -pipe if less than 512Mb free RAM.
447 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
448 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
449 gettext -e "Disabling -pipe compile flag: $free RAM\n"
450 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
451 CXXFLAGS="${CXXFLAGS/-pipe}" && \
452 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
453 fi
454 unset free
456 # Export flags and path to be used by make and receipt.
457 DESTDIR=$pkgdir/install
458 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
460 # Check for build deps and handle implicit depends of *-dev packages
461 # (ex: libusb-dev :: libusb).
462 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
463 touch $CACHE/installed.local $CACHE/installed.web
464 [ "$BUILD_DEPENDS" ] && gettext -e "Checking build dependencies...\n"
465 for dep in $BUILD_DEPENDS
466 do
467 implicit=${dep%-dev}
468 for i in $dep $implicit
469 do
470 if [ ! -f "$INSTALLED/$i/receipt" ]; then
471 # Try local package first. In some cases implicit doesn't exist, ex:
472 # libboost-dev exists but not libboost, so check if we got vers.
473 unset vers
474 vers=$(grep ^VERSION= $WOK/$i/receipt 2>/dev/null | cut -d '"' -f 2)
475 if [ -f "$PKGS/$i-$vers.tazpkg" ]; then
476 echo $i-$vers.tazpkg >> $CACHE/installed.local
477 else
478 # Priority to package version in wok (maybe more up-to-date)
479 # than the mirrored one.
480 if [ "$vers" ]; then
481 if fgrep -q $i-$vers $DB/packages.list; then
482 echo $i >> $CACHE/installed.web
483 else
484 # So package exists in wok but not available.
485 gettext "Missing dep (wok/pkg):"; echo " $i $vers"
486 echo $i >> $CACHE/missing.dep
487 fi
488 else
489 # Package is not in wok but may be in repo.
490 if fgrep -q $i-$vers $DB/packages.list; then
491 echo $i >> $CACHE/installed.web
492 else
493 echo "ERROR: unknown dep $i" && exit 1
494 fi
495 fi
496 fi
497 fi
498 done
499 done
501 # Get the list of installed packages
502 cd $INSTALLED && ls -1 > $CACHE/installed.list
504 # Have we a missing build dep to cook ?
505 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
506 gettext -e "Auto cook config is set : AUTO_COOK\n"
507 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
508 for i in $(uniq $CACHE/missing.dep)
509 do
510 (gettext "Building dep (wok/pkg) :"; echo " $i $vers") | \
511 tee -a $LOGS/$PACKAGE.log.$$
512 cook $i || (echo -e "ERROR: can't cook dep '$i'\n" && \
513 fgrep "remove: " $LOGS/$i.log && \
514 fgrep "Removing: " $LOGS/$i.log && echo "") | \
515 tee -a $LOGS/$PACKAGE.log.$$ && break
516 done
517 rm -f $CACHE/missing.dep
518 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
519 fi
521 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
522 # is enabled and cook fails we have ERROR in log, if no auto cook we have
523 # missing dep in cached file.
524 if fgrep -q "ERROR:" $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
525 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
526 echo "ERROR: missing dep $nb" && exit 1
527 fi
529 # Install local packages.
530 cd $PKGS
531 for i in $(uniq $CACHE/installed.local)
532 do
533 gettext "Installing dep (pkg/local):"; echo " $i"
534 tazpkg install $i >/dev/null
535 done
537 # Install web or cached packages (if mirror is set to $PKGS we only
538 # use local packages).
539 for i in $(uniq $CACHE/installed.web)
540 do
541 gettext "Installing dep (web/cache):"; echo " $i"
542 tazpkg get-install $i >/dev/null
543 done
545 # If a cook failed deps are removed.
546 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
547 [ ! -s "installed.cook.diff" ] && \
548 busybox diff installed.list installed.cook > installed.cook.diff
549 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
551 # Get source tarball and make sure we have source dir named:
552 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
553 # tarball if it exists.
554 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
555 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
556 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
557 LZMA_SRC=""
558 else
559 get_source || exit 1
560 fi
561 fi
562 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
563 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
564 if ! extract_source ; then
565 get_source
566 extract_source || exit 1
567 fi
568 if [ "$LZMA_SRC" ]; then
569 cd $pkgdir/source
570 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
571 mv tmp tmp-1 && mkdir tmp
572 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
573 fi
574 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
575 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
576 fi
577 fi
578 cd $pkgdir/source/tmp
579 # Some archives are not well done and don't extract to one dir (ex lzma).
580 files=$(ls | wc -l)
581 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
582 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
583 mv * ../$PACKAGE-$VERSION/$TARBALL
584 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
585 mv * ../$PACKAGE-$VERSION
586 cd .. && rm -rf tmp
587 fi
589 # Execute receipt rules.
590 if grep -q ^compile_rules $receipt; then
591 gettext -e "Executing: compile_rules\n"
592 [ -d "$src" ] && cd $src
593 compile_rules $@ || exit 1
594 # Stay compatible with _pkg
595 [ -d "$src/_pkg" ] && mv $src/_pkg $install
596 # QA: compile_rules success so valid.
597 mkdir -p $install
598 else
599 # QA: No compile_rules so no error, valid.
600 mkdir -p $install
601 fi
602 separator && echo ""
603 }
605 # Cook quality assurance.
606 cookit_quality() {
607 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
608 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
609 fi
610 # ERROR can be echoed any time in cookit()
611 if fgrep -q ERROR: $LOGS/$pkg.log; then
612 debug_info | tee -a $LOGS/$pkg.log
613 rm -f $command && exit 1
614 fi
615 }
617 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
618 # but it doesn't handle EXTRAVERSION.
619 packit() {
620 set_paths
621 echo "Pack: $PACKAGE $VERSION"
622 separator
623 if grep -q ^genpkg_rules $receipt; then
624 gettext -e "Executing: genpkg_rules\n"
625 set -e && cd $pkgdir && mkdir -p $fs
626 genpkg_rules || echo -e "\nERROR: genpkg_rules failed\n" >> \
627 $LOGS/$pkg.log
628 else
629 gettext "No packages rules: meta package"; echo
630 mkdir -p $fs
631 fi
633 # First QA check to stop now if genpkg_rules failed.
634 if fgrep -q ERROR: $LOGS/$pkg.log; then
635 exit 1
636 fi
638 cd $taz
639 for file in receipt description.txt
640 do
641 [ ! -f "../$file" ] && continue
642 gettext "Copying"; echo -n " $file..."
643 cp -f ../$file $pack && chown 0.0 $pack/$file && status
644 done
645 copy_generic_files
647 # Create files.list with redirecting find output.
648 gettext "Creating the list of files..." && cd $fs
649 find . -type f -print > ../files.list
650 find . -type l -print >> ../files.list
651 cd .. && sed -i s/'^.'/''/ files.list
652 status
654 # Strip and stuff files.
655 strip_package
657 # Md5sum of files.
658 gettext "Creating md5sum of files..."
659 while read file; do
660 [ -L "fs$file" ] && continue
661 [ -f "fs$file" ] || continue
662 case "$file" in
663 /lib/modules/*/modules.*|*.pyc) continue ;;
664 esac
665 md5sum "fs$file" | sed 's/ fs/ /'
666 done < files.list > md5sum
667 status
668 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
669 description.txt 2> /dev/null | awk \
670 '{ sz=$1 } END { print sz }')
672 # Build cpio archives.
673 gettext "Compressing the fs... "
674 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
675 rm -rf fs
676 status
677 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
678 md5sum description.txt 2> /dev/null | awk \
679 '{ sz=$1 } END { print sz }')
680 gettext "Updating receipt sizes..."
681 sed -i s/^PACKED_SIZE.*$// receipt
682 sed -i s/^UNPACKED_SIZE.*$// receipt
683 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
684 status
686 # Set extra version.
687 if [ "$EXTRAVERSION" ]; then
688 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
689 sed -i s/^EXTRAVERSION.*$// receipt
690 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
691 status
692 fi
694 # Compress.
695 gettext "Creating full cpio archive... "
696 find . -print | cpio -o -H newc --quiet > \
697 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
698 status
699 gettext "Restoring original package tree... "
700 unlzma -c fs.cpio.lzma | cpio -idm --quiet
701 status
702 rm fs.cpio.lzma && cd ..
704 # QA and give info.
705 tazpkg=$(ls *.tazpkg)
706 packit_quality
707 separator && gettext "Package:"; echo -e " $tazpkg\n"
708 }
710 # Verify package quality and consistency.
711 packit_quality() {
712 #gettext "QA: Checking for broken link..."
713 #link=$(find $fs/usr -type l -follow)
714 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
715 #status
717 # Exit if any error found in log file.
718 if fgrep -q ERROR: $LOGS/$pkg.log; then
719 rm -f $command && exit 1
720 fi
722 gettext "QA: Checking for empty package..."
723 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
724 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
725 echo -e "\nERROR: empty package"
726 rm -f $command && exit 1
727 else
728 # Ls sort by name so the first file is the one we want.
729 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
730 status
731 if [ -f "$old" ]; then
732 gettext "Removing old: $(basename $old)"
733 rm -f $old && status
734 fi
735 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
736 sed -i /^${pkg}$/d $broken
737 #gettext "Removing source tree..."
738 #rm -f $WOK/$pkg/source && status
739 fi
740 }
742 mkinstall_list() {
743 local pkg
744 for pkg in $@ ; do
745 case " $INSTALL_LIST " in
746 *\ $pkg\ *) continue ;;
747 *) if [ -s /home/slitaz/wok/$pkg/receipt ]; then
748 unset DEPENDS
749 . /home/slitaz/wok/$pkg/receipt
750 INSTALL_LIST="$INSTALL_LIST $pkg"
751 [ -n "$DEPENDS" ] && mkinstall_list $DEPENDS
752 fi
753 echo $pkg
754 esac
755 done
756 }
758 tac()
759 {
760 sed '1!G;h;$!d' $1
761 }
763 # Launch the cook command into a chroot jail protected by aufs.
764 # The current filesystems are used read-only and updates are
765 # stored in a separate branch.
766 try_aufs_chroot() {
768 # Can we setup the chroot ? Is it already done ?
769 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
770 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
772 echo "Setup aufs chroot..."
773 base=/dev/shm/aufsmnt$$
774 mkdir ${base}root ${base}rw
776 # Sanity check
777 for i in / /proc /sys /dev/shm ; do
778 case " $AUFS_MOUNTS " in
779 *\ $i\ *) ;;
780 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
781 esac
782 done
783 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
784 mount --bind $mnt ${base}root$mnt
785 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
786 echo "Aufs mountage failure"
787 umount ${base}root
788 rmdir ${base}*
789 return
790 fi
791 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
792 done
793 mount --bind /home ${base}root/home
795 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
796 status=$?
798 echo "Leave aufs chroot..."
799 umount ${base}root/home
800 tac ${base}rw/aufs-umount.sh | sh
801 rm -rf ${base}rw
802 umount ${base}root
803 rmdir $base*
805 # Install package if requested
806 if [ "$inst" ]; then
807 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
808 cd $PKGS && tazpkg install \
809 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
810 else
811 gettext -e "Unable to install package, build has failed.\n\n"
812 exit 1
813 fi
814 fi
815 exit $status
816 }
818 #
819 # Commands
820 #
822 case "$1" in
823 usage|help|-u|-h)
824 usage ;;
825 list-wok)
826 gettext -e "\nList of packages in:"; echo " $WOK"
827 separator
828 cd $WOK && ls -1
829 separator
830 echo -n "Packages: " && ls | wc -l
831 echo "" ;;
832 search)
833 # Just a simple search function, we dont need more actually.
834 query="$2"
835 gettext -e "\nSearch results for:"; echo " $query"
836 separator
837 cd $WOK && ls -1 | grep "$query"
838 separator && echo "" ;;
839 setup)
840 # Setup a build environment
841 check_root
842 echo "Cook: setting up the environment" | log
843 gettext -e "\nSetting up your environment\n"
844 separator && cd $SLITAZ
845 init_db_files
846 gettext -e "Checking for packages to install...\n"
847 case " $@ " in
848 *\ --reinstall\ *)
849 INSTALL_LIST=""
850 for pkg in $(mkinstall_list $SETUP_PKGS); do
851 tazpkg get-install $pkg --forced
852 done ;;
853 *)
854 for pkg in $SETUP_PKGS
855 do
856 [ ! -f "$INSTALLED/$pkg/receipt" ] &&
857 tazpkg get-install $pkg
858 done ;;
859 esac
861 # Handle --options
862 case "$2" in
863 --wok|-w)
864 hg clone $WOK_URL wok || exit 1 ;;
865 --stable)
866 hg clone $WOK_URL-stable wok || exit 1 ;;
867 --undigest)
868 hg clone $WOK_URL-undigest wok || exit 1 ;;
869 esac
871 # SliTaz group and permissions
872 if ! grep -q ^slitaz /etc/group; then
873 gettext -e "Adding group: slitaz\n"
874 addgroup slitaz
875 fi
876 gettext -e "Setting permissions for slitaz group...\n"
877 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
878 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
879 separator
880 gettext -e "All done, ready to cook packages :-)\n\n" ;;
881 test)
882 # Test a cook environment.
883 echo "Cook test: testing the cook environment" | log
884 [ ! -d "$WOK" ] && exit 1
885 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
886 cook cooktest ;;
887 new)
888 # Create the package folder and an empty receipt.
889 pkg="$2"
890 [ "$pkg" ] || usage
891 echo ""
892 if [ -d "$WOK/$pkg" ]; then
893 echo -n "$pkg " && gettext "package already exists."
894 echo -e "\n" && exit 1
895 fi
896 gettext "Creating"; echo -n " $WOK/$pkg"
897 mkdir $WOK/$pkg && cd $WOK/$pkg && status
898 gettext "Preparing the package receipt..."
899 cp $DATA/receipt .
900 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
901 status && echo ""
903 # Interactive mode, asking and seding.
904 case "$3" in
905 --interactive|-x)
906 gettext -e "Entering interactive mode...\n"
907 separator
908 echo "Package : $pkg"
909 # Version.
910 echo -n "Version : " ; read anser
911 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
912 # Category.
913 echo -n "Category : " ; read anser
914 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
915 # Short description.
916 echo -n "Short desc : " ; read anser
917 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
918 # Maintainer.
919 echo -n "Maintainer : " ; read anser
920 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
921 # Web site.
922 echo -n "Web site : " ; read anser
923 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
924 echo ""
925 # Wget URL.
926 echo "Wget URL to download source tarball."
927 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
928 echo -n "Wget url : " ; read anser
929 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
930 # Ask for a stuff dir.
931 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
932 if [ "$anser" = "y" ]; then
933 echo -n "Creating the stuff directory..."
934 mkdir $WOK/$pkg/stuff && status
935 fi
936 # Ask for a description file.
937 echo -n "Are you going to write a description ? (y/N) : " ; read anser
938 if [ "$anser" = "y" ]; then
939 echo -n "Creating the description.txt file..."
940 echo "" > $WOK/$pkg/description.txt && status
941 fi
942 separator
943 gettext -e "Receipt is ready to use.\n"
944 echo "" ;;
945 esac ;;
946 list)
947 # Cook a list of packages (better use the Cooker since it will order
948 # packages before executing cook).
949 check_root
950 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
951 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
952 echo -e " $2\n" && exit 1
953 echo "Cook list starting: $2" | log
954 for pkg in $(cat $2)
955 do
956 cook $pkg || broken
957 done ;;
958 clean-wok)
959 check_root
960 gettext -e "\nCleaning all packages files..."
961 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
962 status && echo "" ;;
963 clean-src)
964 check_root
965 gettext -e "\nCleaning all packages sources..."
966 rm -rf $WOK/*/source
967 status && echo "" ;;
968 pkgdb)
969 # Create suitable packages list for TazPKG and only for built packages
970 # as well as flavors files for TazLiTo. We dont need logs since we do it
971 # manually to ensure everything is fine before syncing the mirror.
972 case "$2" in
973 --flavors)
974 continue ;;
975 *)
976 [ "$2" ] && PKGS="$2"
977 [ ! -d "$PKGS" ] && \
978 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1 ;;
979 esac
980 time=$(date +%s)
981 flavors=$SLITAZ/flavors
982 live=$SLITAZ/live
983 echo "cook:pkgdb" > $command
984 echo "Cook pkgdb: Creating all packages lists" | log
985 echo ""
986 gettext "Creating lists for: "; echo "$PKGS"
987 separator
988 gettext "Cook pkgdb started: "; date "+%Y-%m-%d %H:%M"
989 cd $PKGS
990 rm -f packages.*
991 gettext -e "Creating: packages.list\n"
992 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
993 gettext -e "Creating: packages.md5\n"
994 md5sum *.tazpkg > $PKGS/packages.md5
995 gettext -e "Creating lists from: "; echo "$WOK"
996 cd $WOK
997 for pkg in *
998 do
999 unset_receipt
1000 . $pkg/receipt
1001 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1002 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1003 if [ -s $pkg/taz/*/receipt ]; then
1004 . $pkg/taz/*/receipt
1005 fi
1006 # packages.desc lets us search easily in DB
1007 cat >> $PKGS/packages.desc << EOT
1008 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1009 EOT
1010 # packages.txt used by tazpkg and tazpkg-web also to provide
1011 # a human readable package list with version and description.
1012 cat >> $PKGS/packages.txt << EOT
1013 $PACKAGE
1014 ${VERSION}$EXTRAVERSION
1015 $SHORT_DESC
1016 $PACKED_SIZE ($UNPACKED_SIZE installed)
1018 EOT
1019 # packages.equiv is used by tazpkg install to check depends.
1020 for i in $PROVIDE; do
1021 DEST=""
1022 echo $i | fgrep -q : && DEST="${i#*:}:"
1023 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1024 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1025 $PKGS/packages.equiv
1026 else
1027 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1028 fi
1029 done
1030 # files.list provides a list of all packages files.
1031 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1032 $PKGS/files.list
1033 fi
1034 done
1036 # Display list size.
1037 gettext -e "Done: packages.desc\n"
1038 gettext -e "Done: packages.txt\n"
1039 gettext -e "Done: packages.equiv\n"
1041 # files.list.lzma
1042 gettext -e "Creating: files.list.lzma\n"
1043 cd $PKGS && lzma e files.list files.list.lzma
1044 rm -f files.list
1046 # Display some info.
1047 separator
1048 nb=$(ls $PKGS/*.tazpkg | wc -l)
1049 time=$(($(date +%s) - $time))
1050 echo -e "Packages: $nb - Time: ${time}s\n"
1052 # Create all flavors files at once. Do we really need code to monitor
1053 # flavors changes ? Lets just build them with packages lists before
1054 # syncing the mirror.
1055 [ "$2" == "--flavors" ] || exit 1
1056 [ ! -d "$flavors" ] && echo -e "Missing flavors: $flavors\n" && exit 1
1057 [ -d "$live" ] || mkdir -p $live
1058 gettext "Creating flavors files in:"; echo " $live"
1059 echo "Cook pkgdb: Creating all flavors" | log
1060 separator
1061 gettext -e "Recharging lists to use latest packages...\n"
1062 tazpkg recharge 2>1 >/dev/null
1064 # We need a custom tazlito config to set working dir to /home/slitaz.
1065 if [ ! -f "$live/tazlito.conf" ]; then
1066 echo "Creating configuration file: tazlito.conf"
1067 cp /etc/tazlito/tazlito.conf $live
1068 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1069 $live/tazlito.conf
1070 fi
1072 # Update Hg flavors repo and pack.
1073 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
1075 cd $live
1076 echo "Starting to generate flavors..."
1077 rm -f flavors.list *.flavor
1078 for i in $flavors/*
1079 do
1080 fl=$(basename $i)
1081 echo "Packing flavor: $(basename $i)"
1082 tazlito pack-flavor $fl >/dev/null || exit 1
1083 tazlito show-flavor $fl --brief --noheader 2> \
1084 /dev/null >> flavors.list
1085 done
1086 cp -f $live/*.flavor $live/flavors.list $PKGS
1087 separator && gettext "Flavors size: "; du -sh $live | awk '{print $1}'
1088 echo "" && rm -f $command ;;
1089 *)
1090 # Just cook and generate a package.
1091 check_root
1092 time=$(date +%s)
1093 pkg="$1"
1094 [ -z "$pkg" ] && usage
1095 receipt="$WOK/$pkg/receipt"
1096 check_pkg_in_wok && echo ""
1098 # Skip blocked, 3 lines also for the Cooker.
1099 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1100 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
1101 fi
1103 # Log and source receipt.
1104 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1105 echo "cook:$pkg" > $command
1107 try_aufs_chroot "$@"
1109 # Display and log info if cook process stopped.
1110 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
1111 tee -a $LOGS/$pkg.log' INT
1113 unset inst
1114 unset_receipt
1115 . $receipt
1117 # Handle --options
1118 case "$2" in
1119 --clean|-c)
1120 gettext -e "Cleaning:"; echo -n " $pkg"
1121 cd $WOK/$pkg && rm -rf install taz source
1122 status && echo "" && exit 0 ;;
1123 --install|-i)
1124 inst='yes' ;;
1125 --getsrc|-gs)
1126 gettext "Getting source for:"; echo " $pkg"
1127 separator && get_source
1128 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
1129 --block|-b)
1130 gettext "Blocking:"; echo -n " $pkg"
1131 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1132 status && echo "" && exit 0 ;;
1133 --unblock|-ub)
1134 gettext "Unblocking:"; echo -n " $pkg"
1135 sed -i "/^${pkg}$/"d $blocked
1136 status && echo "" && exit 0 ;;
1138 esac
1140 # Check if wanted is built now so we have separate log files.
1141 if [ "$WANTED" ]; then
1142 if grep -q "^$WANTED$" $blocked; then
1143 echo "WANTED package is blocked: $WANTED" | tee $LOGS/$pkg.log
1144 echo "" && rm -f $command && exit 1
1145 fi
1146 if grep -q "^$WANTED$" $broken; then
1147 echo "WANTED package is broken: $WANTED" | tee $LOGS/$pkg.log
1148 echo "" && rm -f $command && exit 1
1149 fi
1150 if [ ! -d "$WOK/$WANTED/install" ]; then
1151 cook "$WANTED" || exit 1
1152 fi
1153 fi
1155 # Cook and pack or exit on error and log everything.
1156 cookit $@ 2>&1 | tee $LOGS/$pkg.log
1157 remove_deps | tee -a $LOGS/$pkg.log
1158 cookit_quality
1159 packit 2>&1 | tee -a $LOGS/$pkg.log
1160 clean_log
1162 # Exit if any error in packing.
1163 if grep -q ^ERROR $LOGS/$pkg.log; then
1164 debug_info | tee -a $LOGS/$pkg.log
1165 rm -f $command && exit 1
1166 fi
1168 # Time and summary
1169 time=$(($(date +%s) - $time))
1170 summary | tee -a $LOGS/$pkg.log
1171 echo ""
1173 # Install package if requested
1174 if [ "$inst" ]; then
1175 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1176 cd $PKGS && tazpkg install \
1177 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1178 else
1179 gettext -e "Unable to install package, build has failed.\n\n"
1180 exit 1
1181 fi
1182 fi
1183 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1184 # You want automation: use the Cooker Build Bot.
1185 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
1186 rm -f $command ;;
1187 esac
1189 exit 0