cookutils annotate cook @ rev 352

cook: show configure args and CFLAGS
author Christophe Lincoln <pankso@slitaz.org>
date Mon Apr 16 10:03:51 2012 +0200 (2012-04-16)
parents 89eb89d8dc22
children 7e69ae6e69a5
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@172 19 # Old style compatibility
pankso@172 20 SOURCES_REPOSITORY=$SRC
pankso@172 21
pankso@1 22 #
pankso@1 23 # Functions
pankso@1 24 #
pankso@1 25
pankso@1 26 usage() {
pankso@1 27 cat << EOT
pankso@1 28
pankso@147 29 $(echo -e "\033[1m$(gettext "Usage:")\033[0m") cook [package|command] [list|--option]
pankso@1 30
pankso@1 31 $(echo -e "\033[1m$(gettext "Commands:")\033[0m")
paul@214 32 usage|help $(gettext "Display this short usage.")
paul@214 33 setup $(gettext "Setup your build environment.")
paul@214 34 test $(gettext "Test environment and cook a package.")
paul@214 35 list-wok $(gettext "List packages in the wok.")
paul@214 36 search $(gettext "Simple packages search function.")
paul@214 37 new $(gettext "Create a new package with a receipt".)
paul@214 38 list $(gettext "Cook a list of packages.")
paul@214 39 clean-wok $(gettext "Clean-up all packages files.")
paul@214 40 clean-src $(gettext "Clean-up all packages sources.")
pankso@239 41 pkgdb $(gettext "Create packages DB lists and flavors.")
pankso@1 42
pankso@1 43 $(echo -e "\033[1m$(gettext "Options:")\033[0m")
paul@214 44 --clean|-c Cook : $(gettext "clean the package in the wok.")
paul@214 45 --install|-i Cook : $(gettext "cook and install the package.")
paul@214 46 --getsrc|-gs Cook : $(gettext "get the package source tarball.")
paul@214 47 --block|-b Cook : $(gettext "Block a package so cook will skip it.")
paul@214 48 --unblock|-ub Cook : $(gettext "Unblock a blocked package.")
pankso@230 49 --interactive|-x New : $(gettext "create a receipt interactively.")
pankso@230 50 --wok|-w Setup: $(gettext "clone the cooking wok from Hg repo.")
pankso@230 51 --stable Setup: $(gettext "clone the stable wok from Hg repo.")
pankso@230 52 --undigest Setup: $(gettext "clone the undigest wok from Hg repo.")
pankso@239 53 --flavors Pkgdb: $(gettext "create up-to-date flavors files.")
pankso@1 54
pankso@1 55 EOT
pankso@1 56 exit 0
pankso@1 57 }
pankso@1 58
paul@62 59 # Be sure we're root.
pankso@1 60 check_root() {
pankso@1 61 [ $(id -u) != 0 ] && gettext -e "\nYou must be root to cook.\n\n" && exit 0
pankso@1 62 }
pankso@1 63
pankso@1 64 separator() {
pankso@1 65 echo "================================================================================"
pankso@1 66 }
pankso@1 67
pankso@1 68 status() {
pankso@1 69 echo -en "\\033[70G[ "
pankso@1 70 if [ $? = 0 ]; then
pankso@1 71 echo -en "\\033[1;32mOK"
pankso@1 72 else
pankso@1 73 echo -en "\\033[1;31mFailed"
pankso@1 74 fi
pankso@1 75 echo -e "\\033[0;39m ]"
pankso@1 76 }
pankso@1 77
pankso@13 78 # Log activities, we want first letter capitalized.
pankso@9 79 log() {
pankso@27 80 grep ^[A-Z] | \
pankso@9 81 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
pankso@9 82 }
pankso@9 83
paul@62 84 # We don't want these escapes in web interface.
pankso@1 85 clean_log() {
pankso@1 86 sed -i -e s'|\[70G\[ \[1;32m| |' \
pankso@1 87 -e s'|\[0;39m \]||' $LOGS/$pkg.log
pankso@1 88 }
pankso@1 89
pankso@23 90 # Log broken packages.
pankso@23 91 broken() {
pankso@74 92 if ! grep -q "^$pkg$" $broken; then
pankso@74 93 echo "$pkg" >> $broken
pankso@74 94 fi
pankso@23 95 }
pankso@23 96
paul@62 97 # Be sure package exists in wok.
pankso@1 98 check_pkg_in_wok() {
pankso@1 99 if [ ! -d "$WOK/$pkg" ]; then
pankso@1 100 gettext -e "\nUnable to find package in the wok:"
pankso@1 101 echo -e " $pkg\n" && exit 1
pankso@1 102 fi
pankso@1 103 }
pankso@1 104
pankso@9 105 if_empty_value() {
pankso@9 106 if [ -z "$value" ]; then
pankso@9 107 gettext "QA: empty variable:"; echo -e " ${var}=\"\"\n"
pankso@9 108 exit 1
pankso@9 109 fi
pankso@9 110 }
pankso@9 111
paul@62 112 # Initialize files used in $CACHE
pankso@52 113 init_db_files() {
pankso@52 114 gettext "Creating directories structure in:"; echo " $SLITAZ"
pankso@52 115 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS
pankso@52 116 gettext "Creating DB files in:"; echo " $CACHE"
pankso@52 117 for f in $activity $command $broken $blocked
pankso@52 118 do
pankso@52 119 touch $f
pankso@52 120 done
pankso@52 121 }
pankso@52 122
paul@62 123 # QA: check a receipt consistency before building.
pankso@9 124 receipt_quality() {
pankso@9 125 gettext -e "QA: checking package receipt...\n"
pankso@9 126 unset online
pankso@9 127 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
pankso@9 128 online="online"
pankso@9 129 fi
pankso@9 130 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
pankso@9 131 do
pankso@9 132 unset value
pascal@279 133 value="$(. $receipt ; eval echo \$$var)"
pankso@9 134 case "$var" in
pankso@9 135 PACKAGE|VERSION|SHORT_DESC)
pankso@9 136 if_empty_value ;;
pankso@9 137 CATEGORY)
pankso@9 138 [ -z "$value" ] && value="empty"
pankso@9 139 valid="base-system x-window utilities network graphics \
pankso@9 140 multimedia office development system-tools security games \
pankso@9 141 misc meta non-free"
pankso@9 142 if ! echo "$valid" | grep -q -w "$value"; then
paul@62 143 gettext "QA: unknown category:"; echo -e " $value\n"
pankso@9 144 exit 1
pankso@9 145 fi ;;
pankso@9 146 WEB_SITE)
paul@62 147 # We don't check WGET_URL since if dl is needed it will fail.
paul@62 148 # Break also if we're not online. Here error is not fatal.
pankso@9 149 if_empty_value
pankso@9 150 [ -z "$online" ] || break
pankso@199 151 if ! busybox wget -T 12 -s $value 2>/dev/null; then
pankso@61 152 gettext "QA: Unable to reach:"; echo -e " $value"
pankso@9 153 fi ;;
pankso@9 154 esac
pankso@9 155 done
pankso@9 156 }
pankso@9 157
pankso@9 158 # Executed before sourcing a receipt.
pankso@9 159 unset_receipt() {
pankso@9 160 unset DEPENDS BUILD_DEPENDS WANTED EXTRAVERSION WGET_URL PROVIDE TARBALL
pankso@9 161 }
pankso@9 162
paul@62 163 # Paths used in receipt and by cook itself.
pankso@1 164 set_paths() {
pankso@1 165 pkgdir=$WOK/$PACKAGE
pankso@1 166 src=$pkgdir/source/$PACKAGE-$VERSION
pankso@44 167 taz=$pkgdir/taz
pankso@44 168 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
pankso@1 169 fs=$pack/fs
pankso@1 170 stuff=$pkgdir/stuff
pankso@1 171 install=$pkgdir/install
pankso@1 172 if [ "$WANTED" ]; then
pascal@291 173 wanted=${WANTED%% *}
pascal@291 174 src=$WOK/$wanted/source/$wanted-$VERSION
pascal@291 175 install=$WOK/$wanted/install
pascal@291 176 wanted_stuff=$WOK/$wanted/stuff
pankso@1 177 fi
paul@243 178 # Kernel version is set from linux-api-headers since it is part of toolchain.
pankso@232 179 if [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
pankso@232 180 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d '"' -f 2)
pankso@232 181 fi
pankso@9 182 # Old way compatibility.
pankso@1 183 _pkg=$install
pankso@1 184 }
pankso@1 185
pankso@144 186 # Create source tarball when URL is a SCM.
pankso@144 187 create_tarball() {
pankso@144 188 gettext "Creating tarball: "; echo "$tarball"
pankso@162 189 if [ "$LZMA_SRC" ]; then
pankso@162 190 tar -c $pkgsrc | lzma e $SRC/$tarball -si || exit 1
pankso@162 191 else
pankso@162 192 tar cjf $tarball $pkgsrc || exit 1
pankso@162 193 mv $tarball $SRC && rm -rf $pkgsrc
pankso@162 194 fi
pankso@144 195 }
pankso@144 196
pankso@145 197 # Get package source. For SCM we are in cache so clone here and create a
pankso@145 198 # tarball here.
pankso@1 199 get_source() {
pankso@115 200 pwd=$(pwd)
pankso@144 201 pkgsrc=${SOURCE:-$PACKAGE}-$VERSION
pankso@144 202 tarball=$pkgsrc.tar.bz2
pankso@162 203 [ "$LZMA_SRC" ] && tarball=$pkgsrc.tar.lzma
pankso@9 204 case "$WGET_URL" in
pankso@145 205 http://*|ftp://*)
pankso@9 206 # Busybox Wget is better!
pascal@268 207 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
pankso@145 208 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
pankso@145 209 https://*)
pankso@250 210 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
pankso@15 211 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
pankso@9 212 hg*|mercurial*)
pankso@29 213 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
pankso@9 214 url=${WGET_URL#hg|}
pankso@9 215 else
pankso@9 216 url=${WGET_URL#mercurial|}
pankso@9 217 fi
pankso@61 218 gettext -e "Getting source from Hg...\n"
pankso@61 219 echo "URL: $url"
pankso@9 220 gettext "Cloning to: "; echo "$pwd/$pkgsrc"
pankso@246 221 if [ "$BRANCH" ]; then
pankso@246 222 echo "Hg branch: $BRANCH"
pankso@246 223 hg clone $url --rev $BRANCH $pkgsrc || \
pankso@246 224 (echo "ERROR: hg clone $url --rev $BRANCH" && exit 1)
pankso@246 225 else
pankso@246 226 hg clone $url $pkgsrc || (echo "ERROR: hg clone $url" && exit 1)
pankso@246 227 fi
pankso@255 228 rm -rf $pkgsrc/.hg
pankso@144 229 create_tarball ;;
pankso@9 230 git*)
pankso@61 231 url=${WGET_URL#git|}
pankso@61 232 gettext -e "Getting source from Git...\n"
pankso@61 233 echo "URL: $url"
pankso@64 234 git clone $url $pkgsrc || (echo "ERROR: git clone $url" && exit 1)
pankso@63 235 if [ "$BRANCH" ]; then
pankso@146 236 echo "Git branch: $BRANCH"
pankso@64 237 cd $pkgsrc && git checkout $BRANCH && cd ..
pankso@63 238 fi
pankso@144 239 create_tarball ;;
pankso@144 240 cvs*)
pankso@144 241 url=${WGET_URL#cvs|}
pankso@144 242 mod=$PACKAGE
pankso@144 243 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
pankso@144 244 gettext -e "Getting source from CVS...\n"
pankso@144 245 echo "URL: $url"
pankso@146 246 [ "$CVS_MODULE" ] && echo "CVS module: $mod"
pankso@144 247 gettext "Cloning to: "; echo "$pwd/$mod"
pankso@144 248 cvs -d:$url co $mod && mv $mod $pkgsrc
pankso@144 249 create_tarball ;;
pankso@69 250 svn*|subversion*)
pankso@159 251 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
pankso@146 252 url=${WGET_URL#svn|}
pankso@146 253 else
pankso@146 254 url=${WGET_URL#subversion|}
pankso@146 255 fi
pankso@146 256 gettext -e "Getting source from SVN...\n"
pankso@146 257 echo "URL: $url"
pankso@161 258 if [ "$BRANCH" ]; then
pankso@161 259 echo t | svn co $url -r $BRANCH $pkgsrc
pankso@161 260 else
pankso@161 261 echo t | svn co $url $pkgsrc
pankso@161 262 fi
pankso@146 263 create_tarball ;;
pankso@9 264 *)
pankso@9 265 gettext -e "\nERROR: Unable to handle:"; echo -e " $WGET_URL \n" | \
pankso@9 266 tee -a $LOGS/$PACKAGE.log
pankso@9 267 exit 1 ;;
pankso@9 268 esac
pankso@1 269 }
pankso@1 270
pankso@9 271 # Extract source package.
pankso@1 272 extract_source() {
pankso@177 273 if [ ! -s "$SRC/$TARBALL" ]; then
pankso@177 274 local url
pankso@177 275 url="http://mirror.slitaz.org/sources/packages"
pankso@177 276 url=$url/${TARBALL:0:1}/$TARBALL
pankso@177 277 gettext "Getting source from mirror:"; echo " $url"
pankso@177 278 busybox wget -c -P $SRC $url || echo -e "ERROR: wget $url"
pankso@177 279 fi
pankso@1 280 gettext "Extracting:"; echo " $TARBALL"
pankso@1 281 case "$TARBALL" in
pankso@120 282 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
pankso@178 283 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
pankso@1 284 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
pankso@42 285 *.tar) tar xf $SRC/$TARBALL ;;
pankso@42 286 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
pankso@42 287 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
pankso@42 288 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
pankso@42 289 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
pankso@238 290 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
pankso@191 291 *) cp $SRC/$TARBALL $(pwd) ;;
pankso@1 292 esac
pankso@1 293 }
pankso@1 294
pankso@9 295 # Display cooked package summary.
pankso@1 296 summary() {
pankso@1 297 cd $WOK/$pkg
pankso@1 298 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
pankso@1 299 fs=$(du -sh taz/* | awk '{print $1}')
pankso@44 300 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
pankso@44 301 files=$(cat taz/$pkg-*/files.list | wc -l)
pankso@18 302 cookdate=$(date "+%Y-%m-%d %H:%M")
pankso@101 303 sec=$time
pascal@280 304 div=$(( ($time + 30) / 60))
pankso@112 305 [ "$div" != 0 ] && min="~ ${div}m"
pankso@1 306 gettext "Summary for:"; echo " $PACKAGE $VERSION"
pankso@1 307 separator
pankso@67 308 [ "$prod" ] && echo "Produced : $prod"
pankso@1 309 cat << EOT
pankso@1 310 Packed : $fs
pankso@1 311 Compressed : $size
pankso@18 312 Files : $files
pankso@102 313 Cook time : ${sec}s $min
pankso@18 314 Cook date : $cookdate
pankso@1 315 $(separator)
pankso@1 316 EOT
pankso@1 317 }
pankso@1 318
paul@62 319 # Display debugging error info.
pankso@15 320 debug_info() {
pankso@17 321 echo -e "\nDebug information"
pankso@15 322 separator
pankso@48 323 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
pankso@76 324 for error in \
pankso@77 325 ERROR "No package" "cp: can't" "can't open" "can't cd" \
pankso@76 326 "error:" "fatal error:"
pankso@34 327 do
pankso@34 328 fgrep "$error" $LOGS/$pkg.log
pankso@34 329 done
pankso@15 330 separator && echo ""
pankso@15 331 }
pankso@15 332
pankso@1 333 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
pankso@1 334 # so some packages need to copy these files with the receipt and genpkg_rules.
pankso@1 335 copy_generic_files()
pankso@1 336 {
pankso@1 337 # $LOCALE is set in cook.conf
pankso@281 338 if [ "$LOCALE" ]; then
pankso@260 339 if [ -d "$install/usr/share/locale" ]; then
pankso@1 340 mkdir -p $fs/usr/share/locale
pankso@1 341 for i in $LOCALE
pankso@1 342 do
pankso@260 343 if [ -d "$install/usr/share/locale/$i" ]; then
pankso@260 344 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
pankso@1 345 fi
pankso@1 346 done
pankso@1 347 fi
pankso@1 348 fi
pankso@1 349
pankso@1 350 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
pankso@1 351 if [ "$GENERIC_PIXMAPS" != "no" ]; then
pankso@260 352 if [ -d "$install/usr/share/pixmaps" ]; then
pankso@1 353 mkdir -p $fs/usr/share/pixmaps
pankso@260 354 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
pankso@281 355 $fs/usr/share/pixmaps 2>/dev/null || continue
pankso@260 356 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
pankso@281 357 $fs/usr/share/pixmaps 2>/dev/null || continue
pankso@1 358 fi
pankso@1 359
pankso@1 360 # Custom or homemade PNG pixmap can be in stuff.
pankso@1 361 if [ -f "$stuff/$PACKAGE.png" ]; then
pankso@1 362 mkdir -p $fs/usr/share/pixmaps
pankso@1 363 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
pankso@1 364 fi
pankso@1 365 fi
pankso@1 366
pankso@1 367 # Desktop entry (.desktop).
erjo@284 368 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
erjo@284 369 if [ "$GENERIC_MENUS" != "no" ]; then
erjo@284 370 if [ -d "$install/usr/share/applications" ] && [ "$WANTED" == "" ]; then
erjo@284 371 cp -a $install/usr/share/applications $fs/usr/share
erjo@284 372 fi
pankso@1 373 fi
pankso@1 374
pankso@1 375 # Homemade desktop file(s) can be in stuff.
pankso@1 376 if [ -d "$stuff/applications" ]; then
pankso@1 377 mkdir -p $fs/usr/share
pankso@1 378 cp -a $stuff/applications $fs/usr/share
pankso@1 379 fi
pankso@1 380 if [ -f "$stuff/$PACKAGE.desktop" ]; then
pankso@1 381 mkdir -p $fs/usr/share/applications
pankso@1 382 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
pankso@1 383 fi
pankso@1 384 }
pankso@1 385
pankso@67 386 # Find and strip : --strip-all (-s) or --strip-debug on static libs as well
pankso@68 387 # as removing uneeded files like in Python packages.
pankso@1 388 strip_package()
pankso@1 389 {
pankso@67 390 gettext "Executing strip on all files..."
pankso@1 391 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
pankso@1 392 do
pankso@1 393 if [ -d "$dir" ]; then
pankso@1 394 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
pankso@1 395 fi
pankso@1 396 done
pankso@1 397 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
pankso@1 398 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
pankso@1 399 status
pankso@67 400
pankso@117 401 # Remove Python .pyc and .pyo from packages.
pankso@150 402 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
pankso@68 403 gettext "Removing Python compiled files..."
pankso@67 404 find $fs -type f -name "*.pyc" -delete 2>/dev/null
pankso@67 405 find $fs -type f -name "*.pyo" -delete 2>/dev/null
pankso@117 406 status
pankso@117 407 fi
pankso@117 408
pankso@117 409 # Remove Perl perllocal.pod and .packlist from packages.
pankso@117 410 if echo "$DEPENDS" | fgrep -q "perl"; then
pankso@117 411 gettext "Removing Perl compiled files..."
pankso@67 412 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
pankso@67 413 find $fs -type f -name ".packlist" -delete 2>/dev/null
pankso@67 414 status
pankso@67 415 fi
pankso@1 416 }
pankso@1 417
pankso@8 418 # Remove installed deps.
pankso@8 419 remove_deps() {
pankso@8 420 # Now remove installed build deps.
pankso@113 421 diff="$CACHE/installed.cook.diff"
pankso@113 422 if [ -s "$CACHE/installed.cook.diff" ]; then
pankso@113 423 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
pankso@113 424 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
pankso@8 425 gettext "Build dependencies to remove:"; echo " $nb"
pankso@8 426 gettext "Removing:"
pankso@8 427 for dep in $deps
pankso@8 428 do
pankso@8 429 echo -n " $dep"
pankso@205 430 echo 'y' | tazpkg remove $dep >/dev/null
pankso@8 431 done
pankso@16 432 echo -e "\n"
pankso@113 433 # Keep the last diff for debug and info.
pankso@113 434 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
pankso@1 435 fi
pankso@1 436 }
pankso@1 437
pankso@1 438 # The main cook function.
pankso@1 439 cookit() {
pankso@11 440 echo "Cook: $PACKAGE $VERSION"
pankso@9 441 separator
pankso@1 442 set_paths
pankso@9 443 [ "$QA" ] && receipt_quality
pankso@44 444 cd $pkgdir
pankso@33 445 rm -rf install taz source
pankso@1 446
pankso@1 447 # Disable -pipe if less than 512Mb free RAM.
pankso@1 448 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
pankso@1 449 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
pankso@1 450 gettext -e "Disabling -pipe compile flag: $free RAM\n"
pankso@1 451 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
pankso@47 452 CXXFLAGS="${CXXFLAGS/-pipe}" && \
pankso@47 453 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
pankso@1 454 fi
pankso@1 455 unset free
pankso@1 456
pankso@232 457 # Export flags and path to be used by make and receipt.
pankso@44 458 DESTDIR=$pkgdir/install
pankso@232 459 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
pankso@1 460
pankso@126 461 # Check for build deps and handle implicit depends of *-dev packages
pankso@126 462 # (ex: libusb-dev :: libusb).
pankso@215 463 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
pankso@215 464 touch $CACHE/installed.local $CACHE/installed.web
pankso@215 465 [ "$BUILD_DEPENDS" ] && gettext -e "Checking build dependencies...\n"
pankso@1 466 for dep in $BUILD_DEPENDS
pankso@1 467 do
pankso@126 468 implicit=${dep%-dev}
pankso@131 469 for i in $dep $implicit
pankso@126 470 do
pankso@131 471 if [ ! -f "$INSTALLED/$i/receipt" ]; then
paul@174 472 # Try local package first. In some cases implicit doesn't exist, ex:
paul@174 473 # libboost-dev exists but not libboost, so check if we got vers.
pankso@173 474 unset vers
pascal@343 475 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
pankso@131 476 if [ -f "$PKGS/$i-$vers.tazpkg" ]; then
pankso@215 477 echo $i-$vers.tazpkg >> $CACHE/installed.local
pankso@126 478 else
paul@227 479 # Priority to package version in wok (maybe more up-to-date)
paul@227 480 # than the mirrored one.
pankso@173 481 if [ "$vers" ]; then
pankso@202 482 if fgrep -q $i-$vers $DB/packages.list; then
pankso@215 483 echo $i >> $CACHE/installed.web
pankso@198 484 else
paul@211 485 # So package exists in wok but not available.
pankso@215 486 gettext "Missing dep (wok/pkg):"; echo " $i $vers"
pankso@215 487 echo $i >> $CACHE/missing.dep
pankso@198 488 fi
pankso@225 489 else
pankso@225 490 # Package is not in wok but may be in repo.
pankso@225 491 if fgrep -q $i-$vers $DB/packages.list; then
pankso@225 492 echo $i >> $CACHE/installed.web
pankso@225 493 else
paul@227 494 echo "ERROR: unknown dep $i" && exit 1
pankso@225 495 fi
pankso@173 496 fi
pankso@126 497 fi
pankso@1 498 fi
pankso@126 499 done
pankso@1 500 done
pankso@225 501
pankso@215 502 # Get the list of installed packages
pankso@215 503 cd $INSTALLED && ls -1 > $CACHE/installed.list
pankso@204 504
paul@211 505 # Have we a missing build dep to cook ?
pankso@215 506 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
pankso@205 507 gettext -e "Auto cook config is set : AUTO_COOK\n"
pankso@204 508 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
pankso@224 509 for i in $(uniq $CACHE/missing.dep)
pankso@204 510 do
pankso@205 511 (gettext "Building dep (wok/pkg) :"; echo " $i $vers") | \
pankso@204 512 tee -a $LOGS/$PACKAGE.log.$$
pankso@205 513 cook $i || (echo -e "ERROR: can't cook dep '$i'\n" && \
pankso@205 514 fgrep "remove: " $LOGS/$i.log && \
pankso@205 515 fgrep "Removing: " $LOGS/$i.log && echo "") | \
pankso@204 516 tee -a $LOGS/$PACKAGE.log.$$ && break
pankso@204 517 done
pankso@215 518 rm -f $CACHE/missing.dep
pankso@204 519 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
pankso@204 520 fi
pankso@204 521
paul@211 522 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
paul@211 523 # is enabled and cook fails we have ERROR in log, if no auto cook we have
pankso@204 524 # missing dep in cached file.
pankso@215 525 if fgrep -q "ERROR:" $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
pankso@215 526 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
pankso@215 527 echo "ERROR: missing dep $nb" && exit 1
pankso@202 528 fi
pankso@215 529
pankso@215 530 # Install local packages.
pankso@215 531 cd $PKGS
pankso@224 532 for i in $(uniq $CACHE/installed.local)
pankso@215 533 do
pankso@224 534 gettext "Installing dep (pkg/local):"; echo " $i"
pankso@215 535 tazpkg install $i >/dev/null
pankso@215 536 done
pankso@215 537
pankso@215 538 # Install web or cached packages (if mirror is set to $PKGS we only
pankso@215 539 # use local packages).
pankso@224 540 for i in $(uniq $CACHE/installed.web)
pankso@215 541 do
pankso@228 542 gettext "Installing dep (web/cache):"; echo " $i"
pankso@215 543 tazpkg get-install $i >/dev/null
pankso@215 544 done
pankso@215 545
pankso@215 546 # If a cook failed deps are removed.
pankso@215 547 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
pankso@215 548 [ ! -s "installed.cook.diff" ] && \
pankso@215 549 busybox diff installed.list installed.cook > installed.cook.diff
pankso@215 550 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
pankso@202 551
pankso@1 552 # Get source tarball and make sure we have source dir named:
paul@62 553 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
paul@62 554 # tarball if it exists.
pankso@1 555 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
pankso@1 556 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
pankso@10 557 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
pankso@190 558 LZMA_SRC=""
pankso@1 559 else
pankso@1 560 get_source || exit 1
pankso@1 561 fi
pankso@1 562 fi
pankso@242 563 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
pankso@1 564 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
pascal@268 565 if ! extract_source ; then
pascal@268 566 get_source
pascal@268 567 extract_source || exit 1
pascal@268 568 fi
pankso@190 569 if [ "$LZMA_SRC" ]; then
pankso@190 570 cd $pkgdir/source
pankso@190 571 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
pankso@190 572 mv tmp tmp-1 && mkdir tmp
pankso@190 573 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
pankso@190 574 fi
pankso@190 575 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
pankso@190 576 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
pankso@190 577 fi
pankso@190 578 fi
pankso@190 579 cd $pkgdir/source/tmp
paul@62 580 # Some archives are not well done and don't extract to one dir (ex lzma).
pankso@57 581 files=$(ls | wc -l)
pankso@244 582 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
pankso@244 583 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
pankso@244 584 mv * ../$PACKAGE-$VERSION/$TARBALL
pankso@57 585 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
pankso@57 586 mv * ../$PACKAGE-$VERSION
pankso@1 587 cd .. && rm -rf tmp
pankso@1 588 fi
pankso@1 589
pankso@9 590 # Execute receipt rules.
pankso@44 591 if grep -q ^compile_rules $receipt; then
pankso@352 592 echo "Executing: compile_rules"
pankso@352 593 echo "Configure: $CONFIGURE_ARGS"
pankso@352 594 echo "CFLAGS : $CFLAGS"
pankso@55 595 [ -d "$src" ] && cd $src
pankso@97 596 compile_rules $@ || exit 1
pankso@10 597 # Stay compatible with _pkg
pankso@55 598 [ -d "$src/_pkg" ] && mv $src/_pkg $install
pankso@9 599 # QA: compile_rules success so valid.
pankso@9 600 mkdir -p $install
pankso@9 601 else
pankso@9 602 # QA: No compile_rules so no error, valid.
pankso@9 603 mkdir -p $install
pankso@1 604 fi
pankso@1 605 separator && echo ""
pankso@1 606 }
pankso@1 607
pankso@1 608 # Cook quality assurance.
pankso@1 609 cookit_quality() {
pankso@9 610 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
pankso@15 611 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
pankso@9 612 fi
pankso@9 613 # ERROR can be echoed any time in cookit()
pankso@33 614 if fgrep -q ERROR: $LOGS/$pkg.log; then
pankso@17 615 debug_info | tee -a $LOGS/$pkg.log
pankso@33 616 rm -f $command && exit 1
pankso@1 617 fi
pankso@1 618 }
pankso@1 619
pankso@16 620 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
paul@62 621 # but it doesn't handle EXTRAVERSION.
pankso@1 622 packit() {
pankso@1 623 set_paths
pankso@55 624 echo "Pack: $PACKAGE $VERSION"
pankso@1 625 separator
pankso@44 626 if grep -q ^genpkg_rules $receipt; then
pankso@16 627 gettext -e "Executing: genpkg_rules\n"
pankso@259 628 set -e && cd $pkgdir && mkdir -p $fs
pankso@232 629 genpkg_rules || echo -e "\nERROR: genpkg_rules failed\n" >> \
pankso@234 630 $LOGS/$pkg.log
pankso@241 631 else
pankso@241 632 gettext "No packages rules: meta package"; echo
pankso@241 633 mkdir -p $fs
pankso@16 634 fi
pankso@98 635
pankso@98 636 # First QA check to stop now if genpkg_rules failed.
pankso@98 637 if fgrep -q ERROR: $LOGS/$pkg.log; then
pankso@98 638 exit 1
pankso@98 639 fi
pankso@98 640
pankso@44 641 cd $taz
pankso@1 642 for file in receipt description.txt
pankso@1 643 do
pankso@1 644 [ ! -f "../$file" ] && continue
pankso@1 645 gettext "Copying"; echo -n " $file..."
pankso@1 646 cp -f ../$file $pack && chown 0.0 $pack/$file && status
pankso@1 647 done
pankso@119 648 copy_generic_files
pankso@16 649
paul@62 650 # Create files.list with redirecting find output.
pankso@16 651 gettext "Creating the list of files..." && cd $fs
pankso@16 652 find . -type f -print > ../files.list
pankso@16 653 find . -type l -print >> ../files.list
pankso@16 654 cd .. && sed -i s/'^.'/''/ files.list
pankso@16 655 status
pankso@43 656
pankso@119 657 # Strip and stuff files.
pankso@43 658 strip_package
pankso@43 659
pankso@43 660 # Md5sum of files.
pankso@16 661 gettext "Creating md5sum of files..."
pankso@16 662 while read file; do
pankso@16 663 [ -L "fs$file" ] && continue
pankso@16 664 [ -f "fs$file" ] || continue
pankso@16 665 case "$file" in
pankso@232 666 /lib/modules/*/modules.*|*.pyc) continue ;;
pankso@16 667 esac
pankso@16 668 md5sum "fs$file" | sed 's/ fs/ /'
pankso@16 669 done < files.list > md5sum
pankso@16 670 status
pankso@16 671 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
pankso@16 672 description.txt 2> /dev/null | awk \
pankso@16 673 '{ sz=$1 } END { print sz }')
pankso@16 674
pankso@16 675 # Build cpio archives.
pankso@16 676 gettext "Compressing the fs... "
pankso@16 677 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
pankso@16 678 rm -rf fs
pankso@16 679 status
pankso@16 680 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
pankso@16 681 md5sum description.txt 2> /dev/null | awk \
pankso@16 682 '{ sz=$1 } END { print sz }')
pankso@16 683 gettext "Updating receipt sizes..."
pankso@16 684 sed -i s/^PACKED_SIZE.*$// receipt
pankso@16 685 sed -i s/^UNPACKED_SIZE.*$// receipt
pankso@16 686 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
pankso@16 687 status
pankso@16 688
pankso@16 689 # Set extra version.
pankso@16 690 if [ "$EXTRAVERSION" ]; then
pankso@16 691 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
pankso@16 692 sed -i s/^EXTRAVERSION.*$// receipt
pankso@16 693 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
pankso@16 694 status
pankso@16 695 fi
pankso@16 696
pankso@16 697 # Compress.
pankso@16 698 gettext "Creating full cpio archive... "
pankso@16 699 find . -print | cpio -o -H newc --quiet > \
pankso@16 700 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
pankso@16 701 status
pankso@16 702 gettext "Restoring original package tree... "
pankso@16 703 unlzma -c fs.cpio.lzma | cpio -idm --quiet
pankso@16 704 status
pankso@16 705 rm fs.cpio.lzma && cd ..
pankso@43 706
pankso@43 707 # QA and give info.
pankso@43 708 tazpkg=$(ls *.tazpkg)
pankso@43 709 packit_quality
pankso@43 710 separator && gettext "Package:"; echo -e " $tazpkg\n"
pankso@1 711 }
pankso@1 712
paul@62 713 # Verify package quality and consistency.
pankso@8 714 packit_quality() {
pankso@157 715 #gettext "QA: Checking for broken link..."
pankso@157 716 #link=$(find $fs/usr -type l -follow)
pankso@157 717 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
pankso@157 718 #status
pankso@142 719
pankso@142 720 # Exit if any error found in log file.
pankso@33 721 if fgrep -q ERROR: $LOGS/$pkg.log; then
pankso@32 722 rm -f $command && exit 1
pankso@8 723 fi
pankso@142 724
pankso@44 725 gettext "QA: Checking for empty package..."
pankso@45 726 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
pankso@259 727 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
pankso@44 728 echo -e "\nERROR: empty package"
pankso@32 729 rm -f $command && exit 1
pankso@8 730 else
pankso@134 731 # Ls sort by name so the first file is the one we want.
pankso@136 732 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
pankso@134 733 status
pankso@154 734 if [ -f "$old" ]; then
pankso@265 735 gettext "Removing old: $(basename $old)"
pankso@135 736 rm -f $old && status
pankso@154 737 fi
pankso@134 738 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
pankso@11 739 sed -i /^${pkg}$/d $broken
pankso@265 740 #gettext "Removing source tree..."
pankso@265 741 #rm -f $WOK/$pkg/source && status
pankso@8 742 fi
pankso@8 743 }
pankso@8 744
pascal@276 745 mkinstall_list() {
pascal@276 746 local pkg
pascal@276 747 for pkg in $@ ; do
pascal@276 748 case " $INSTALL_LIST " in
pascal@278 749 *\ $pkg\ *) continue ;;
pascal@279 750 *) if [ -s /home/slitaz/wok/$pkg/receipt ]; then
pascal@279 751 unset DEPENDS
pascal@279 752 . /home/slitaz/wok/$pkg/receipt
pascal@279 753 INSTALL_LIST="$INSTALL_LIST $pkg"
pascal@279 754 [ -n "$DEPENDS" ] && mkinstall_list $DEPENDS
pascal@279 755 fi
pascal@279 756 echo $pkg
pascal@276 757 esac
pascal@276 758 done
pascal@276 759 }
pascal@276 760
pascal@285 761 tac()
pascal@285 762 {
pascal@285 763 sed '1!G;h;$!d' $1
pascal@285 764 }
pascal@285 765
pascal@285 766 # Launch the cook command into a chroot jail protected by aufs.
pascal@285 767 # The current filesystems are used read-only and updates are
pascal@285 768 # stored in a separate branch.
pascal@285 769 try_aufs_chroot() {
pascal@285 770
pascal@286 771 base=/dev/shm/aufsmnt$$
pascal@286 772
pascal@285 773 # Can we setup the chroot ? Is it already done ?
pascal@292 774 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
pascal@285 775 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
pascal@285 776 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
pascal@286 777 mkdir ${base}root ${base}rw || return
pascal@285 778
pascal@285 779 echo "Setup aufs chroot..."
pascal@285 780
pascal@285 781 # Sanity check
pascal@286 782 for i in / /proc /sys /dev/shm /home ; do
pascal@285 783 case " $AUFS_MOUNTS " in
pascal@285 784 *\ $i\ *) ;;
pascal@285 785 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
pascal@285 786 esac
pascal@285 787 done
pascal@285 788 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
pascal@285 789 mount --bind $mnt ${base}root$mnt
pascal@285 790 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
pascal@285 791 echo "Aufs mountage failure"
pascal@285 792 umount ${base}root
pascal@285 793 rmdir ${base}*
pascal@285 794 return
pascal@285 795 fi
pascal@285 796 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
pascal@285 797 done
pascal@285 798
pascal@285 799 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
pascal@285 800 status=$?
pascal@285 801
paul@342 802 echo "Leaving aufs chroot..."
pascal@285 803 tac ${base}rw/aufs-umount.sh | sh
pascal@285 804 rm -rf ${base}rw
pascal@285 805 umount ${base}root
pascal@285 806 rmdir $base*
pascal@285 807
pascal@285 808 # Install package if requested
pascal@285 809 if [ "$inst" ]; then
pascal@285 810 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
pascal@285 811 cd $PKGS && tazpkg install \
pascal@285 812 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
pascal@285 813 else
pascal@285 814 gettext -e "Unable to install package, build has failed.\n\n"
pascal@285 815 exit 1
pascal@285 816 fi
pascal@285 817 fi
pankso@306 818
pankso@306 819 # Install package if part of the chroot to keep env up-to-date.
pankso@308 820 if [ -d "$INSTALLED/$pkg" ]; then
pankso@308 821 . /etc/slitaz/cook.conf
pankso@308 822 . $WOK/$pkg/taz/$pkg-*/receipt
pankso@308 823 echo "Updating chroot environment..."
pankso@308 824 echo "Updating chroot: $pkg (${VERSION}${EXTRAVERSION})" | log
pankso@306 825 cd $PKGS && tazpkg install \
pankso@308 826 $pkg-${VERSION}${EXTRAVERSION}.tazpkg --forced
pankso@306 827 fi
pascal@285 828 exit $status
pascal@285 829 }
pascal@285 830
pankso@310 831 # Create a XML feed for freshly builded package.
pankso@310 832 gen_rss() {
pankso@310 833 pubdate=$(date "+%a, %d %b %Y %X")
pankso@310 834 cat > $FEEDS/$pkg.xml << EOT
pankso@310 835 <item>
pankso@310 836 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
pankso@310 837 <link>${COOKER_URL}?pkg=$PACKAGE</link>
pankso@310 838 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
pankso@310 839 <pubDate>$pubdate</pubDate>
pankso@310 840 <description>$SHORT_DESC</description>
pankso@310 841 </item>
pankso@310 842 EOT
pankso@310 843 }
pankso@310 844
pankso@1 845 #
pankso@1 846 # Commands
pankso@1 847 #
pankso@1 848
pankso@1 849 case "$1" in
pankso@32 850 usage|help|-u|-h)
pankso@1 851 usage ;;
pankso@1 852 list-wok)
pankso@52 853 gettext -e "\nList of packages in:"; echo " $WOK"
pankso@1 854 separator
pankso@1 855 cd $WOK && ls -1
pankso@1 856 separator
pankso@1 857 echo -n "Packages: " && ls | wc -l
pankso@1 858 echo "" ;;
pankso@69 859 search)
pankso@69 860 # Just a simple search function, we dont need more actually.
pankso@69 861 query="$2"
pankso@69 862 gettext -e "\nSearch results for:"; echo " $query"
pankso@69 863 separator
pankso@69 864 cd $WOK && ls -1 | grep "$query"
pankso@69 865 separator && echo "" ;;
pankso@1 866 setup)
pankso@1 867 # Setup a build environment
pankso@1 868 check_root
pankso@11 869 echo "Cook: setting up the environment" | log
pankso@1 870 gettext -e "\nSetting up your environment\n"
pankso@1 871 separator && cd $SLITAZ
pankso@52 872 init_db_files
pankso@1 873 gettext -e "Checking for packages to install...\n"
pascal@276 874 case " $@ " in
pascal@276 875 *\ --reinstall\ *)
pascal@276 876 INSTALL_LIST=""
pascal@276 877 for pkg in $(mkinstall_list $SETUP_PKGS); do
pascal@276 878 tazpkg get-install $pkg --forced
pascal@276 879 done ;;
pascal@276 880 *)
pascal@276 881 for pkg in $SETUP_PKGS
pascal@276 882 do
pascal@276 883 [ ! -f "$INSTALLED/$pkg/receipt" ] &&
pascal@276 884 tazpkg get-install $pkg
pascal@276 885 done ;;
pascal@276 886 esac
pankso@1 887
pankso@1 888 # Handle --options
pankso@1 889 case "$2" in
pankso@49 890 --wok|-w)
pankso@230 891 hg clone $WOK_URL wok || exit 1 ;;
pankso@230 892 --stable)
pankso@230 893 hg clone $WOK_URL-stable wok || exit 1 ;;
pankso@230 894 --undigest)
pankso@230 895 hg clone $WOK_URL-undigest wok || exit 1 ;;
pankso@1 896 esac
pankso@1 897
pankso@1 898 # SliTaz group and permissions
pankso@1 899 if ! grep -q ^slitaz /etc/group; then
pankso@1 900 gettext -e "Adding group: slitaz\n"
pankso@1 901 addgroup slitaz
pankso@1 902 fi
pankso@1 903 gettext -e "Setting permissions for slitaz group...\n"
pascal@277 904 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
pascal@277 905 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
pankso@1 906 separator
pankso@1 907 gettext -e "All done, ready to cook packages :-)\n\n" ;;
pankso@9 908 test)
pankso@9 909 # Test a cook environment.
pankso@13 910 echo "Cook test: testing the cook environment" | log
pankso@9 911 [ ! -d "$WOK" ] && exit 1
pankso@9 912 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
pankso@9 913 cook cooktest ;;
pankso@1 914 new)
pankso@1 915 # Create the package folder and an empty receipt.
pankso@1 916 pkg="$2"
pankso@1 917 [ "$pkg" ] || usage
pankso@1 918 echo ""
pankso@1 919 if [ -d "$WOK/$pkg" ]; then
paul@62 920 echo -n "$pkg " && gettext "package already exists."
pankso@1 921 echo -e "\n" && exit 1
pankso@1 922 fi
pankso@1 923 gettext "Creating"; echo -n " $WOK/$pkg"
pankso@1 924 mkdir $WOK/$pkg && cd $WOK/$pkg && status
pankso@1 925 gettext "Preparing the package receipt..."
pankso@1 926 cp $DATA/receipt .
pankso@1 927 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
pankso@196 928 status && echo ""
pankso@196 929
pankso@196 930 # Interactive mode, asking and seding.
pankso@196 931 case "$3" in
paul@214 932 --interactive|-x)
paul@211 933 gettext -e "Entering interactive mode...\n"
paul@211 934 separator
pankso@196 935 echo "Package : $pkg"
pankso@196 936 # Version.
pankso@196 937 echo -n "Version : " ; read anser
pankso@196 938 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
pankso@196 939 # Category.
pankso@196 940 echo -n "Category : " ; read anser
pankso@196 941 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
pankso@196 942 # Short description.
pankso@196 943 echo -n "Short desc : " ; read anser
pankso@196 944 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
pankso@196 945 # Maintainer.
pankso@196 946 echo -n "Maintainer : " ; read anser
pankso@196 947 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
pankso@196 948 # Web site.
pankso@196 949 echo -n "Web site : " ; read anser
pankso@196 950 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
pankso@196 951 echo ""
pankso@196 952 # Wget URL.
pankso@196 953 echo "Wget URL to download source tarball."
pankso@196 954 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
pankso@196 955 echo -n "Wget url : " ; read anser
paul@211 956 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
pankso@196 957 # Ask for a stuff dir.
pankso@196 958 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
pankso@196 959 if [ "$anser" = "y" ]; then
pankso@196 960 echo -n "Creating the stuff directory..."
pankso@196 961 mkdir $WOK/$pkg/stuff && status
pankso@196 962 fi
pankso@196 963 # Ask for a description file.
pankso@196 964 echo -n "Are you going to write a description ? (y/N) : " ; read anser
pankso@196 965 if [ "$anser" = "y" ]; then
pankso@196 966 echo -n "Creating the description.txt file..."
pankso@196 967 echo "" > $WOK/$pkg/description.txt && status
pankso@196 968 fi
paul@211 969 separator
paul@211 970 gettext -e "Receipt is ready to use.\n"
pankso@196 971 echo "" ;;
pankso@196 972 esac ;;
pankso@1 973 list)
pankso@1 974 # Cook a list of packages (better use the Cooker since it will order
pankso@1 975 # packages before executing cook).
pankso@1 976 check_root
pankso@1 977 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
pankso@1 978 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
pankso@1 979 echo -e " $2\n" && exit 1
pankso@13 980 echo "Cook list starting: $2" | log
pankso@1 981 for pkg in $(cat $2)
pankso@1 982 do
pankso@1 983 cook $pkg || broken
pankso@1 984 done ;;
pankso@1 985 clean-wok)
pankso@1 986 check_root
pankso@1 987 gettext -e "\nCleaning all packages files..."
pankso@1 988 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
pankso@1 989 status && echo "" ;;
pankso@1 990 clean-src)
pankso@1 991 check_root
paul@62 992 gettext -e "\nCleaning all packages sources..."
pankso@1 993 rm -rf $WOK/*/source
pankso@1 994 status && echo "" ;;
pankso@235 995 pkgdb)
pankso@235 996 # Create suitable packages list for TazPKG and only for built packages
pankso@235 997 # as well as flavors files for TazLiTo. We dont need logs since we do it
paul@243 998 # manually to ensure everything is fine before syncing the mirror.
pankso@239 999 case "$2" in
pankso@239 1000 --flavors)
pankso@239 1001 continue ;;
pankso@239 1002 *)
pankso@240 1003 [ "$2" ] && PKGS="$2"
pankso@239 1004 [ ! -d "$PKGS" ] && \
pankso@240 1005 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1 ;;
pankso@239 1006 esac
pankso@226 1007 time=$(date +%s)
pankso@239 1008 flavors=$SLITAZ/flavors
pankso@239 1009 live=$SLITAZ/live
pankso@235 1010 echo "cook:pkgdb" > $command
pankso@235 1011 echo "Cook pkgdb: Creating all packages lists" | log
pankso@235 1012 echo ""
pankso@239 1013 gettext "Creating lists for: "; echo "$PKGS"
pankso@1 1014 separator
pankso@235 1015 gettext "Cook pkgdb started: "; date "+%Y-%m-%d %H:%M"
pankso@133 1016 cd $PKGS
pankso@192 1017 rm -f packages.*
pankso@235 1018 gettext -e "Creating: packages.list\n"
pankso@85 1019 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
pankso@235 1020 gettext -e "Creating: packages.md5\n"
pankso@1 1021 md5sum *.tazpkg > $PKGS/packages.md5
gokhlayeh@297 1022 md5sum packages.md5 | cut -f1 -d' ' > ID
pankso@235 1023 gettext -e "Creating lists from: "; echo "$WOK"
pankso@1 1024 cd $WOK
pankso@1 1025 for pkg in *
pankso@1 1026 do
pankso@1 1027 unset_receipt
pankso@1 1028 . $pkg/receipt
pankso@1 1029 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
pascal@267 1030 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
pascal@274 1031 if [ -s $pkg/taz/*/receipt ]; then
pascal@274 1032 . $pkg/taz/*/receipt
pascal@274 1033 fi
pankso@192 1034 # packages.desc lets us search easily in DB
pankso@1 1035 cat >> $PKGS/packages.desc << EOT
pankso@235 1036 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
pankso@1 1037 EOT
pankso@192 1038 # packages.txt used by tazpkg and tazpkg-web also to provide
pankso@192 1039 # a human readable package list with version and description.
pankso@192 1040 cat >> $PKGS/packages.txt << EOT
pankso@192 1041 $PACKAGE
pankso@235 1042 ${VERSION}$EXTRAVERSION
pankso@235 1043 $SHORT_DESC
pankso@235 1044 $PACKED_SIZE ($UNPACKED_SIZE installed)
pankso@235 1045
pankso@192 1046 EOT
pankso@192 1047 # packages.equiv is used by tazpkg install to check depends.
pankso@1 1048 for i in $PROVIDE; do
pankso@1 1049 DEST=""
pankso@1 1050 echo $i | fgrep -q : && DEST="${i#*:}:"
pankso@1 1051 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
pankso@1 1052 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
pankso@1 1053 $PKGS/packages.equiv
pankso@1 1054 else
pankso@1 1055 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
pankso@1 1056 fi
pankso@1 1057 done
paul@197 1058 # files.list provides a list of all packages files.
pankso@194 1059 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
pankso@194 1060 $PKGS/files.list
pankso@1 1061 fi
pankso@1 1062 done
pankso@235 1063
pankso@213 1064 # Display list size.
pankso@235 1065 gettext -e "Done: packages.desc\n"
pankso@235 1066 gettext -e "Done: packages.txt\n"
pankso@235 1067 gettext -e "Done: packages.equiv\n"
pankso@155 1068
pankso@194 1069 # files.list.lzma
pankso@235 1070 gettext -e "Creating: files.list.lzma\n"
pankso@235 1071 cd $PKGS && lzma e files.list files.list.lzma
pankso@194 1072 rm -f files.list
pankso@148 1073
pankso@235 1074 # Display some info.
pankso@1 1075 separator
pankso@1 1076 nb=$(ls $PKGS/*.tazpkg | wc -l)
pankso@226 1077 time=$(($(date +%s) - $time))
pankso@235 1078 echo -e "Packages: $nb - Time: ${time}s\n"
pankso@235 1079
paul@243 1080 # Create all flavors files at once. Do we really need code to monitor
paul@243 1081 # flavors changes ? Lets just build them with packages lists before
pankso@235 1082 # syncing the mirror.
pankso@239 1083 [ "$2" == "--flavors" ] || exit 1
pankso@239 1084 [ ! -d "$flavors" ] && echo -e "Missing flavors: $flavors\n" && exit 1
pankso@239 1085 [ -d "$live" ] || mkdir -p $live
pankso@236 1086 gettext "Creating flavors files in:"; echo " $live"
pankso@239 1087 echo "Cook pkgdb: Creating all flavors" | log
pankso@235 1088 separator
pankso@236 1089 gettext -e "Recharging lists to use latest packages...\n"
pankso@329 1090 tazpkg recharge >/dev/null 2>/dev/null
pankso@235 1091
pankso@235 1092 # We need a custom tazlito config to set working dir to /home/slitaz.
pankso@235 1093 if [ ! -f "$live/tazlito.conf" ]; then
pankso@235 1094 echo "Creating configuration file: tazlito.conf"
pankso@235 1095 cp /etc/tazlito/tazlito.conf $live
pankso@235 1096 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
pankso@235 1097 $live/tazlito.conf
pankso@235 1098 fi
pankso@235 1099
pankso@239 1100 # Update Hg flavors repo and pack.
pankso@239 1101 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
pankso@239 1102
pankso@239 1103 cd $live
pankso@235 1104 echo "Starting to generate flavors..."
pankso@235 1105 rm -f flavors.list *.flavor
pankso@235 1106 for i in $flavors/*
pankso@235 1107 do
pankso@235 1108 fl=$(basename $i)
pankso@235 1109 echo "Packing flavor: $(basename $i)"
pankso@235 1110 tazlito pack-flavor $fl >/dev/null || exit 1
pankso@235 1111 tazlito show-flavor $fl --brief --noheader 2> \
pankso@235 1112 /dev/null >> flavors.list
pankso@235 1113 done
pankso@237 1114 cp -f $live/*.flavor $live/flavors.list $PKGS
pankso@235 1115 separator && gettext "Flavors size: "; du -sh $live | awk '{print $1}'
pankso@235 1116 echo "" && rm -f $command ;;
pankso@1 1117 *)
pankso@1 1118 # Just cook and generate a package.
pankso@1 1119 check_root
pankso@1 1120 time=$(date +%s)
pankso@1 1121 pkg="$1"
pankso@1 1122 [ -z "$pkg" ] && usage
pankso@44 1123 receipt="$WOK/$pkg/receipt"
pankso@1 1124 check_pkg_in_wok && echo ""
pankso@47 1125
pankso@47 1126 # Skip blocked, 3 lines also for the Cooker.
pankso@151 1127 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
pankso@47 1128 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
pankso@47 1129 fi
pankso@47 1130
pascal@289 1131 try_aufs_chroot "$@"
pascal@289 1132
pankso@47 1133 # Log and source receipt.
pankso@56 1134 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
pankso@16 1135 echo "cook:$pkg" > $command
pascal@285 1136
pascal@285 1137 # Display and log info if cook process stopped.
pascal@285 1138 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
pascal@285 1139 tee -a $LOGS/$pkg.log' INT
pascal@285 1140
pankso@1 1141 unset inst
pankso@1 1142 unset_receipt
pankso@44 1143 . $receipt
pankso@1 1144
pankso@1 1145 # Handle --options
pankso@1 1146 case "$2" in
pankso@1 1147 --clean|-c)
pankso@49 1148 gettext -e "Cleaning:"; echo -n " $pkg"
pankso@1 1149 cd $WOK/$pkg && rm -rf install taz source
pankso@1 1150 status && echo "" && exit 0 ;;
pankso@1 1151 --install|-i)
pankso@1 1152 inst='yes' ;;
pankso@49 1153 --getsrc|-gs)
pankso@49 1154 gettext "Getting source for:"; echo " $pkg"
pankso@45 1155 separator && get_source
pankso@39 1156 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
pankso@49 1157 --block|-b)
pankso@49 1158 gettext "Blocking:"; echo -n " $pkg"
pankso@49 1159 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
pankso@49 1160 status && echo "" && exit 0 ;;
pankso@49 1161 --unblock|-ub)
pankso@49 1162 gettext "Unblocking:"; echo -n " $pkg"
pankso@49 1163 sed -i "/^${pkg}$/"d $blocked
pankso@49 1164 status && echo "" && exit 0 ;;
pankso@196 1165
pankso@1 1166 esac
pankso@1 1167
paul@62 1168 # Check if wanted is built now so we have separate log files.
pankso@295 1169 for wanted in $WANTED ; do
pascal@291 1170 if grep -q "^$wanted$" $blocked; then
pascal@291 1171 echo "WANTED package is blocked: $wanted" | tee $LOGS/$pkg.log
pankso@221 1172 echo "" && rm -f $command && exit 1
pankso@217 1173 fi
pascal@291 1174 if grep -q "^$wanted$" $broken; then
pascal@291 1175 echo "WANTED package is broken: $wanted" | tee $LOGS/$pkg.log
pankso@221 1176 echo "" && rm -f $command && exit 1
pankso@218 1177 fi
pascal@291 1178 if [ ! -d "$WOK/$wanted/install" ]; then
pascal@291 1179 cook "$wanted" || exit 1
pankso@137 1180 fi
pascal@291 1181 done
pankso@1 1182
pankso@1 1183 # Cook and pack or exit on error and log everything.
pankso@97 1184 cookit $@ 2>&1 | tee $LOGS/$pkg.log
pankso@15 1185 remove_deps | tee -a $LOGS/$pkg.log
pankso@1 1186 cookit_quality
pankso@26 1187 packit 2>&1 | tee -a $LOGS/$pkg.log
pankso@1 1188 clean_log
pankso@33 1189
pankso@33 1190 # Exit if any error in packing.
pankso@33 1191 if grep -q ^ERROR $LOGS/$pkg.log; then
pankso@33 1192 debug_info | tee -a $LOGS/$pkg.log
pankso@33 1193 rm -f $command && exit 1
pankso@33 1194 fi
pankso@16 1195
pankso@310 1196 # Create an XML feed
pankso@310 1197 gen_rss
pankso@310 1198
pankso@1 1199 # Time and summary
pankso@1 1200 time=$(($(date +%s) - $time))
pankso@1 1201 summary | tee -a $LOGS/$pkg.log
pankso@50 1202 echo ""
pankso@1 1203
pankso@1 1204 # Install package if requested
pankso@1 1205 if [ "$inst" ]; then
pankso@1 1206 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
pankso@1 1207 cd $PKGS && tazpkg install \
pankso@1 1208 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
pankso@1 1209 else
paul@62 1210 gettext -e "Unable to install package, build has failed.\n\n"
pankso@1 1211 exit 1
pankso@1 1212 fi
pankso@1 1213 fi
pankso@303 1214
pankso@304 1215 # Install package if part of the chroot to keep env up-to-date.
pankso@307 1216 if [ -d "$INSTALLED/$PACKAGE" ] && [ -z "$AUFS_MOUNTS" ]; then
pankso@308 1217 echo "Updating chroot environment..."
pankso@308 1218 echo "Updating chroot: $PACKAGE (${VERSION}${EXTRAVERSION})" | log
pankso@304 1219 cd $PKGS && tazpkg install \
pankso@304 1220 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
pankso@303 1221 fi
pankso@303 1222
pankso@9 1223 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
pankso@17 1224 # You want automation: use the Cooker Build Bot.
pankso@1 1225 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
pankso@18 1226 rm -f $command ;;
pankso@1 1227 esac
pankso@1 1228
pankso@1 1229 exit 0