cookutils annotate cook @ rev 381

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