cookutils annotate cook @ rev 34

cook: improve debug info and function
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 06 19:12:33 2011 +0200 (2011-05-06)
parents 62bf9ac888b1
children e1a3c5900648
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@29 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@34 225 for error in ERROR "No package" "cp: can't stat" "can't open"
pankso@34 226 do
pankso@34 227 fgrep "$error" $LOGS/$pkg.log
pankso@34 228 done
pankso@15 229 separator && echo ""
pankso@15 230 }
pankso@15 231
pankso@1 232 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
pankso@1 233 # so some packages need to copy these files with the receipt and genpkg_rules.
pankso@1 234 copy_generic_files()
pankso@1 235 {
pankso@1 236 # $LOCALE is set in cook.conf
pankso@1 237 if [ "$LOCALE" ]; then
pankso@1 238 if [ -d "$_pkg/usr/share/locale" ]; then
pankso@1 239 mkdir -p $fs/usr/share/locale
pankso@1 240 for i in $LOCALE
pankso@1 241 do
pankso@1 242 if [ -d "$_pkg/usr/share/locale/$i" ]; then
pankso@1 243 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
pankso@1 244 fi
pankso@1 245 done
pankso@1 246 fi
pankso@1 247 fi
pankso@1 248
pankso@1 249 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
pankso@1 250 if [ "$GENERIC_PIXMAPS" != "no" ]; then
pankso@1 251 if [ -d "$_pkg/usr/share/pixmaps" ]; then
pankso@1 252 mkdir -p $fs/usr/share/pixmaps
pankso@1 253 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
pankso@1 254 $fs/usr/share/pixmaps 2>/dev/null
pankso@1 255 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
pankso@1 256 $fs/usr/share/pixmaps 2>/dev/null
pankso@1 257 fi
pankso@1 258
pankso@1 259 # Custom or homemade PNG pixmap can be in stuff.
pankso@1 260 if [ -f "$stuff/$PACKAGE.png" ]; then
pankso@1 261 mkdir -p $fs/usr/share/pixmaps
pankso@1 262 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
pankso@1 263 fi
pankso@1 264 fi
pankso@1 265
pankso@1 266 # Desktop entry (.desktop).
pankso@1 267 if [ -d "$_pkg/usr/share/applications" ]; then
pankso@1 268 cp -a $_pkg/usr/share/applications $fs/usr/share
pankso@1 269 fi
pankso@1 270
pankso@1 271 # Homemade desktop file(s) can be in stuff.
pankso@1 272 if [ -d "$stuff/applications" ]; then
pankso@1 273 mkdir -p $fs/usr/share
pankso@1 274 cp -a $stuff/applications $fs/usr/share
pankso@1 275 fi
pankso@1 276 if [ -f "$stuff/$PACKAGE.desktop" ]; then
pankso@1 277 mkdir -p $fs/usr/share/applications
pankso@1 278 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
pankso@1 279 fi
pankso@1 280 }
pankso@1 281
pankso@1 282 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
pankso@1 283 strip_package()
pankso@1 284 {
pankso@1 285 gettext "Executing strip on all files"
pankso@1 286 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
pankso@1 287 do
pankso@1 288 if [ -d "$dir" ]; then
pankso@1 289 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
pankso@1 290 fi
pankso@1 291 done
pankso@1 292 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
pankso@1 293 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
pankso@1 294 status
pankso@1 295 }
pankso@1 296
pankso@8 297 # Remove installed deps.
pankso@8 298 remove_deps() {
pankso@8 299 # Now remove installed build deps.
pankso@9 300 diff="$CACHE/installed.diff"
pankso@9 301 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
pankso@9 302 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
pankso@8 303 if [ -s "$CACHE/installed.diff" ]; then
pankso@8 304 gettext "Build dependencies to remove:"; echo " $nb"
pankso@8 305 gettext "Removing:"
pankso@8 306 for dep in $deps
pankso@8 307 do
pankso@8 308 echo -n " $dep"
pankso@8 309 yes | tazpkg remove $dep >/dev/null
pankso@8 310 done
pankso@16 311 echo -e "\n"
pankso@8 312 mv -f $CACHE/installed.diff $CACHE/installed.last.diff
pankso@1 313 fi
pankso@1 314 }
pankso@1 315
pankso@1 316 # The main cook function.
pankso@1 317 cookit() {
pankso@11 318 echo "Cook: $PACKAGE $VERSION"
pankso@9 319 separator
pankso@1 320 set_paths
pankso@9 321 [ "$QA" ] && receipt_quality
pankso@33 322 rm -rf install taz source
pankso@1 323
pankso@1 324 # Disable -pipe if less than 512Mb free RAM.
pankso@1 325 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
pankso@1 326 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
pankso@1 327 gettext -e "Disabling -pipe compile flag: $free RAM\n"
pankso@1 328 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
pankso@1 329 CXXFLAGS="${CXXFLAGS/-pipe}" && CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
pankso@1 330 fi
pankso@1 331 unset free
pankso@1 332
pankso@1 333 # Export flags and path to be used by make
pankso@1 334 DESTDIR=$WOK/$PACKAGE/install
pankso@1 335 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS BUILD_HOST CONFIG_SITE
pankso@1 336 local LC_ALL=POSIX LANG=POSIX
pankso@1 337
pankso@1 338 # Check for build dep.
pankso@1 339 cd $INSTALLED && ls -1 > $CACHE/installed.list
pankso@1 340 [ "$DEPENDS" ] && gettext -e "Checking build dependencies...\n"
pankso@1 341 for dep in $BUILD_DEPENDS
pankso@1 342 do
pankso@1 343 if [ ! -d "$INSTALLED/$dep" ]; then
pankso@1 344 # Try local package first
pankso@1 345 if [ -f "$PKGS/$dep-*.tazpkg" ]; then
pankso@1 346 gettext "Installing dep (local):"; echo " $dep"
pankso@1 347 cd $PKGS && tazpkg install $dep-*.tazpkg >/dev/null
pankso@1 348 else
pankso@1 349 gettext "Installing dep (web/cache):"; echo " $dep"
pankso@1 350 tazpkg get-install $dep >/dev/null
pankso@1 351 fi
pankso@1 352 fi
pankso@1 353 done
pankso@1 354 ls -1 > $CACHE/installed.cook && cd $CACHE
pankso@8 355
pankso@8 356 # If a cook failed deps are not remove since we exit 1.
pankso@8 357 [ ! -s "installed.diff" ] && \
pankso@8 358 diff installed.list installed.cook > installed.diff
pankso@8 359 deps=$(cat installed.diff | grep ^+[a-zA-Z0-9] | wc -l)
pankso@1 360
pankso@1 361 # Get source tarball and make sure we have source dir named:
pankso@1 362 # $PACKAGE-$VERSION to be standard in receipts. Her we use tar.lzma
pankso@1 363 # tarball if it exist.
pankso@1 364 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
pankso@1 365 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
pankso@10 366 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
pankso@1 367 else
pankso@1 368 get_source || exit 1
pankso@1 369 fi
pankso@1 370 fi
pankso@9 371 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
pankso@1 372 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
pankso@1 373 extract_source || exit 1
pankso@1 374 mv * ../$PACKAGE-$VERSION
pankso@1 375 cd .. && rm -rf tmp
pankso@1 376 fi
pankso@1 377
pankso@9 378 # Execute receipt rules.
pankso@1 379 if grep -q ^compile_rules $pkgdir/receipt; then
pankso@1 380 gettext -e "Executing: compile_rules\n"
pankso@9 381 [ -d "$src" ] && cd $src
pankso@33 382 compile_rules || echo "" && exit 1
pankso@10 383 # Stay compatible with _pkg
pankso@10 384 [ -d $src/_pkg ] && mv $src/_pkg $install
pankso@9 385 # QA: compile_rules success so valid.
pankso@9 386 mkdir -p $install
pankso@9 387 else
pankso@9 388 # QA: No compile_rules so no error, valid.
pankso@9 389 mkdir -p $install
pankso@1 390 fi
pankso@1 391 separator && echo ""
pankso@1 392 }
pankso@1 393
pankso@1 394 # Cook quality assurance.
pankso@1 395 cookit_quality() {
pankso@9 396 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
pankso@15 397 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
pankso@9 398 fi
pankso@9 399 # ERROR can be echoed any time in cookit()
pankso@33 400 if fgrep -q ERROR: $LOGS/$pkg.log; then
pankso@17 401 debug_info | tee -a $LOGS/$pkg.log
pankso@33 402 rm -f $command && exit 1
pankso@1 403 fi
pankso@1 404 }
pankso@1 405
pankso@16 406 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
pankso@16 407 # but it dont handle EXTRAVERSION.
pankso@1 408 packit() {
pankso@1 409 set_paths
pankso@16 410 echo "Packing: $PACKAGE $VERSION"
pankso@1 411 separator
pankso@16 412 if grep -q ^genpkg_rules $pkgdir/receipt; then
pankso@16 413 gettext -e "Executing: genpkg_rules\n"
pankso@16 414 cd $pkgdir
pankso@33 415 mkdir -p $fs && genpkg_rules || (echo -e \
pankso@33 416 "\nERROR: genpkg_rules failed\n" >> $LOGS/$pkg.log && exit 1)
pankso@16 417 fi
pankso@33 418 packit_quality
pankso@1 419 cd $pkgdir/taz
pankso@1 420 strip_package
pankso@1 421 for file in receipt description.txt
pankso@1 422 do
pankso@1 423 [ ! -f "../$file" ] && continue
pankso@1 424 gettext "Copying"; echo -n " $file..."
pankso@1 425 cp -f ../$file $pack && chown 0.0 $pack/$file && status
pankso@1 426 done
pankso@1 427 copy_generic_files
pankso@16 428
pankso@16 429 # Create files.list with redirecting find outpout.
pankso@16 430 gettext "Creating the list of files..." && cd $fs
pankso@16 431 find . -type f -print > ../files.list
pankso@16 432 find . -type l -print >> ../files.list
pankso@16 433 cd .. && sed -i s/'^.'/''/ files.list
pankso@16 434 status
pankso@16 435 gettext "Creating md5sum of files..."
pankso@16 436 while read file; do
pankso@16 437 [ -L "fs$file" ] && continue
pankso@16 438 [ -f "fs$file" ] || continue
pankso@16 439 case "$file" in
pankso@16 440 /lib/modules/*/modules.*|*.pyc) continue;;
pankso@16 441 esac
pankso@16 442 md5sum "fs$file" | sed 's/ fs/ /'
pankso@16 443 done < files.list > md5sum
pankso@16 444 status
pankso@16 445 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
pankso@16 446 description.txt 2> /dev/null | awk \
pankso@16 447 '{ sz=$1 } END { print sz }')
pankso@16 448
pankso@16 449 # Build cpio archives.
pankso@16 450 gettext "Compressing the fs... "
pankso@16 451 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
pankso@16 452 rm -rf fs
pankso@16 453 status
pankso@16 454 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
pankso@16 455 md5sum description.txt 2> /dev/null | awk \
pankso@16 456 '{ sz=$1 } END { print sz }')
pankso@16 457 gettext "Updating receipt sizes..."
pankso@16 458 sed -i s/^PACKED_SIZE.*$// receipt
pankso@16 459 sed -i s/^UNPACKED_SIZE.*$// receipt
pankso@16 460 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
pankso@16 461 status
pankso@16 462
pankso@16 463 # Set extra version.
pankso@16 464 if [ "$EXTRAVERSION" ]; then
pankso@16 465 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
pankso@16 466 sed -i s/^EXTRAVERSION.*$// receipt
pankso@16 467 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
pankso@16 468 status
pankso@16 469 fi
pankso@16 470
pankso@16 471 # Compress.
pankso@16 472 gettext "Creating full cpio archive... "
pankso@16 473 find . -print | cpio -o -H newc --quiet > \
pankso@16 474 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
pankso@16 475 status
pankso@16 476 gettext "Restoring original package tree... "
pankso@16 477 unlzma -c fs.cpio.lzma | cpio -idm --quiet
pankso@16 478 status
pankso@16 479 rm fs.cpio.lzma && cd ..
pankso@16 480 separator && gettext "Package: "
pankso@16 481 du -sh $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
pankso@16 482 echo ""
pankso@1 483 }
pankso@1 484
pankso@8 485 # Verify package quality and consitensy.
pankso@8 486 packit_quality() {
pankso@33 487 if fgrep -q ERROR: $LOGS/$pkg.log; then
pankso@32 488 rm -f $command && exit 1
pankso@8 489 fi
pankso@8 490 if ! grep -q ^/ $WOK/$pkg/taz/$pkg-*/files.list; then
pankso@32 491 echo -e "ERROR: empty package\n" | tee -a $LOGS/$pkg.log
pankso@32 492 rm -f $command && exit 1
pankso@8 493 else
pankso@8 494 mv -f $WOK/$pkg/taz/$pkg-*.tazpkg $PKGS
pankso@11 495 sed -i /^${pkg}$/d $broken
pankso@8 496 fi
pankso@8 497 }
pankso@8 498
pankso@1 499 #
pankso@1 500 # Commands
pankso@1 501 #
pankso@1 502
pankso@1 503 case "$1" in
pankso@32 504 usage|help|-u|-h)
pankso@1 505 usage ;;
pankso@1 506 list-wok)
pankso@1 507 gettext "List of packages in:"; echo " $WOK"
pankso@1 508 separator
pankso@1 509 cd $WOK && ls -1
pankso@1 510 separator
pankso@1 511 echo -n "Packages: " && ls | wc -l
pankso@1 512 echo "" ;;
pankso@1 513 setup)
pankso@1 514 # Setup a build environment
pankso@1 515 check_root
pankso@11 516 echo "Cook: setting up the environment" | log
pankso@1 517 gettext -e "\nSetting up your environment\n"
pankso@1 518 separator && cd $SLITAZ
pankso@1 519 gettext "Creating directories structure in:"; echo " $SLITAZ"
pankso@1 520 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS
pankso@1 521 gettext -e "Checking for packages to install...\n"
pankso@29 522 for pkg in $SETUP_PKGS
pankso@1 523 do
pankso@1 524 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
pankso@1 525 done
pankso@1 526
pankso@1 527 # Handle --options
pankso@1 528 case "$2" in
pankso@1 529 --wok)
pankso@1 530 [ ! -d "$INSTALLED/mercurial" ] && tazpkg get-install mercurial
pankso@1 531 [ -d "$WOK" ] && echo -e "A wok already exist.\n" && exit 1
pankso@1 532 hg clone $HG_URL ;;
pankso@1 533 --chroot)
pankso@1 534 echo "TODO: create a chroot with tazdev" ;;
pankso@1 535 esac
pankso@1 536
pankso@1 537 # SliTaz group and permissions
pankso@1 538 if ! grep -q ^slitaz /etc/group; then
pankso@1 539 gettext -e "Adding group: slitaz\n"
pankso@1 540 addgroup slitaz
pankso@1 541 fi
pankso@1 542 gettext -e "Setting permissions for slitaz group...\n"
pankso@1 543 chown -R root.slitaz $SLITAZ
pankso@1 544 chmod -R g+w $SLITAZ
pankso@1 545 separator
pankso@1 546 gettext -e "All done, ready to cook packages :-)\n\n" ;;
pankso@9 547 test)
pankso@9 548 # Test a cook environment.
pankso@13 549 echo "Cook test: testing the cook environment" | log
pankso@9 550 [ ! -d "$WOK" ] && exit 1
pankso@9 551 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
pankso@9 552 cook cooktest ;;
pankso@1 553 new)
pankso@1 554 # Create the package folder and an empty receipt.
pankso@1 555 pkg="$2"
pankso@1 556 [ "$pkg" ] || usage
pankso@1 557 echo ""
pankso@1 558 if [ -d "$WOK/$pkg" ]; then
pankso@1 559 echo -n "$pkg " && gettext "package already exist."
pankso@1 560 echo -e "\n" && exit 1
pankso@1 561 fi
pankso@1 562 gettext "Creating"; echo -n " $WOK/$pkg"
pankso@1 563 mkdir $WOK/$pkg && cd $WOK/$pkg && status
pankso@1 564 gettext "Preparing the package receipt..."
pankso@1 565 cp $DATA/receipt .
pankso@1 566 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
pankso@1 567 status && echo "" ;;
pankso@1 568 list)
pankso@1 569 # Cook a list of packages (better use the Cooker since it will order
pankso@1 570 # packages before executing cook).
pankso@1 571 check_root
pankso@1 572 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
pankso@1 573 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
pankso@1 574 echo -e " $2\n" && exit 1
pankso@13 575 echo "Cook list starting: $2" | log
pankso@1 576 for pkg in $(cat $2)
pankso@1 577 do
pankso@1 578 cook $pkg || broken
pankso@1 579 done ;;
pankso@1 580 clean-wok)
pankso@1 581 check_root
pankso@1 582 gettext -e "\nCleaning all packages files..."
pankso@1 583 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
pankso@1 584 status && echo "" ;;
pankso@1 585 clean-src)
pankso@1 586 check_root
pankso@1 587 gettext -e "\nCleaning all packages source..."
pankso@1 588 rm -rf $WOK/*/source
pankso@1 589 status && echo "" ;;
pankso@1 590 pkglist)
pankso@1 591 # Create suitable packages list for TazPKG and only for builded packages.
pankso@1 592 [ "$2" ] && PKGS="$2"
pankso@1 593 [ ! -d "$PKGS" ] && \
pankso@1 594 gettext -e "\nPackages directory dont exist\n\n" && exit 1
pankso@1 595 cd $PKGS
pankso@13 596 echo "Cook pkglist: Creating all packages list" | log
pankso@1 597 gettext -e "\nCreating lists for:"; echo " $PKGS"
pankso@1 598 separator
pankso@1 599 rm -f packages.* files.list*
pankso@1 600 gettext -e "Creating: packages.list\n"
pankso@1 601 ls -1 | sed s'/.tazpkg//' > $PKGS/packages.list
pankso@1 602 gettext -e "Creating: packages.md5\n"
pankso@1 603 md5sum *.tazpkg > $PKGS/packages.md5
pankso@1 604 gettext -e "Creating: packages.desc\n"
pankso@1 605 gettext -e "Creating: packages.equiv\n"
pankso@1 606 cd $WOK
pankso@1 607 for pkg in *
pankso@1 608 do
pankso@1 609 unset_receipt
pankso@1 610 . $pkg/receipt
pankso@1 611 # packages.desc let us search easily in DB
pankso@1 612 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
pankso@1 613 cat >> $PKGS/packages.desc << EOT
pankso@1 614 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
pankso@1 615 EOT
pankso@1 616 # Packages.equiv is used by tazpkg install to check depends.
pankso@1 617 for i in $PROVIDE; do
pankso@1 618 DEST=""
pankso@1 619 echo $i | fgrep -q : && DEST="${i#*:}:"
pankso@1 620 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
pankso@1 621 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
pankso@1 622 $PKGS/packages.equiv
pankso@1 623 else
pankso@1 624 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
pankso@1 625 fi
pankso@1 626 done
pankso@1 627 fi
pankso@1 628 done
pankso@1 629 # files.list.lzma
pankso@1 630 #lzma e files.list files.list.lzma
pankso@1 631 separator
pankso@1 632 nb=$(ls $PKGS/*.tazpkg | wc -l)
pankso@1 633 echo -e "Packages: $nb\n" ;;
pankso@1 634 *)
pankso@1 635 # Just cook and generate a package.
pankso@1 636 check_root
pankso@1 637 time=$(date +%s)
pankso@1 638 pkg="$1"
pankso@1 639 [ -z "$pkg" ] && usage
pankso@1 640 check_pkg_in_wok && echo ""
pankso@16 641 echo "cook:$pkg" > $command
pankso@1 642 unset inst
pankso@1 643 unset_receipt
pankso@1 644 cd $WOK/$pkg && . ./receipt
pankso@1 645
pankso@1 646 # Handle --options
pankso@1 647 case "$2" in
pankso@1 648 --clean|-c)
pankso@1 649 gettext -e "Cleaning package:"; echo -n " $pkg"
pankso@1 650 cd $WOK/$pkg && rm -rf install taz source
pankso@1 651 status && echo "" && exit 0 ;;
pankso@1 652 --install|-i)
pankso@1 653 inst='yes' ;;
pankso@1 654 esac
pankso@1 655
pankso@1 656 # Check if wanted is build now so we have separate log files.
pankso@1 657 if [ "$WANTED" ] && [ ! -d "$WOK/$WANTED/install" ]; then
pankso@1 658 cook "$WANTED"
pankso@1 659 fi
pankso@1 660
pankso@1 661 # Cook and pack or exit on error and log everything.
pankso@26 662 cookit 2>&1 | tee $LOGS/$pkg.log
pankso@15 663 remove_deps | tee -a $LOGS/$pkg.log
pankso@1 664 cookit_quality
pankso@26 665 packit 2>&1 | tee -a $LOGS/$pkg.log
pankso@1 666 clean_log
pankso@33 667
pankso@33 668 # Exit if any error in packing.
pankso@33 669 if grep -q ^ERROR $LOGS/$pkg.log; then
pankso@33 670 debug_info | tee -a $LOGS/$pkg.log
pankso@33 671 rm -f $command && exit 1
pankso@33 672 fi
pankso@16 673
pankso@1 674 # Time and summary
pankso@1 675 time=$(($(date +%s) - $time))
pankso@1 676 summary | tee -a $LOGS/$pkg.log
pankso@1 677
pankso@1 678 # Install package if requested
pankso@1 679 if [ "$inst" ]; then
pankso@1 680 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
pankso@1 681 cd $PKGS && tazpkg install \
pankso@1 682 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
pankso@1 683 else
pankso@1 684 gettext -e "Unable to install package, build have failed.\n\n"
pankso@1 685 exit 1
pankso@1 686 fi
pankso@1 687 fi
pankso@9 688 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
pankso@17 689 # You want automation: use the Cooker Build Bot.
pankso@1 690 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
pankso@18 691 rm -f $command ;;
pankso@1 692 esac
pankso@1 693
pankso@1 694 exit 0