cookutils annotate cook @ rev 161

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