cookutils annotate cook @ rev 27

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