cookutils annotate cook @ rev 120

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