cookutils annotate cook @ rev 61

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