cookutils view cook @ rev 624
Fix doc desktop file category
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Dec 22 13:06:10 2013 +0100 (2013-12-22) |
parents | 1769038308f3 |
children | 411b4c392b46 |
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 #
9 . /usr/lib/slitaz/libcook.sh
11 VERSION="3.1.4"
13 # Internationalization.
14 . /usr/bin/gettext.sh
15 TEXTDOMAIN='cook'
16 export TEXTDOMAIN
18 _() echo -e "$(eval_gettext "$1")"
19 _n() echo -en "$(eval_gettext "$1")"
20 # to disable i18n:
21 # _() echo -e "$1"
22 # _n() echo -en "$1"
25 #
26 # Functions
27 #
29 usage() {
30 cat << EOT
32 $(_ "\033[1mUsage:\033[0m cook [package|command] [list|--option]")
34 $(_ "\033[1mCommands:\033[0m")
35 usage|help $(_ "Display this short usage.")
36 setup $(_ "Setup your build environment.")
37 *-setup $(_ "Setup a cross environment.")
38 test $(_ "Test environment and cook a package.")
39 list-wok $(_ "List packages in the wok.")
40 search $(_ "Simple packages search function.")
41 new $(_ "Create a new package with a receipt.")
42 list $(_ "Cook a list of packages.")
43 clean-wok $(_ "Clean-up all packages files.")
44 clean-src $(_ "Clean-up all packages sources.")
45 pkgdb $(_ "Create packages DB lists and flavors.")
47 $(_ "\033[1mOptions:\033[0m")
48 --clean|-c Cook : $(_ "clean the package in the wok.")
49 --install|-i Cook : $(_ "cook and install the package.")
50 --getsrc|-gs Cook : $(_ "get the package source tarball.")
51 --block|-b Cook : $(_ "block a package so cook will skip it.")
52 --unblock|-ub Cook : $(_ "unblock a blocked package.")
53 --cdeps Cook : $(_ "check dependencies of cooked package.")
54 --pack Cook : $(_ "repack an already built package.")
55 --interactive|-x New : $(_ "create a receipt interactively.")
56 --wok Setup: $(_ "clone the cooking wok from Hg repo.")
57 --stable Setup: $(_ "clone the stable wok from Hg repo.")
58 --undigest Setup: $(_ "clone the undigest wok from Hg repo.")
59 --tiny Setup: $(_ "clone the tiny SliTaz wok from Hg repo.")
60 --forced Setup: $(_ "force reinstall of chroot packages.")
61 --flavors Pkgdb: $(_ "create up-to-date flavors files.")
63 EOT
64 exit 0
65 }
67 # We don't want these escapes in web interface.
68 clean_log() {
69 sed -i -e s'|\[70G\[ \[1;32m| |' \
70 -e s'|\[0;39m \]||' $LOGS/$pkg.log
71 }
73 # Be sure package exists in wok.
74 check_pkg_in_wok() {
75 if [ ! -d "$WOK/$pkg" ]; then
76 newline; _ "Unable to find package in the wok: \$pkg"; newline
77 exit 1
78 fi
79 }
81 if_empty_value() {
82 if [ -z "$value" ]; then
83 # L10n: QA is quality assurance
84 _ "QA: empty variable: \${var}=\"\""; newline
85 exit 1
86 fi
87 }
89 # Initialize files used in $CACHE
90 init_db_files() {
91 _ "Creating directories structure in: \$SLITAZ"
92 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
93 _ "Creating DB files in: \$CACHE"
94 for f in $activity $command $broken $blocked
95 do
96 touch $f
97 done
98 }
100 # QA: check a receipt consistency before building.
101 receipt_quality() {
102 _ "QA: checking package receipt..."
103 unset online
104 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
105 online="online"
106 fi
107 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
108 do
109 unset value
110 value="$(. $receipt ; eval echo \$$var)"
111 case "$var" in
112 PACKAGE|VERSION|SHORT_DESC)
113 if_empty_value ;;
114 CATEGORY)
115 [ -z "$value" ] && value="empty"
116 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
117 if ! echo "$valid" | grep -q -w "$value"; then
118 _ "QA: unknown category: \$value"
119 _ "Please, use one of: \$valid" | busybox fold -s
120 newline; exit 1
121 fi ;;
122 WEB_SITE)
123 # We don't check WGET_URL since if dl is needed it will fail.
124 # Break also if we're not online. Here error is not fatal.
125 if_empty_value
126 [ -z "$online" ] || break
127 if ! busybox wget -T 12 -s $value 2>/dev/null; then
128 _ "QA: unable to reach: \$value"
129 fi ;;
130 esac
131 done
132 }
134 # Paths used in receipt and by cook itself.
135 set_paths() {
136 pkgdir=$WOK/$PACKAGE
137 basesrc=$pkgdir/source
138 tmpsrc=$basesrc/tmp
139 src=$basesrc/$PACKAGE-$VERSION
140 taz=$pkgdir/taz
141 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
142 fs=$pack/fs
143 stuff=$pkgdir/stuff
144 install=$pkgdir/install
145 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
146 lzma_tarball="$pkgsrc.tar.lzma"
147 if [ "$PATCH" ]; then
148 [ "${PTARBALL}" ] || PTARBALL="$(basename $PATCH)"
149 fi
150 if [ "$WANTED" ]; then
151 basesrc=$WOK/$WANTED/source
152 src=$basesrc/$WANTED-$VERSION
153 install=$WOK/$WANTED/install
154 wanted_stuff=$WOK/$WANTED/stuff
155 fi
156 if [ "$SOURCE" ]; then
157 source_stuff=$WOK/$SOURCE/stuff
158 fi
159 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
160 if [ -f "$WOK/linux/receipt" ]; then
161 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d '"' -f 2)
162 kbasevers=${kvers:0:3}
163 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
164 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d '"' -f 2)
165 kbasevers=${kvers:0:3}
166 fi
167 # Python version
168 if [ -f "$WOK/python/receipt" ]; then
169 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d '"' -f 2)
170 fi
171 # perl version for some packages needed it
172 if [ -f "$WOK/perl/receipt" ]; then
173 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d '"' -f 2)
174 fi
175 # Old way compatibility.
176 _pkg=$install
177 }
179 # Create source tarball when URL is a SCM.
180 create_tarball() {
181 local tarball
182 tarball=$pkgsrc.tar.bz2
183 [ "$LZMA_SRC" ] && tarball=$lzma_tarball
184 _ "Creating tarball: \$tarball"
185 if [ "$LZMA_SRC" ]; then
186 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
187 LZMA_SRC=""
188 else
189 tar cjf $tarball $pkgsrc || exit 1
190 mv $tarball $SRC && rm -rf $pkgsrc
191 fi
192 TARBALL=$tarball
193 }
195 # Get package source. For SCM we are in cache so clone here and create a
196 # tarball here.
197 get_source() {
198 local url
199 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
200 set_paths
201 pwd=$(pwd)
202 case "$WGET_URL" in
203 http://*|ftp://*)
204 # Busybox Wget is better!
205 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
206 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
207 (_ "ERROR: wget \$WGET_URL" && exit 1) ;;
208 https://*)
209 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
210 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
211 (_ "ERROR: wget \$WGET_URL" && exit 1) ;;
212 hg*|mercurial*)
213 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
214 url=${WGET_URL#hg|}
215 else
216 url=${WGET_URL#mercurial|}
217 fi
218 _ "Getting source from Hg..."
219 _ "URL: \$url"
220 _ "Cloning to: \$pwd/\$pkgsrc"
221 if [ "$BRANCH" ]; then
222 _ "Hg branch: \$BRANCH"
223 hg clone $url --rev $BRANCH $pkgsrc || \
224 (_ "ERROR: hg clone \$url --rev \$BRANCH" && exit 1)
225 else
226 hg clone $url $pkgsrc || (_ "ERROR: hg clone \$url" && exit 1)
227 fi
228 rm -rf $pkgsrc/.hg
229 create_tarball ;;
230 git*)
231 url=${WGET_URL#git|}
232 _ "Getting source from Git..."
233 _ "URL: \$url"
234 git clone $url $pkgsrc || (_ "ERROR: git clone \$url" && exit 1)
235 if [ "$BRANCH" ]; then
236 _ "Git branch: \$BRANCH"
237 cd $pkgsrc && git checkout $BRANCH && cd ..
238 fi
239 create_tarball ;;
240 cvs*)
241 url=${WGET_URL#cvs|}
242 mod=$PACKAGE
243 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
244 _ "Getting source from CVS..."
245 _ "URL: \$url"
246 [ "$CVS_MODULE" ] && _ "CVS module: \$mod"
247 _ "Cloning to: \$pwd/\$mod"
248 cvs -d:$url co $mod && mv $mod $pkgsrc
249 create_tarball ;;
250 svn*|subversion*)
251 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
252 url=${WGET_URL#svn|}
253 else
254 url=${WGET_URL#subversion|}
255 fi
256 _ "Getting source from SVN..."
257 _ "URL: \$url"
258 if [ "$BRANCH" ]; then
259 echo t | svn co $url -r $BRANCH $pkgsrc
260 else
261 echo t | svn co $url $pkgsrc
262 fi
263 create_tarball ;;
264 bzr*)
265 url=${WGET_URL#bzr|}
266 _ "Getting source from bazaar..."
267 cd $SRC
268 pkgsrc=${url#*:}
269 if [ "$BRANCH" ]; then
270 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
271 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
272 else
273 echo "bzr -Ossl.cert_reqs=none branch $url"
274 bzr -Ossl.cert_reqs=none branch $url
275 cd $pkgsrc && BRANCH=$(bzr revno) && cd ..
276 _ "Don't forget to add to receipt:"
277 echo 'BRANCH="'$BRANCH'"'; newline
278 fi
279 mv $pkgsrc $pkgsrc-$BRANCH
280 pkgsrc=$pkgsrc-$BRANCH
281 create_tarball ;;
282 *)
283 (newline; _ "ERROR: Unable to handle: \$WGET_URL"; newline) | \
284 tee -a $LOGS/$PACKAGE.log
285 exit 1 ;;
286 esac
287 }
289 # Extract source package.
290 extract_source() {
291 if [ ! -s "$SRC/$TARBALL" ]; then
292 local url
293 url="$MIRROR_URL/sources/packages"
294 url=$url/${TARBALL:0:1}/$TARBALL
295 _ "Getting source from mirror: \$url"
296 busybox wget -c -P $SRC $url || _ "ERROR: wget \$url"
297 fi
298 _ "Extracting: \$TARBALL"
299 case "$TARBALL" in
300 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
301 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
302 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
303 *.tar) tar xf $SRC/$TARBALL ;;
304 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
305 *.xz) unxz -c $SRC/$TARBALL | tar xf - || tar xf $SRC/$TARBALL 2>/dev/null;;
306 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
307 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
308 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
309 *) cp $SRC/$TARBALL $(pwd) ;;
310 esac
311 }
313 # Display cooked package summary.
314 summary() {
315 cd $WOK/$pkg
316 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
317 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
318 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
319 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
320 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
321 [ "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
322 cookdate=$(date "$(_ '+%Y-%m-%d %H:%M')")
323 sec=$time
324 div=$(( ($time + 30) / 60))
325 # L10n: 'm' is for minutes (approximate cooking time)
326 min=$(_n "~ \${div}m"); [ "$div" = 0 ] && min=""
327 _ "Summary for: \$PACKAGE \$VERSION"
328 separator
329 # L10n: keep the same width of translations to get a consistent view
330 [ "$srcdir" ] && _ "Source dir : \$srcdir"
331 [ "$TARBALL" ] && _ "Src file : \$TARBALL"
332 [ "$srcsize" ] && _ "Src size : \$srcsize"
333 [ "$prod" ] && _ "Produced : \$prod"
334 _ "Packed : \$fs"
335 _ "Compressed : \$size"
336 _ "Files : \$files"
337 # L10n: 's' is for seconds (cooking time)
338 _ "Cook time : \${sec}s \$min"
339 _ "Cook date : \$cookdate"
340 _ "Host arch : \$ARCH"
341 separator
342 }
344 # Display debugging error info.
345 debug_info() {
346 newline; _ "Debug information"; separator
347 # L10n: specify your format of date and time (to help: man date)
348 # L10n: not bad one is '+%x %R'
349 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
350 _ "Cook date: \$datenow"
351 # L10n: Please, translate all messages beginning with ERROR in a same way
352 lerror=$(_n "ERROR")
353 for error in \
354 ERROR $lerror "No package" "cp: can't" "can't open" "can't cd" \
355 "error:" "fatal error:" "undefined reference to" \
356 "Unable to connect to" "link: cannot find the library" \
357 "CMake Error" ": No such file or directory"
358 do
359 fgrep "$error" $LOGS/$pkg.log
360 done
361 separator; newline
362 }
364 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
365 # so some packages need to copy these files with the receipt and genpkg_rules.
366 copy_generic_files()
367 {
368 # $LOCALE is set in cook.conf
369 if [ "$LOCALE" -a "$WANTED" = "" ]; then
370 if [ -d "$install/usr/share/locale" ]; then
371 mkdir -p $fs/usr/share/locale
372 for i in $LOCALE
373 do
374 if [ -d "$install/usr/share/locale/$i" ]; then
375 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
376 fi
377 done
378 fi
379 fi
381 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
382 if [ "$GENERIC_PIXMAPS" != "no" ]; then
383 if [ -d "$install/usr/share/pixmaps" ]; then
384 mkdir -p $fs/usr/share/pixmaps
385 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
386 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
387 $fs/usr/share/pixmaps
388 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
389 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
390 $fs/usr/share/pixmaps
391 fi
392 fi
394 # Custom or homemade PNG pixmap can be in stuff.
395 if [ -f "$stuff/$PACKAGE.png" ]; then
396 mkdir -p $fs/usr/share/pixmaps
397 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
398 fi
399 fi
401 # Desktop entry (.desktop).
402 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
403 if [ "$GENERIC_MENUS" != "no" ]; then
404 if [ -d "$install/usr/share/applications" ] && [ "$WANTED" == "" ]; then
405 mkdir -p $fs/usr/share
406 cp -a $install/usr/share/applications $fs/usr/share
407 fi
408 fi
410 # Homemade desktop file(s) can be in stuff.
411 if [ -d "$stuff/applications" ]; then
412 mkdir -p $fs/usr/share
413 cp -a $stuff/applications $fs/usr/share
414 fi
415 if [ -f "$stuff/$PACKAGE.desktop" ]; then
416 mkdir -p $fs/usr/share/applications
417 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
418 fi
420 # Add custom licenses
421 if [ -d "$stuff/licenses" ]; then
422 mkdir -p $fs/usr/share/licenses
423 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
424 fi
425 }
427 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
428 # as removing uneeded files like in Python packages. Cross compiled binaries
429 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
430 strip_package() {
431 case "$ARCH" in
432 arm|x86_64) export STRIP=${HOST_SYSTEM}-strip ;;
433 *) export STRIP=strip ;;
434 esac
435 _n "Executing strip on all files..."
436 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
437 do
438 if [ -d "$dir" ]; then
439 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
440 fi
441 done
442 find $fs -name "*.so*" -exec $STRIP -s '{}' 2>/dev/null \;
443 find $fs -name "*.a" -exec $STRIP --strip-debug '{}' 2>/dev/null \;
444 status
446 # Remove Python .pyc and .pyo from packages.
447 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
448 _n "Removing Python compiled files..."
449 find $fs -type f -name "*.pyc" -delete 2>/dev/null
450 find $fs -type f -name "*.pyo" -delete 2>/dev/null
451 status
452 fi
454 # Remove Perl perllocal.pod and .packlist from packages.
455 if echo "$DEPENDS" | fgrep -q "perl"; then
456 _n "Removing Perl compiled files..."
457 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
458 find $fs -type f -name ".packlist" -delete 2>/dev/null
459 status
460 fi
461 }
463 # Remove installed deps.
464 remove_deps() {
465 # Now remove installed build deps.
466 diff="/tmp/installed.cook.diff"
467 if [ -s $diff ]; then
468 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
469 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
470 _n "Build dependencies to remove: "; echo $nb $root
471 _n "Removing:"
472 for dep in $deps
473 do
474 echo -n " $dep"
475 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
476 done
477 newline; newline
478 # Keep the last diff for debug and info.
479 mv -f $diff $CACHE/installed.diff
480 fi
481 }
483 # The main cook function.
484 cookit() {
485 _ "Cook: \$PACKAGE \$VERSION"; separator
486 set_paths
488 # Handle cross-tools.
489 case "$ARCH" in
490 arm|x86_64)
491 # CROSS_COMPILE is used by at least Busybox and the kernel to set
492 # the cross-tools prefix. Sysroot is the root of our target arch
493 sysroot=$CROSS_TREE/sysroot
494 tools=$CROSS_TREE/tools
495 # Set root path when cross compiling. ARM tested but not x86_64
496 # When cross compiling we must install build deps in $sysroot.
497 arch="-${ARCH}"
498 root=$sysroot
499 _ "\$ARCH sysroot: \$sysroot"
500 _ "Adding \$tools/bin to PATH"
501 export PATH=$PATH:$tools/bin
502 export PKG_CONFIG_PATH=$sysroot/usr/lib/pkgconfig
503 export CROSS_COMPILE=${HOST_SYSTEM}-
504 _ "Using cross-tools: \$CROSS_COMPILE"
505 if [ "$ARCH" == "x86_64" ]; then
506 export CC="${HOST_SYSTEM}-gcc -m64"
507 export CXX="${HOST_SYSTEM}-g++ -m64"
508 else
509 export CC=${HOST_SYSTEM}-gcc
510 export CXX=${HOST_SYSTEM}-g++
511 fi
512 export AR=${HOST_SYSTEM}-ar
513 export AS=${HOST_SYSTEM}-as
514 export RANLIB=${HOST_SYSTEM}-ranlib
515 export LD=${HOST_SYSTEM}-ld
516 export STRIP=${HOST_SYSTEM}-strip ;;
517 esac
519 [ "$QA" ] && receipt_quality
520 cd $pkgdir
521 rm -rf install taz source 2> /dev/null
523 # Disable -pipe if less than 512Mb free RAM.
524 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
525 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
526 _ "Disabling -pipe compile flag: \$free RAM"
527 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
528 CXXFLAGS="${CXXFLAGS/-pipe}" && \
529 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
530 fi
531 unset free
533 # Export flags and path to be used by make and receipt.
534 DESTDIR=$pkgdir/install
535 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
536 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
537 #LDFLAGS
539 # Check for build deps and handle implicit depends of *-dev packages
540 # (ex: libusb-dev :: libusb).
541 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
542 touch $CACHE/installed.local $CACHE/installed.web
543 [ "$BUILD_DEPENDS" ] && _ "Checking build dependencies..."
544 [ "$root" ] && _ "Using packages DB: \${root}\$DB"
545 for dep in $BUILD_DEPENDS
546 do
547 implicit=${dep%-dev}
548 for i in $dep $implicit
549 do
550 if [ ! -f "${root}$INSTALLED/$i/receipt" ]; then
551 # Try local package first. In some cases implicit doesn't exist, ex:
552 # libboost-dev exists but not libboost, so check if we got vers.
553 unset vers
554 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
555 # We may have a local package.
556 if [ ! "$vers" ]; then
557 vers=$(grep "^$i |" $PKGS/packages.desc | awk '{print $3}')
558 fi
559 debug "bdep: $i version: $vers"
560 if [ -f "$PKGS/$i-${vers}${arch}.tazpkg" ]; then
561 echo $i-${vers}${arch}.tazpkg >> $CACHE/installed.local
562 else
563 # Priority to package version in wok (maybe more up-to-date)
564 # than the mirrored one.
565 if [ "$vers" ]; then
566 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
567 echo $i >> $CACHE/installed.web
568 else
569 # So package exists in wok but not available.
570 _ "Missing dep (wok/pkg): \$i \$vers"
571 echo $i >> $CACHE/missing.dep
572 fi
573 else
574 # Package is not in wok but may be in online repo.
575 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
576 echo $i >> $CACHE/installed.web
577 else
578 _ "ERROR: unknown dep \$i"; exit 1
579 fi
580 fi
581 fi
582 fi
583 done
584 done
586 # Get the list of installed packages
587 cd ${root}$INSTALLED && ls -1 > $CACHE/installed.list
589 # Have we a missing build dep to cook?
590 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
591 _ "Auto cook config is set: AUTO_COOK"
592 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
593 for i in $(uniq $CACHE/missing.dep)
594 do
595 (_ "Building dep (wok/pkg) : \$i \$vers") | \
596 tee -a $LOGS/$PACKAGE.log.$$
597 # programmers: next two messages are exact copy from remove_deps()
598 togrep1=$(_n "Build dependencies to remove: ")
599 togrep2=$(_n "Removing:")
600 cook $i || (_ "ERROR: can't cook dep '\$i'" && newline && \
601 fgrep $togrep1 $LOGS/$i.log && \
602 fgrep $togrep2 $LOGS/$i.log && newline) | \
603 tee -a $LOGS/$PACKAGE.log.$$ && break
604 done
605 rm -f $CACHE/missing.dep
606 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
607 fi
609 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
610 # is enabled and cook fails we have ERROR in log, if no auto cook we have
611 # missing dep in cached file.
612 lerror=$(_n "ERROR")
613 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
614 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
615 _ "ERROR: missing dep \$nb" && exit 1
616 fi
618 # Install local packages: package-version${arch}
619 cd $PKGS
620 for i in $(uniq $CACHE/installed.local)
621 do
622 _ "Installing dep (pkg/local): \$i"
623 tazpkg install $i --root=$root >/dev/null
624 done
626 # Install web or cached packages (if mirror is set to $PKGS we only
627 # use local packages).
628 for i in $(uniq $CACHE/installed.web)
629 do
630 _ "Installing dep (web/cache): \$i"
631 tazpkg get-install $i --root=$root >/dev/null
632 done
634 # If a cook failed deps are removed.
635 cd ${root}$INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
636 [ ! -s "/tmp/installed.cook.diff" ] && \
637 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
638 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
640 # Get source tarball and make sure we have source dir named:
641 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
642 # tarball if it exists.
643 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
644 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
645 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
646 LZMA_SRC=""
647 else
648 get_source || exit 1
649 fi
650 fi
651 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
652 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
653 if ! extract_source ; then
654 get_source
655 extract_source || exit 1
656 fi
657 if [ "$LZMA_SRC" ]; then
658 cd $pkgdir/source
659 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
660 mv tmp tmp-1 && mkdir tmp
661 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
662 fi
663 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
664 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
665 fi
666 fi
667 cd $pkgdir/source/tmp
668 # Some archives are not well done and don't extract to one dir (ex lzma).
669 files=$(ls | wc -l)
670 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
671 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
672 mv * ../$PACKAGE-$VERSION/$TARBALL
673 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
674 mv * ../$PACKAGE-$VERSION
675 cd .. && rm -rf tmp
676 fi
678 # Execute receipt rules.
679 if grep -q ^compile_rules $receipt; then
680 _ "Executing: compile_rules"
681 echo "CFLAGS : $CFLAGS"
682 #echo "LDFLAGS : $LDFLAGS"
683 [ -d "$src" ] && cd $src
684 compile_rules $@ || exit 1
685 # Stay compatible with _pkg
686 [ -d "$src/_pkg" ] && mv $src/_pkg $install
687 # QA: compile_rules success so valid.
688 mkdir -p $install
689 else
690 # QA: no compile_rules so no error, valid.
691 mkdir -p $install
692 fi
693 separator; newline
695 # Execute testsuite.
696 if grep -q ^testsuite $receipt; then
697 _ "Running testsuite"; separator
698 testsuite $@ || exit 1
699 separator; newline
700 fi
701 }
703 # Cook quality assurance.
704 cookit_quality() {
705 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
706 _ "ERROR: cook failed" | tee -a $LOGS/$pkg.log
707 fi
708 # ERROR can be echoed any time in cookit()
709 lerror=$(_n "ERROR")
710 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
711 grep -Eq "(^$lerror|undefined reference to)" ; then
712 debug_info | tee -a $LOGS/$pkg.log
713 rm -f $command && exit 1
714 fi
715 }
717 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
718 # but it doesn't handle EXTRAVERSION.
719 packit() {
720 set_paths
722 # Handle cross compilation
723 case "$ARCH" in
724 arm|x86_64) arch="-$ARCH" ;;
725 esac
727 _ "Pack: \$PACKAGE \${VERSION}\${arch}"; separator
729 if grep -q ^genpkg_rules $receipt; then
730 _ "Executing: genpkg_rules"
731 set -e && cd $pkgdir && mkdir -p $fs
732 genpkg_rules || (newline; _ "ERROR: genpkg_rules failed"; newline) >> \
733 $LOGS/$pkg.log
734 else
735 _ "No packages rules: meta package"
736 mkdir -p $fs
737 fi
739 # First QA check to stop now if genpkg_rules failed.
740 lerror=$(_n "ERROR")
741 if fgrep -q ^$lerror $LOGS/$pkg.log; then
742 exit 1
743 fi
745 cd $taz
746 for file in receipt description.txt
747 do
748 [ ! -f "../$file" ] && continue
749 _n "Copying \$file..."
750 cp -f ../$file $pack && chown 0.0 $pack/$file && status
751 done
752 copy_generic_files
754 # Create files.list with redirecting find output.
755 _n "Creating the list of files..."
756 cd $fs
757 find . -type f -print > ../files.list
758 find . -type l -print >> ../files.list
759 cd .. && sed -i s/'^.'/''/ files.list
760 status
762 # Strip and stuff files.
763 strip_package
765 # Md5sum of files.
766 _n "Creating md5sum of files..."
767 while read file; do
768 [ -L "fs$file" ] && continue
769 [ -f "fs$file" ] || continue
770 case "$file" in
771 /lib/modules/*/modules.*|*.pyc) continue ;;
772 esac
773 md5sum "fs$file" | sed 's/ fs/ /'
774 done < files.list > md5sum
775 status
776 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
777 description.txt 2> /dev/null | awk \
778 '{ sz=$1 } END { print sz }')
780 # Build cpio archives.
781 _n "Compressing the fs..."
782 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
783 rm -rf fs
784 status
785 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
786 md5sum description.txt 2> /dev/null | awk \
787 '{ sz=$1 } END { print sz }')
788 _n "Updating receipt sizes..."
789 sed -i s/^PACKED_SIZE.*$// receipt
790 sed -i s/^UNPACKED_SIZE.*$// receipt
791 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
792 status
794 # Set extra version.
795 if [ "$EXTRAVERSION" ]; then
796 _n "Updating receipt EXTRAVERSION: \$EXTRAVERSION"
797 sed -i s/^EXTRAVERSION.*$// receipt
798 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
799 status
800 fi
802 # Compress.
803 _n "Creating full cpio archive..."
804 find . -print | cpio -o -H newc --quiet > \
805 ../$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg
806 status
807 _n "Restoring original package tree..."
808 unlzma -c fs.cpio.lzma | cpio -idm --quiet
809 status
810 rm fs.cpio.lzma && cd ..
812 # QA and give info.
813 tazpkg=$(ls *.tazpkg)
814 packit_quality
815 separator; _ "Package: \$tazpkg"; newline
816 }
818 # Verify package quality and consistency.
819 packit_quality() {
820 #gettext "QA: checking for broken link..."
821 #link=$(find $fs/usr -type l -follow)
822 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
823 #status
825 # Exit if any error found in log file.
826 lerror=$(_n "ERROR")
827 if fgrep -q ^$lerror $LOGS/$pkg.log; then
828 rm -f $command && exit 1
829 fi
831 _n "QA: checking for empty package..."
832 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
833 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
834 newline; _ "ERROR: empty package"
835 rm -f $command && exit 1
836 else
837 # Ls sort by name so the first file is the one we want.
838 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
839 status
840 if [ -f "$old" ]; then
841 old_pkg=$(basename $old)
842 _n "Removing old: \$old_pkg"
843 rm -f $old && status
844 fi
845 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
846 sed -i /^${pkg}$/d $broken
847 #gettext "Removing source tree..."
848 #rm -f $WOK/$pkg/source && status
849 fi
850 }
852 # Tic tac, tic tac...
853 tac() {
854 sed '1!G;h;$!d' $1
855 }
857 # Install package on --install or update the chroot.
858 install_package() {
859 case "$ARCH" in
860 arm|x86_64)
861 arch="-${ARCH}"
862 root=$CROSS_TREE/sysroot ;;
863 esac
864 # Install package if requested but skip install if target host doesn't
865 # match build system or it will break the build chroot.
866 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
867 if [ "$inst" ] && [ "$build" == "$ARCH" ]; then
868 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
869 cd $PKGS && tazpkg install \
870 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
871 else
872 _ "Unable to install package, build has failed."; newline
873 exit 1
874 fi
875 fi
877 # Install package if part of the chroot to keep env up-to-date.
878 if [ -d "${root}$INSTALLED/$pkg" ]; then
879 . /etc/slitaz/cook.conf
880 . $WOK/$pkg/taz/$pkg-*/receipt
881 _ "Updating \$ARCH chroot environment..."
882 _ "Updating chroot: \$pkg (\${VERSION}\${EXTRAVERSION}\${arch})" | log
883 cd $PKGS && tazpkg install \
884 $pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg \
885 --forced --root=$root
886 fi
887 }
889 # Launch the cook command into a chroot jail protected by aufs.
890 # The current filesystems are used read-only and updates are
891 # stored in a separate branch.
892 try_aufs_chroot() {
894 base=/dev/shm/aufsmnt$$
896 # Can we setup the chroot? Is it already done?
897 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
898 grep -q ^AUFS_NOT_RAMFS $receipt && base=/mnt/aufsmnt$$
899 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
900 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
901 mkdir ${base}root ${base}rw || return
903 _ "Setup aufs chroot..."
905 # Sanity check
906 for i in / /proc /sys /dev/shm /home ; do
907 case " $AUFS_MOUNTS " in
908 *\ $i\ *) ;;
909 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
910 esac
911 done
912 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
913 mount --bind $mnt ${base}root$mnt
914 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
915 _ "Aufs mountage failure"
916 umount ${base}root
917 rmdir ${base}*
918 return
919 fi
920 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
921 done
923 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
924 status=$?
926 _ "Leaving aufs chroot..."
927 tac ${base}rw/aufs-umount.sh | sh
928 rm -rf ${base}rw
929 umount ${base}root
930 rmdir $base*
931 # Dont install pkg twice... it's done after
932 #install_package
933 exit $status
934 }
936 # Create a XML feed for freshly built packages.
937 gen_rss() {
938 pubdate=$(date "+%a, %d %b %Y %X")
939 cat > $FEEDS/$pkg.xml << EOT
940 <item>
941 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
942 <link>${COOKER_URL}?pkg=$PACKAGE</link>
943 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
944 <pubDate>$pubdate</pubDate>
945 <description>$SHORT_DESC</description>
946 </item>
947 EOT
948 }
950 # Truncate stdout log file to $1 Mb.
951 loglimit()
952 {
953 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
954 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
955 else
956 tee /dev/stderr
957 fi
958 }
960 # Search file in mirrored packages
961 search_file_mirror()
962 {
963 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
964 }
966 # Search file in local wok packages
967 search_file_local()
968 {
969 # existing packages have precedence over the package/taz folder
970 srch=$1
971 { for package in $(find $PKGS -name '*.tazpkg'); do
972 if [ ! "x$(busybox cpio --to-stdout --quiet -i files.list < $package | grep /$srch\$)" == "x" ]; then
973 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
974 fi
975 done } | sort -u
976 }
978 # Ask in multiple choice
979 ask_multiple()
980 {
981 local multiples first my_choice
982 multiples="$1"
983 first=$(echo "$multiples" | head -n1)
984 newline; _ "Multiple choice:\n$multiples\n"
985 _ "Select one [$first]: "; read my_choice
986 [ "x$my_choice" == "x" ] && my_choice="$first"
987 found=$my_choice
988 }
990 # Search file in local cache (fast), local wok packages, mirrored packages
991 search_file()
992 {
993 local srch cache missing
994 srch=$1
995 cache=/var/cache/ldsearch.cache
996 missing=/var/cache/missing.file
997 touch $cache $missing
998 found=$(grep $srch $cache | cut -d' ' -f2)
999 if [ "x$found" == "x" ]; then
1000 found=$(search_file_local $srch)
1001 if [ "x$found" != "x" ]; then
1002 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1003 ask_multiple "$found"
1004 fi
1005 echo "$srch $found" >> $cache
1006 else
1007 found=$(search_file_mirror $srch)
1008 if [ "x$found" != "x" ]; then
1009 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1010 ask_multiple "$found"
1011 fi
1012 echo "$srch $found" >> $cache
1013 else
1014 echo "$srch" >> $missing
1015 fi
1016 fi
1017 fi
1018 }
1023 #
1024 # Commands
1025 #
1027 case "$1" in
1028 usage|help|-u|-h)
1029 usage ;;
1030 list-wok)
1031 newline; _ "List of packages in: \$WOK"; separator
1032 cd $WOK && ls -1
1033 separator
1034 pkg_total=$(ls | wc -l)
1035 _ "Packages: \$pkg_total"; newline ;;
1036 activity)
1037 cat $activity ;;
1038 search)
1039 # Just a simple search function, we dont need more actually.
1040 query="$2"
1041 newline; _ "Search results for: \$query"; separator
1042 cd $WOK && ls -1 | grep "$query"
1043 separator; newline ;;
1044 setup)
1045 # Setup a build environment
1046 check_root
1047 _ "Cook: setup environment" | log
1048 newline; _ "Setting up your environment"; separator
1049 cd $SLITAZ
1050 init_db_files
1051 _ "Checking for packages to install..."
1052 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1053 # ARCH-setup or 'cross check-env' should be used before: cook setup
1054 case "$ARCH" in
1055 arm|x86_64)
1056 if [ ! -x "/usr/bin/cross" ]; then
1057 _ "ERROR: cross is not installed"
1058 exit 1
1059 fi
1060 _ "Using config file: /etc/slitaz/cross.conf"
1061 . /etc/slitaz/cross.conf ;;
1062 esac
1063 for pkg in $SETUP_PKGS; do
1064 if [ "$forced" ]; then
1065 tazpkg -gi $pkg --forced
1066 else
1067 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
1068 fi
1069 done
1071 # Handle --options
1072 case "$2" in
1073 --wok)
1074 hg clone $WOK_URL wok || exit 1 ;;
1075 --stable)
1076 hg clone $WOK_URL-stable wok || exit 1 ;;
1077 --undigest)
1078 hg clone $WOK_URL-undigest wok || exit 1 ;;
1079 --tiny)
1080 hg clone $WOK_URL-tiny wok || exit 1 ;;
1081 esac
1083 # SliTaz group and permissions
1084 if ! grep -q ^slitaz /etc/group; then
1085 _ "Adding group: slitaz"
1086 addgroup slitaz
1087 fi
1088 _ "Setting permissions for slitaz group..."
1089 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1090 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1091 separator; _ "All done, ready to cook packages :-)"; newline ;;
1092 *-setup)
1093 # Setup for cross compiling.
1094 arch=${1%-setup}
1095 check_root
1096 _ "Cook: setup \$arch cross environment" | log
1097 newline; boldify $(_n "Setting up your \$arch cross environment"); separator
1098 init_db_files
1099 sed -i \
1100 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1101 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1102 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1103 /etc/slitaz/cook.conf
1104 case "$arch" in
1105 arm)
1106 sed -i \
1107 -e s'/CFLAGS=.*/CFLAGS="-march=armv6 -O2"/' \
1108 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux-gnueabi/' \
1109 -e s'/xorg-dev/""/' \
1110 /etc/slitaz/cook.conf ;;
1111 x86_64)
1112 sed -i \
1113 -e s'/CFLAGS=.*/CFLAGS=""/' \
1114 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux/' \
1115 /etc/slitaz/cook.conf ;;
1116 esac
1117 . /etc/slitaz/cook.conf
1118 sysroot=$CROSS_TREE/sysroot
1119 tools=/cross/$arch/tools
1120 root=$sysroot
1121 CC=$tools/bin/${HOST_SYSTEM}-gcc
1122 # L10n: keep the same width of translations to get a consistent view
1123 _ "Target arch : \$ARCH"
1124 _ "Configure args : \$CONFIGURE_ARGS"
1125 _ "Arch sysroot : \$sysroot"
1126 _ "Tools prefix : \$tools/bin"
1127 # Tell the packages manager where to find packages.
1128 _ "Packages DB : \${root}\$DB"
1129 mkdir -p ${root}$INSTALLED
1130 cd ${root}$DB && rm -f *.bak
1131 for list in packages.list packages.desc packages.equiv packages.md5
1132 do
1133 rm -f $list && ln -s $SLITAZ/packages/$list $list
1134 done
1135 # We must have the cross compiled glibc-base installed or default
1136 # i486 package will be used as dep by tazpkg and then break the
1137 # cross environment
1138 if [ ! -f "${root}$INSTALLED/glibc-base/receipt" ]; then
1139 colorize 36 $(_ "WARNING: (e)glibc-base is not installed in sysroot")
1140 fi
1141 # Show GCC version or warn if not yet compiled.
1142 if [ -x $CC ]; then
1143 _ "Cross compiler : \${HOST_SYSTEM}-gcc"
1144 else
1145 colorize 36 $(_ "C compiler is missing: \${HOST_SYSTEM}-gcc")
1146 _ "Run 'cross compile' to cook a toolchain"
1147 fi
1148 separator; newline ;;
1149 test)
1150 # Test a cook environment.
1151 _ "Cook test: testing the cook environment" | log
1152 [ ! -d "$WOK" ] && exit 1
1153 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1154 cook cooktest ;;
1155 new)
1156 # Create the package folder and an empty receipt.
1157 pkg="$2"
1158 [ "$pkg" ] || usage
1159 newline
1160 if [ -d "$WOK/$pkg" ]; then
1161 _ "\$pkg package already exists."
1162 exit 1
1163 fi
1164 _n "Creating \$WOK/\$pkg"
1165 mkdir $WOK/$pkg && cd $WOK/$pkg && status
1166 _n "Preparing the package receipt..."
1167 cp $DATA/receipt .
1168 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1169 status && newline
1171 # Interactive mode, asking and seding.
1172 case "$3" in
1173 --interactive|-x)
1174 _ "Entering interactive mode..."
1175 separator
1176 _ "Package : \$pkg"
1177 _n "Version : " ; read answer
1178 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1179 _n "Category : " ; read answer
1180 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1181 # L10n: Short description
1182 _n "Short desc : " ; read answer
1183 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1184 _n "Maintainer : " ; read answer
1185 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1186 _n "License : " ; read answer
1187 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1188 _n "Web site : " ; read answer
1189 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1190 newline
1191 # Wget URL.
1192 _ "Wget URL to download source tarball."
1193 _n "Example : " ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1194 _n "Wget url : " ; read answer
1195 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$answer\""# receipt
1196 # Ask for a stuff dir.
1197 _n "Do you need a stuff directory? (y/N) : " ; read answer
1198 if [ "$answer" = "y" ]; then
1199 _n "Creating the stuff directory..."
1200 mkdir $WOK/$pkg/stuff && status
1201 fi
1202 # Ask for a description file.
1203 _n "Are you going to write a description? (y/N) : " ; read answer
1204 if [ "$answer" = "y" ]; then
1205 _n "Creating the description.txt file..."
1206 newline > $WOK/$pkg/description.txt && status
1207 fi
1208 separator; _ "Receipt is ready to use."; newline ;;
1209 esac ;;
1210 list)
1211 # Cook a list of packages (better use the Cooker since it will order
1212 # packages before executing cook).
1213 check_root
1214 [ -z "$2" ] && (newline; _ "No list in argument."; newline) && exit 1
1215 list2=$2
1216 [ ! -f "$2" ] && (newline; _ "No list found: \$list2"; newline) && exit 1
1217 _ "Cook list starting: \$list2" | log
1218 for pkg in $(cat $2)
1219 do
1220 cook $pkg || broken
1221 done ;;
1222 clean-wok)
1223 check_root
1224 newline; _n "Cleaning all packages files..."
1225 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1226 status; newline ;;
1227 clean-src)
1228 check_root
1229 newline; _n "Cleaning all packages sources..."
1230 rm -rf $WOK/*/source
1231 status; newline ;;
1232 pkgdb)
1233 # Create suitable packages list for TazPKG and only for built packages
1234 # as well as flavors files for TazLiTo. We dont need logs since we do it
1235 # manually to ensure everything is fine before syncing the mirror.
1236 case "$2" in
1237 --flavors)
1238 continue ;;
1239 *)
1240 [ "$2" ] && PKGS="$2"
1241 [ ! -d "$PKGS" ] && \
1242 newline && _ "Packages directory doesn't exist" && \
1243 newline && exit 1 ;;
1244 esac
1245 time=$(date +%s)
1246 flavors=$SLITAZ/flavors
1247 live=$SLITAZ/live
1248 echo "cook:pkgdb" > $command
1249 _ "Cook pkgdb: Creating all packages lists" | log
1250 newline; _ "Creating lists for: \$PKGS"; separator
1251 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
1252 _ "Cook pkgdb started: \$datenow"
1253 cd $PKGS
1254 rm -f packages.*
1255 _ "Creating: packages.list"
1256 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1257 _ "Creating: packages.md5"
1258 md5sum *.tazpkg > $PKGS/packages.md5
1259 md5sum packages.md5 | cut -f1 -d' ' > ID
1260 _ "Creating lists from: \$WOK"
1261 cd $WOK
1262 for pkg in *
1263 do
1264 unset_receipt
1265 . $pkg/receipt
1266 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1267 if [ -s $pkg/taz/*/receipt ]; then
1268 . $pkg/taz/*/receipt
1269 fi
1270 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1271 # packages.desc lets us search easily in DB
1272 cat >> $PKGS/packages.desc << EOT
1273 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1274 EOT
1275 # packages.txt used by tazpkg and tazpkg-web also to provide
1276 # a human readable package list with version and description.
1277 cat >> $PKGS/packages.txt << EOT
1278 $PACKAGE
1279 ${VERSION}$EXTRAVERSION
1280 $SHORT_DESC
1281 $PACKED_SIZE ($UNPACKED_SIZE installed)
1283 EOT
1284 # packages.equiv is used by tazpkg install to check depends.
1285 for i in $PROVIDE; do
1286 DEST=""
1287 echo $i | fgrep -q : && DEST="${i#*:}:"
1288 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1289 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1290 $PKGS/packages.equiv
1291 else
1292 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1293 fi
1294 done
1295 # files.list provides a list of all packages files.
1296 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1297 $PKGS/files.list
1298 fi
1299 done
1301 # Display list size.
1302 _ "Done: packages.desc"
1303 _ "Done: packages.txt"
1304 _ "Done: packages.equiv"
1306 # files.list.lzma
1307 _ "Creating: files.list.lzma"
1308 cd $PKGS && lzma e files.list files.list.lzma
1309 rm -f files.list
1311 # Display some info.
1312 separator
1313 nb=$(ls $PKGS/*.tazpkg | wc -l)
1314 time=$(($(date +%s) - $time))
1315 # L10n: 's' is for seconds (cooking time)
1316 _ "Packages: \$nb - Time: \${time}s"; newline
1318 # Create all flavors files at once. Do we really need code to monitor
1319 # flavors changes? Lets just build them with packages lists before
1320 # syncing the mirror.
1321 [ "$2" == "--flavors" ] || exit 1
1322 [ ! -d "$flavors" ] && (_ "Missing flavors: \$flavors"; newline) && exit 1
1323 [ -d "$live" ] || mkdir -p $live
1324 _ "Creating flavors files in: \$live"
1325 _ "Cook pkgdb: Creating all flavors" | log
1326 separator
1327 _ "Recharging lists to use latest packages..."
1328 tazpkg recharge >/dev/null 2>/dev/null
1330 # We need a custom tazlito config to set working dir to /home/slitaz.
1331 if [ ! -f "$live/tazlito.conf" ]; then
1332 _ "Creating configuration file: tazlito.conf"
1333 cp /etc/tazlito/tazlito.conf $live
1334 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1335 $live/tazlito.conf
1336 fi
1338 # Update Hg flavors repo and pack.
1339 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
1341 cd $live
1342 _ "Starting to generate flavors..."
1343 rm -f flavors.list *.flavor
1344 for i in $flavors/*
1345 do
1346 fl=$(basename $i)
1347 _ "Packing flavor: \$fl"
1348 tazlito pack-flavor $fl >/dev/null || exit 1
1349 tazlito show-flavor $fl --brief --noheader 2> \
1350 /dev/null >> flavors.list
1351 done
1352 cp -f $live/*.flavor $live/flavors.list $PKGS
1353 separator
1354 fl_size=$(du -sh $live | awk '{print $1}')
1355 _ "Flavors size: \$fl_size"; newline
1356 rm -f $command
1357 separator
1358 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
1359 _ "Cook pkgdb end: \$datenow" ;;
1360 *)
1361 # Just cook and generate a package.
1362 check_root
1363 time=$(date +%s)
1364 pkg="$1"
1365 [ -z "$pkg" ] && usage
1366 receipt="$WOK/$pkg/receipt"
1367 check_pkg_in_wok && newline
1369 unset inst
1370 unset_receipt
1371 . $receipt
1373 # Handle cross compilation.
1374 #
1375 # CROSS_NOTE: Actually we are running an ARM cooker but running
1376 # the cooker and build each commit in wok is not possible since
1377 # we dont cook the full wok for this arch. For ARM we need a set
1378 # of packages to handle a touch screen desktop, servers but not
1379 # erlang.
1380 #
1381 # The temporary solution is to build only reviewed and tested
1382 # packages with HOST_ARCH set in receipt.
1383 case "$ARCH" in
1384 arm)
1385 if [ ! "$HOST_ARCH" ]; then
1386 _ "cook: HOST_ARCH is not set in \$pkg receipt"
1387 _ "cook: This package is not included in: \$ARCH"
1388 [ "$CROSS_BUGS" ] && _ "bugs: \$CROSS_BUGS"
1389 _ "Cook skip: \$pkg is not included in: \$ARCH" | log
1390 newline && exit 1
1391 fi ;;
1392 esac
1394 # Some packages are not included in some arch or fail to cross compile.
1395 : ${HOST_ARCH=i486}
1396 if ! $(echo "$HOST_ARCH" | fgrep -q $ARCH); then
1397 _ "cook: HOST_ARCH=\$HOST_ARCH"
1398 _ "cook: \$pkg doesn't cook or is not included in: \$ARCH"
1399 [ "$CROSS_BUGS" ] && _ "bugs: \$CROSS_BUGS"
1400 _ "Cook skip: \$pkg doesn't cook or is not included in: \$ARCH" | log
1401 newline && exit 1
1402 fi
1404 # Skip blocked, 3 lines also for the Cooker.
1405 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1406 _ "Blocked package: \$pkg"; newline
1407 exit 0
1408 fi
1410 try_aufs_chroot "$@"
1412 # Log and source receipt.
1413 _ "Cook started for: <a href='cooker.cgi?pkg=\$pkg'>\$pkg</a>" | log
1414 echo "cook:$pkg" > $command
1416 # Display and log info if cook process stopped.
1417 # FIXME: gettext not worked (in single quotes) here!
1418 trap '_ "\n\nCook stopped: control-C\n\n" | \
1419 tee -a $LOGS/$pkg.log' INT
1421 # Handle --options
1422 case "$2" in
1423 --clean|-c)
1424 _n "Cleaning: \$pkg"
1425 cd $WOK/$pkg && rm -rf install taz source
1426 status && newline && exit 0 ;;
1427 --install|-i)
1428 inst='yes' ;;
1429 --getsrc|-gs)
1430 _ "Getting source for: \$pkg"; separator
1431 get_source
1432 _ "Tarball: \$SRC/\$TARBALL"; newline
1433 exit 0 ;;
1434 --block|-b)
1435 _n "Blocking: \$pkg"
1436 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1437 status && newline && exit 0 ;;
1438 --unblock|-ub)
1439 _n "Unblocking: \$pkg"
1440 sed -i "/^${pkg}$/"d $blocked
1441 status && newline && exit 0 ;;
1442 --pack)
1443 if [ -d $WOK/$pkg/taz ]; then
1444 rm -rf $WOK/$pkg/taz
1445 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1446 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1447 clean_log
1448 else
1449 _ "Need to build \$pkg." && exit 0
1450 fi
1451 exit 0 ;;
1452 --cdeps)
1453 [ ! -d $WOK/$pkg/taz ] && _ "Need to build \$pkg." && exit 0
1454 _ "Checking depends"; separator
1455 lddlist=/tmp/lddlist; touch $lddlist
1456 missing=/var/cache/missing.file
1457 # find all deps using ldd
1458 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1459 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1460 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1461 done
1462 # remove exe/so duplicates
1463 sort -u $lddlist > $lddlist.sorted
1464 # search packages
1465 for exefile in $(cat $lddlist.sorted); do
1466 search_file $exefile
1467 echo $found >> $lddlist.pkgs
1468 echo -n "."
1469 done
1470 echo
1471 # remove packages duplicates
1472 sort -u $lddlist.pkgs > $lddlist.final
1473 sort -u $missing > $missing.final
1474 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1475 exit 0 ;;
1476 esac
1478 # Check if wanted is built now so we have separate log files.
1479 for wanted in $WANTED ; do
1480 if grep -q "^$wanted$" $blocked; then
1481 _ "WANTED package is blocked: \$wanted" | tee $LOGS/$pkg.log
1482 newline && rm -f $command && exit 1
1483 fi
1484 if grep -q "^$wanted$" $broken; then
1485 _ "WANTED package is broken: \$wanted" | tee $LOGS/$pkg.log
1486 newline && rm -f $command && exit 1
1487 fi
1488 if [ ! -d "$WOK/$wanted/install" ]; then
1489 cook "$wanted" || exit 1
1490 fi
1491 done
1493 # Cook and pack or exit on error and log everything.
1494 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1495 remove_deps | tee -a $LOGS/$pkg.log
1496 cookit_quality
1497 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1498 clean_log
1500 # Exit if any error in packing.
1501 lerror=$(_n "ERROR")
1502 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1503 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors)"; then
1504 debug_info | tee -a $LOGS/$pkg.log
1505 rm -f $command && exit 1
1506 fi
1508 # Create an XML feed
1509 gen_rss
1511 # Time and summary
1512 time=$(($(date +%s) - $time))
1513 summary | tee -a $LOGS/$pkg.log
1514 newline
1516 # We may want to install/update.
1517 install_package
1519 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1520 # You want automation: use the Cooker Build Bot.
1521 rm -f $command ;;
1522 esac
1524 exit 0