cookutils annotate cook @ rev 665

Tiny edits
author Paul Issott <paul@slitaz.org>
date Fri Mar 28 18:55:34 2014 +0000 (2014-03-28)
parents 9e54be28452b
children b7a34d301d7c
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
paul@647 4 # before adding or modifying 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@422 9 . /usr/lib/slitaz/libcook.sh
pankso@1 10
pankso@633 11 VERSION="3.2"
al@596 12
al@596 13 # Internationalization.
al@596 14 . /usr/bin/gettext.sh
al@596 15 TEXTDOMAIN='cook'
al@596 16 export TEXTDOMAIN
al@596 17
al@596 18 _() echo -e "$(eval_gettext "$1")"
al@596 19 _n() echo -en "$(eval_gettext "$1")"
al@596 20 # to disable i18n:
al@596 21 # _() echo -e "$1"
al@596 22 # _n() echo -en "$1"
al@596 23
al@596 24
pankso@1 25 #
pankso@1 26 # Functions
pankso@1 27 #
pankso@1 28
pankso@1 29 usage() {
pankso@1 30 cat << EOT
pankso@1 31
al@596 32 $(_ "\033[1mUsage:\033[0m cook [package|command] [list|--option]")
pankso@1 33
al@596 34 $(_ "\033[1mCommands:\033[0m")
al@596 35 usage|help $(_ "Display this short usage.")
al@596 36 setup $(_ "Setup your build environment.")
al@596 37 *-setup $(_ "Setup a cross environment.")
al@596 38 test $(_ "Test environment and cook a package.")
al@596 39 list-wok $(_ "List packages in the wok.")
al@596 40 search $(_ "Simple packages search function.")
al@596 41 new $(_ "Create a new package with a receipt.")
al@596 42 list $(_ "Cook a list of packages.")
al@596 43 clean-wok $(_ "Clean-up all packages files.")
al@596 44 clean-src $(_ "Clean-up all packages sources.")
pankso@662 45 uncook $(_ "Check for uncooked packages")
al@596 46 pkgdb $(_ "Create packages DB lists and flavors.")
pankso@1 47
al@596 48 $(_ "\033[1mOptions:\033[0m")
al@596 49 --clean|-c Cook : $(_ "clean the package in the wok.")
al@596 50 --install|-i Cook : $(_ "cook and install the package.")
al@596 51 --getsrc|-gs Cook : $(_ "get the package source tarball.")
al@596 52 --block|-b Cook : $(_ "block a package so cook will skip it.")
al@596 53 --unblock|-ub Cook : $(_ "unblock a blocked package.")
al@598 54 --cdeps Cook : $(_ "check dependencies of cooked package.")
al@596 55 --pack Cook : $(_ "repack an already built package.")
pankso@662 56 --debug Cook : $(_ "display debugging messages.")
al@596 57 --interactive|-x New : $(_ "create a receipt interactively.")
al@596 58 --wok Setup: $(_ "clone the cooking wok from Hg repo.")
al@596 59 --stable Setup: $(_ "clone the stable wok from Hg repo.")
al@596 60 --undigest Setup: $(_ "clone the undigest wok from Hg repo.")
al@596 61 --tiny Setup: $(_ "clone the tiny SliTaz wok from Hg repo.")
al@596 62 --forced Setup: $(_ "force reinstall of chroot packages.")
al@596 63 --flavors Pkgdb: $(_ "create up-to-date flavors files.")
pankso@1 64
pankso@1 65 EOT
pankso@1 66 exit 0
pankso@1 67 }
pankso@1 68
paul@62 69 # We don't want these escapes in web interface.
pankso@1 70 clean_log() {
pankso@1 71 sed -i -e s'|\[70G\[ \[1;32m| |' \
pankso@1 72 -e s'|\[0;39m \]||' $LOGS/$pkg.log
pankso@1 73 }
pankso@1 74
paul@62 75 # Be sure package exists in wok.
pankso@1 76 check_pkg_in_wok() {
pankso@1 77 if [ ! -d "$WOK/$pkg" ]; then
al@596 78 newline; _ "Unable to find package in the wok: \$pkg"; newline
al@596 79 exit 1
pankso@1 80 fi
pankso@1 81 }
pankso@1 82
pankso@9 83 if_empty_value() {
pankso@9 84 if [ -z "$value" ]; then
al@596 85 # L10n: QA is quality assurance
al@596 86 _ "QA: empty variable: \${var}=\"\""; newline
pankso@9 87 exit 1
pankso@9 88 fi
pankso@9 89 }
pankso@9 90
paul@62 91 # Initialize files used in $CACHE
pankso@52 92 init_db_files() {
al@596 93 _ "Creating directories structure in: \$SLITAZ"
xfred222@559 94 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
al@596 95 _ "Creating DB files in: \$CACHE"
pankso@52 96 for f in $activity $command $broken $blocked
pankso@52 97 do
pankso@52 98 touch $f
pankso@52 99 done
pankso@52 100 }
pankso@52 101
paul@62 102 # QA: check a receipt consistency before building.
pankso@9 103 receipt_quality() {
al@596 104 _ "QA: checking package receipt..."
pankso@9 105 unset online
pankso@9 106 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
pankso@9 107 online="online"
pankso@9 108 fi
pankso@9 109 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
pankso@9 110 do
pankso@9 111 unset value
pascal@279 112 value="$(. $receipt ; eval echo \$$var)"
pankso@9 113 case "$var" in
pankso@9 114 PACKAGE|VERSION|SHORT_DESC)
pankso@9 115 if_empty_value ;;
pankso@9 116 CATEGORY)
pankso@9 117 [ -z "$value" ] && value="empty"
al@596 118 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
pankso@9 119 if ! echo "$valid" | grep -q -w "$value"; then
al@596 120 _ "QA: unknown category: \$value"
al@596 121 _ "Please, use one of: \$valid" | busybox fold -s
al@596 122 newline; exit 1
pankso@9 123 fi ;;
pankso@9 124 WEB_SITE)
paul@62 125 # We don't check WGET_URL since if dl is needed it will fail.
paul@62 126 # Break also if we're not online. Here error is not fatal.
pankso@9 127 if_empty_value
pankso@9 128 [ -z "$online" ] || break
pankso@199 129 if ! busybox wget -T 12 -s $value 2>/dev/null; then
al@596 130 _ "QA: unable to reach: \$value"
pankso@9 131 fi ;;
pankso@9 132 esac
pankso@9 133 done
pankso@9 134 }
pankso@9 135
paul@62 136 # Paths used in receipt and by cook itself.
pankso@1 137 set_paths() {
pankso@1 138 pkgdir=$WOK/$PACKAGE
slaxemulator@492 139 basesrc=$pkgdir/source
slaxemulator@492 140 tmpsrc=$basesrc/tmp
slaxemulator@492 141 src=$basesrc/$PACKAGE-$VERSION
pankso@44 142 taz=$pkgdir/taz
pankso@44 143 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
pankso@1 144 fs=$pack/fs
pankso@1 145 stuff=$pkgdir/stuff
pankso@1 146 install=$pkgdir/install
slaxemulator@492 147 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
slaxemulator@492 148 lzma_tarball="$pkgsrc.tar.lzma"
slaxemulator@492 149 if [ "$PATCH" ]; then
slaxemulator@492 150 [ "${PTARBALL}" ] || PTARBALL="$(basename $PATCH)"
slaxemulator@492 151 fi
pankso@1 152 if [ "$WANTED" ]; then
slaxemulator@492 153 basesrc=$WOK/$WANTED/source
slaxemulator@492 154 src=$basesrc/$WANTED-$VERSION
slaxemulator@492 155 install=$WOK/$WANTED/install
slaxemulator@492 156 wanted_stuff=$WOK/$WANTED/stuff
pankso@1 157 fi
slaxemulator@456 158 if [ "$SOURCE" ]; then
slaxemulator@456 159 source_stuff=$WOK/$SOURCE/stuff
slaxemulator@456 160 fi
mojo@620 161 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
slaxemulator@492 162 if [ -f "$WOK/linux/receipt" ]; then
slaxemulator@492 163 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d '"' -f 2)
slaxemulator@492 164 kbasevers=${kvers:0:3}
mojo@620 165 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
mojo@620 166 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d '"' -f 2)
mojo@620 167 kbasevers=${kvers:0:3}
pankso@662 168 fi
pankso@662 169 # Python version
slaxemulator@492 170 if [ -f "$WOK/python/receipt" ]; then
slaxemulator@492 171 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d '"' -f 2)
slaxemulator@492 172 fi
slaxemulator@492 173 # perl version for some packages needed it
slaxemulator@492 174 if [ -f "$WOK/perl/receipt" ]; then
slaxemulator@492 175 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d '"' -f 2)
pankso@232 176 fi
pankso@9 177 # Old way compatibility.
pankso@1 178 _pkg=$install
pankso@1 179 }
pankso@1 180
pankso@144 181 # Create source tarball when URL is a SCM.
pankso@144 182 create_tarball() {
slaxemulator@498 183 local tarball
slaxemulator@498 184 tarball=$pkgsrc.tar.bz2
slaxemulator@498 185 [ "$LZMA_SRC" ] && tarball=$lzma_tarball
al@596 186 _ "Creating tarball: \$tarball"
pankso@162 187 if [ "$LZMA_SRC" ]; then
slaxemulator@498 188 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
slaxemulator@498 189 LZMA_SRC=""
pankso@162 190 else
pankso@162 191 tar cjf $tarball $pkgsrc || exit 1
pankso@162 192 mv $tarball $SRC && rm -rf $pkgsrc
pankso@162 193 fi
slaxemulator@498 194 TARBALL=$tarball
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() {
pascal@610 200 local url
pascal@610 201 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
ernia@571 202 set_paths
pankso@115 203 pwd=$(pwd)
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 || \
pascal@610 208 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
al@596 209 (_ "ERROR: wget \$WGET_URL" && exit 1) ;;
pankso@145 210 https://*)
pankso@250 211 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
pascal@610 212 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
al@596 213 (_ "ERROR: wget \$WGET_URL" && exit 1) ;;
pankso@9 214 hg*|mercurial*)
pankso@29 215 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
pankso@9 216 url=${WGET_URL#hg|}
pankso@9 217 else
pankso@9 218 url=${WGET_URL#mercurial|}
pankso@9 219 fi
al@596 220 _ "Getting source from Hg..."
al@596 221 _ "URL: \$url"
al@596 222 _ "Cloning to: \$pwd/\$pkgsrc"
pankso@246 223 if [ "$BRANCH" ]; then
al@596 224 _ "Hg branch: \$BRANCH"
pankso@246 225 hg clone $url --rev $BRANCH $pkgsrc || \
al@596 226 (_ "ERROR: hg clone \$url --rev \$BRANCH" && exit 1)
pankso@246 227 else
al@596 228 hg clone $url $pkgsrc || (_ "ERROR: hg clone \$url" && exit 1)
pankso@246 229 fi
pankso@255 230 rm -rf $pkgsrc/.hg
pankso@144 231 create_tarball ;;
pankso@9 232 git*)
pankso@61 233 url=${WGET_URL#git|}
al@596 234 _ "Getting source from Git..."
al@596 235 _ "URL: \$url"
al@596 236 git clone $url $pkgsrc || (_ "ERROR: git clone \$url" && exit 1)
pankso@63 237 if [ "$BRANCH" ]; then
al@596 238 _ "Git branch: \$BRANCH"
pankso@358 239 cd $pkgsrc && git checkout $BRANCH && cd ..
pankso@63 240 fi
pankso@144 241 create_tarball ;;
pankso@144 242 cvs*)
pankso@144 243 url=${WGET_URL#cvs|}
pankso@144 244 mod=$PACKAGE
pankso@144 245 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
al@596 246 _ "Getting source from CVS..."
al@596 247 _ "URL: \$url"
al@596 248 [ "$CVS_MODULE" ] && _ "CVS module: \$mod"
al@596 249 _ "Cloning to: \$pwd/\$mod"
pankso@144 250 cvs -d:$url co $mod && mv $mod $pkgsrc
pankso@144 251 create_tarball ;;
pankso@69 252 svn*|subversion*)
pankso@159 253 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
pankso@146 254 url=${WGET_URL#svn|}
pankso@146 255 else
pankso@146 256 url=${WGET_URL#subversion|}
pankso@146 257 fi
al@596 258 _ "Getting source from SVN..."
al@596 259 _ "URL: \$url"
pankso@161 260 if [ "$BRANCH" ]; then
pankso@161 261 echo t | svn co $url -r $BRANCH $pkgsrc
pankso@161 262 else
pankso@161 263 echo t | svn co $url $pkgsrc
pankso@161 264 fi
pankso@146 265 create_tarball ;;
al@590 266 bzr*)
al@590 267 url=${WGET_URL#bzr|}
al@596 268 _ "Getting source from bazaar..."
al@590 269 cd $SRC
al@590 270 pkgsrc=${url#*:}
al@590 271 if [ "$BRANCH" ]; then
al@590 272 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
al@590 273 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
al@590 274 else
al@590 275 echo "bzr -Ossl.cert_reqs=none branch $url"
al@590 276 bzr -Ossl.cert_reqs=none branch $url
al@590 277 cd $pkgsrc && BRANCH=$(bzr revno) && cd ..
al@596 278 _ "Don't forget to add to receipt:"
al@596 279 echo 'BRANCH="'$BRANCH'"'; newline
al@590 280 fi
al@590 281 mv $pkgsrc $pkgsrc-$BRANCH
al@590 282 pkgsrc=$pkgsrc-$BRANCH
al@590 283 create_tarball ;;
pankso@9 284 *)
al@596 285 (newline; _ "ERROR: Unable to handle: \$WGET_URL"; newline) | \
pankso@9 286 tee -a $LOGS/$PACKAGE.log
pankso@9 287 exit 1 ;;
pankso@9 288 esac
pankso@1 289 }
pankso@1 290
pankso@9 291 # Extract source package.
pankso@1 292 extract_source() {
pankso@177 293 if [ ! -s "$SRC/$TARBALL" ]; then
pankso@177 294 local url
slaxemulator@458 295 url="$MIRROR_URL/sources/packages"
pankso@177 296 url=$url/${TARBALL:0:1}/$TARBALL
al@596 297 _ "Getting source from mirror: \$url"
al@596 298 busybox wget -c -P $SRC $url || _ "ERROR: wget \$url"
pankso@177 299 fi
al@596 300 _ "Extracting: \$TARBALL"
pankso@1 301 case "$TARBALL" in
pankso@120 302 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
pankso@178 303 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
pankso@1 304 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
pankso@42 305 *.tar) tar xf $SRC/$TARBALL ;;
pankso@42 306 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
pascal@597 307 *.xz) unxz -c $SRC/$TARBALL | tar xf - || tar xf $SRC/$TARBALL 2>/dev/null;;
pankso@42 308 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
pankso@42 309 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
pankso@238 310 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
pankso@191 311 *) cp $SRC/$TARBALL $(pwd) ;;
pankso@1 312 esac
pankso@1 313 }
pankso@1 314
pankso@9 315 # Display cooked package summary.
pankso@1 316 summary() {
pankso@1 317 cd $WOK/$pkg
slaxemulator@499 318 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
slaxemulator@499 319 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
slaxemulator@499 320 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
pankso@44 321 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
slaxemulator@499 322 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
slaxemulator@499 323 [ "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
al@596 324 cookdate=$(date "$(_ '+%Y-%m-%d %H:%M')")
pankso@101 325 sec=$time
pascal@280 326 div=$(( ($time + 30) / 60))
al@596 327 # L10n: 'm' is for minutes (approximate cooking time)
al@596 328 min=$(_n "~ \${div}m"); [ "$div" = 0 ] && min=""
al@596 329 _ "Summary for: \$PACKAGE \$VERSION"
pankso@1 330 separator
al@596 331 # L10n: keep the same width of translations to get a consistent view
al@596 332 [ "$srcdir" ] && _ "Source dir : \$srcdir"
al@596 333 [ "$TARBALL" ] && _ "Src file : \$TARBALL"
al@596 334 [ "$srcsize" ] && _ "Src size : \$srcsize"
al@596 335 [ "$prod" ] && _ "Produced : \$prod"
al@596 336 _ "Packed : \$fs"
al@596 337 _ "Compressed : \$size"
al@596 338 _ "Files : \$files"
al@596 339 # L10n: 's' is for seconds (cooking time)
al@596 340 _ "Cook time : \${sec}s \$min"
al@596 341 _ "Cook date : \$cookdate"
al@596 342 _ "Host arch : \$ARCH"
al@596 343 separator
pankso@1 344 }
pankso@1 345
paul@62 346 # Display debugging error info.
pankso@15 347 debug_info() {
al@596 348 newline; _ "Debug information"; separator
al@596 349 # L10n: specify your format of date and time (to help: man date)
al@596 350 # L10n: not bad one is '+%x %R'
al@596 351 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
al@596 352 _ "Cook date: \$datenow"
al@596 353 # L10n: Please, translate all messages beginning with ERROR in a same way
al@596 354 lerror=$(_n "ERROR")
pankso@76 355 for error in \
pascal@617 356 ERROR $lerror "No package" "cp: can't" "can't open" "can't cd" \
pascal@473 357 "error:" "fatal error:" "undefined reference to" \
pascal@508 358 "Unable to connect to" "link: cannot find the library" \
pascal@615 359 "CMake Error" ": No such file or directory"
pankso@34 360 do
pankso@34 361 fgrep "$error" $LOGS/$pkg.log
pascal@625 362 done > $LOGS/$pkg.log.debug_info 2>&1
pascal@625 363 cat $LOGS/$pkg.log.debug_info
pascal@625 364 rm -f $LOGS/$pkg.log.debug_info
al@596 365 separator; newline
pankso@15 366 }
pankso@15 367
pankso@1 368 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
pankso@1 369 # so some packages need to copy these files with the receipt and genpkg_rules.
slaxemulator@500 370 copy_generic_files()
slaxemulator@500 371 {
pankso@1 372 # $LOCALE is set in cook.conf
slaxemulator@500 373 if [ "$LOCALE" -a "$WANTED" = "" ]; then
pankso@260 374 if [ -d "$install/usr/share/locale" ]; then
pankso@1 375 mkdir -p $fs/usr/share/locale
pankso@1 376 for i in $LOCALE
pankso@1 377 do
pankso@260 378 if [ -d "$install/usr/share/locale/$i" ]; then
pankso@260 379 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
pankso@1 380 fi
pankso@1 381 done
pankso@1 382 fi
pankso@1 383 fi
pankso@1 384
pankso@1 385 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
pankso@1 386 if [ "$GENERIC_PIXMAPS" != "no" ]; then
pankso@260 387 if [ -d "$install/usr/share/pixmaps" ]; then
pankso@1 388 mkdir -p $fs/usr/share/pixmaps
slaxemulator@500 389 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
slaxemulator@500 390 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
slaxemulator@500 391 $fs/usr/share/pixmaps
slaxemulator@500 392 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
slaxemulator@500 393 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
slaxemulator@500 394 $fs/usr/share/pixmaps
slaxemulator@500 395 fi
pankso@1 396 fi
pankso@1 397
pankso@1 398 # Custom or homemade PNG pixmap can be in stuff.
pankso@1 399 if [ -f "$stuff/$PACKAGE.png" ]; then
pankso@1 400 mkdir -p $fs/usr/share/pixmaps
pankso@1 401 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
pankso@1 402 fi
pankso@1 403 fi
pankso@1 404
pankso@1 405 # Desktop entry (.desktop).
erjo@284 406 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
erjo@284 407 if [ "$GENERIC_MENUS" != "no" ]; then
erjo@284 408 if [ -d "$install/usr/share/applications" ] && [ "$WANTED" == "" ]; then
slaxemulator@500 409 mkdir -p $fs/usr/share
erjo@284 410 cp -a $install/usr/share/applications $fs/usr/share
erjo@284 411 fi
pankso@1 412 fi
pankso@1 413
pankso@1 414 # Homemade desktop file(s) can be in stuff.
pankso@1 415 if [ -d "$stuff/applications" ]; then
pankso@1 416 mkdir -p $fs/usr/share
pankso@1 417 cp -a $stuff/applications $fs/usr/share
pankso@1 418 fi
pankso@1 419 if [ -f "$stuff/$PACKAGE.desktop" ]; then
pankso@1 420 mkdir -p $fs/usr/share/applications
pankso@1 421 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
pankso@1 422 fi
pankso@662 423
slaxemulator@500 424 # Add custom licenses
slaxemulator@500 425 if [ -d "$stuff/licenses" ]; then
slaxemulator@500 426 mkdir -p $fs/usr/share/licenses
slaxemulator@500 427 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
slaxemulator@500 428 fi
pankso@1 429 }
pankso@1 430
al@596 431 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
paul@647 432 # as removing unneeded files like in Python packages. Cross compiled binaries
pankso@415 433 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
pankso@421 434 strip_package() {
pankso@415 435 case "$ARCH" in
pankso@415 436 arm|x86_64) export STRIP=${HOST_SYSTEM}-strip ;;
pankso@415 437 *) export STRIP=strip ;;
pankso@415 438 esac
al@596 439 _n "Executing strip on all files..."
pankso@1 440 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
pankso@1 441 do
pankso@1 442 if [ -d "$dir" ]; then
pankso@414 443 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
pankso@1 444 fi
pankso@1 445 done
pankso@414 446 find $fs -name "*.so*" -exec $STRIP -s '{}' 2>/dev/null \;
pankso@414 447 find $fs -name "*.a" -exec $STRIP --strip-debug '{}' 2>/dev/null \;
pankso@1 448 status
pankso@67 449
pankso@117 450 # Remove Python .pyc and .pyo from packages.
pankso@150 451 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
al@596 452 _n "Removing Python compiled files..."
pankso@67 453 find $fs -type f -name "*.pyc" -delete 2>/dev/null
pankso@67 454 find $fs -type f -name "*.pyo" -delete 2>/dev/null
pankso@117 455 status
pankso@117 456 fi
pankso@117 457
pankso@117 458 # Remove Perl perllocal.pod and .packlist from packages.
pankso@117 459 if echo "$DEPENDS" | fgrep -q "perl"; then
al@596 460 _n "Removing Perl compiled files..."
pankso@67 461 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
pankso@67 462 find $fs -type f -name ".packlist" -delete 2>/dev/null
pankso@67 463 status
pankso@67 464 fi
pankso@1 465 }
pankso@1 466
pankso@8 467 # Remove installed deps.
pankso@8 468 remove_deps() {
pankso@8 469 # Now remove installed build deps.
pascal@609 470 diff="/tmp/installed.cook.diff"
pascal@609 471 if [ -s $diff ]; then
pankso@113 472 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
pankso@113 473 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
al@596 474 _n "Build dependencies to remove: "; echo $nb $root
al@596 475 _n "Removing:"
pankso@8 476 for dep in $deps
pankso@8 477 do
pankso@8 478 echo -n " $dep"
pankso@426 479 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
pankso@8 480 done
al@596 481 newline; newline
pankso@113 482 # Keep the last diff for debug and info.
pascal@609 483 mv -f $diff $CACHE/installed.diff
pankso@1 484 fi
pankso@1 485 }
pankso@1 486
pankso@1 487 # The main cook function.
pankso@1 488 cookit() {
al@596 489 _ "Cook: \$PACKAGE \$VERSION"; separator
pankso@1 490 set_paths
pankso@359 491
pankso@377 492 # Handle cross-tools.
pankso@359 493 case "$ARCH" in
pankso@359 494 arm|x86_64)
paul@387 495 # CROSS_COMPILE is used by at least Busybox and the kernel to set
al@596 496 # the cross-tools prefix. Sysroot is the root of our target arch
pankso@443 497 sysroot=$CROSS_TREE/sysroot
pankso@443 498 tools=$CROSS_TREE/tools
pankso@443 499 # Set root path when cross compiling. ARM tested but not x86_64
pankso@443 500 # When cross compiling we must install build deps in $sysroot.
pankso@443 501 arch="-${ARCH}"
pankso@443 502 root=$sysroot
al@596 503 _ "\$ARCH sysroot: \$sysroot"
al@596 504 _ "Adding \$tools/bin to PATH"
pankso@443 505 export PATH=$PATH:$tools/bin
pankso@446 506 export PKG_CONFIG_PATH=$sysroot/usr/lib/pkgconfig
pankso@421 507 export CROSS_COMPILE=${HOST_SYSTEM}-
al@596 508 _ "Using cross-tools: \$CROSS_COMPILE"
pankso@438 509 if [ "$ARCH" == "x86_64" ]; then
pankso@438 510 export CC="${HOST_SYSTEM}-gcc -m64"
pankso@438 511 export CXX="${HOST_SYSTEM}-g++ -m64"
pankso@438 512 else
pankso@438 513 export CC=${HOST_SYSTEM}-gcc
pankso@438 514 export CXX=${HOST_SYSTEM}-g++
pankso@438 515 fi
pankso@377 516 export AR=${HOST_SYSTEM}-ar
pankso@377 517 export AS=${HOST_SYSTEM}-as
pankso@377 518 export RANLIB=${HOST_SYSTEM}-ranlib
pankso@377 519 export LD=${HOST_SYSTEM}-ld
pankso@443 520 export STRIP=${HOST_SYSTEM}-strip ;;
pankso@359 521 esac
pankso@359 522
pankso@9 523 [ "$QA" ] && receipt_quality
pankso@44 524 cd $pkgdir
pascal@607 525 rm -rf install taz source 2> /dev/null
pankso@1 526
pankso@1 527 # Disable -pipe if less than 512Mb free RAM.
pankso@1 528 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
pankso@1 529 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
al@596 530 _ "Disabling -pipe compile flag: \$free RAM"
pankso@1 531 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
pankso@47 532 CXXFLAGS="${CXXFLAGS/-pipe}" && \
pankso@47 533 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
pankso@1 534 fi
pankso@1 535 unset free
pankso@1 536
pankso@232 537 # Export flags and path to be used by make and receipt.
pankso@44 538 DESTDIR=$pkgdir/install
al@596 539 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
pankso@232 540 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
pankso@358 541 #LDFLAGS
pankso@1 542
pankso@126 543 # Check for build deps and handle implicit depends of *-dev packages
pankso@126 544 # (ex: libusb-dev :: libusb).
pankso@215 545 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
pankso@215 546 touch $CACHE/installed.local $CACHE/installed.web
al@596 547 [ "$BUILD_DEPENDS" ] && _ "Checking build dependencies..."
al@596 548 [ "$root" ] && _ "Using packages DB: \${root}\$DB"
pankso@1 549 for dep in $BUILD_DEPENDS
pankso@1 550 do
pankso@126 551 implicit=${dep%-dev}
pankso@131 552 for i in $dep $implicit
pankso@126 553 do
pankso@426 554 if [ ! -f "${root}$INSTALLED/$i/receipt" ]; then
paul@174 555 # Try local package first. In some cases implicit doesn't exist, ex:
paul@174 556 # libboost-dev exists but not libboost, so check if we got vers.
pankso@173 557 unset vers
pascal@343 558 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
pankso@435 559 # We may have a local package.
pankso@435 560 if [ ! "$vers" ]; then
pankso@435 561 vers=$(grep "^$i |" $PKGS/packages.desc | awk '{print $3}')
pankso@435 562 fi
pankso@435 563 debug "bdep: $i version: $vers"
pankso@426 564 if [ -f "$PKGS/$i-${vers}${arch}.tazpkg" ]; then
pankso@426 565 echo $i-${vers}${arch}.tazpkg >> $CACHE/installed.local
pankso@126 566 else
paul@227 567 # Priority to package version in wok (maybe more up-to-date)
paul@227 568 # than the mirrored one.
pankso@173 569 if [ "$vers" ]; then
pankso@426 570 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
pankso@215 571 echo $i >> $CACHE/installed.web
pankso@198 572 else
paul@211 573 # So package exists in wok but not available.
al@596 574 _ "Missing dep (wok/pkg): \$i \$vers"
pankso@215 575 echo $i >> $CACHE/missing.dep
pankso@198 576 fi
pankso@225 577 else
pankso@435 578 # Package is not in wok but may be in online repo.
pankso@426 579 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
pankso@225 580 echo $i >> $CACHE/installed.web
pankso@225 581 else
al@596 582 _ "ERROR: unknown dep \$i"; exit 1
pankso@225 583 fi
pankso@173 584 fi
pankso@126 585 fi
pankso@1 586 fi
pankso@126 587 done
pankso@1 588 done
pankso@225 589
pankso@215 590 # Get the list of installed packages
pankso@426 591 cd ${root}$INSTALLED && ls -1 > $CACHE/installed.list
pankso@358 592
al@596 593 # Have we a missing build dep to cook?
pankso@215 594 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
al@596 595 _ "Auto cook config is set: AUTO_COOK"
pankso@204 596 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
pankso@224 597 for i in $(uniq $CACHE/missing.dep)
pankso@204 598 do
al@596 599 (_ "Building dep (wok/pkg) : \$i \$vers") | \
pankso@204 600 tee -a $LOGS/$PACKAGE.log.$$
al@596 601 # programmers: next two messages are exact copy from remove_deps()
al@596 602 togrep1=$(_n "Build dependencies to remove: ")
al@596 603 togrep2=$(_n "Removing:")
al@596 604 cook $i || (_ "ERROR: can't cook dep '\$i'" && newline && \
al@596 605 fgrep $togrep1 $LOGS/$i.log && \
al@596 606 fgrep $togrep2 $LOGS/$i.log && newline) | \
pankso@204 607 tee -a $LOGS/$PACKAGE.log.$$ && break
pankso@204 608 done
pankso@215 609 rm -f $CACHE/missing.dep
pankso@204 610 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
pankso@204 611 fi
pankso@358 612
paul@211 613 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
paul@211 614 # is enabled and cook fails we have ERROR in log, if no auto cook we have
pankso@204 615 # missing dep in cached file.
al@596 616 lerror=$(_n "ERROR")
pascal@613 617 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
pankso@215 618 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
al@596 619 _ "ERROR: missing dep \$nb" && exit 1
pankso@202 620 fi
pankso@358 621
pankso@426 622 # Install local packages: package-version${arch}
pankso@215 623 cd $PKGS
pankso@224 624 for i in $(uniq $CACHE/installed.local)
pankso@215 625 do
al@596 626 _ "Installing dep (pkg/local): \$i"
pankso@423 627 tazpkg install $i --root=$root >/dev/null
pankso@215 628 done
pankso@358 629
pankso@215 630 # Install web or cached packages (if mirror is set to $PKGS we only
pankso@215 631 # use local packages).
pankso@224 632 for i in $(uniq $CACHE/installed.web)
pankso@215 633 do
al@596 634 _ "Installing dep (web/cache): \$i"
pankso@423 635 tazpkg get-install $i --root=$root >/dev/null
pankso@215 636 done
pankso@358 637
pankso@215 638 # If a cook failed deps are removed.
pankso@426 639 cd ${root}$INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
pascal@609 640 [ ! -s "/tmp/installed.cook.diff" ] && \
pascal@609 641 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
pascal@609 642 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
pankso@202 643
pankso@1 644 # Get source tarball and make sure we have source dir named:
paul@62 645 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
paul@62 646 # tarball if it exists.
pankso@1 647 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
pankso@1 648 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
pankso@10 649 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
pankso@190 650 LZMA_SRC=""
pankso@1 651 else
pankso@1 652 get_source || exit 1
pankso@1 653 fi
pankso@1 654 fi
pankso@242 655 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
pankso@1 656 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
pascal@268 657 if ! extract_source ; then
pascal@268 658 get_source
pascal@268 659 extract_source || exit 1
pascal@268 660 fi
pankso@190 661 if [ "$LZMA_SRC" ]; then
pankso@190 662 cd $pkgdir/source
pankso@190 663 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
pankso@190 664 mv tmp tmp-1 && mkdir tmp
pankso@190 665 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
pankso@190 666 fi
pankso@190 667 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
pankso@358 668 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
pankso@190 669 fi
pankso@190 670 fi
pankso@190 671 cd $pkgdir/source/tmp
paul@62 672 # Some archives are not well done and don't extract to one dir (ex lzma).
pankso@57 673 files=$(ls | wc -l)
pankso@244 674 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
pankso@244 675 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
pankso@244 676 mv * ../$PACKAGE-$VERSION/$TARBALL
pankso@57 677 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
pankso@57 678 mv * ../$PACKAGE-$VERSION
pankso@1 679 cd .. && rm -rf tmp
pankso@1 680 fi
pankso@662 681
pankso@658 682 # Libtool shared libs path hack.
pankso@658 683 case "$ARCH" in
pankso@658 684 arm*) cross libhack ;;
pankso@658 685 esac
pankso@1 686
pankso@9 687 # Execute receipt rules.
pankso@44 688 if grep -q ^compile_rules $receipt; then
al@596 689 _ "Executing: compile_rules"
pankso@352 690 echo "CFLAGS : $CFLAGS"
pankso@358 691 #echo "LDFLAGS : $LDFLAGS"
pankso@55 692 [ -d "$src" ] && cd $src
pankso@97 693 compile_rules $@ || exit 1
pankso@10 694 # Stay compatible with _pkg
pankso@55 695 [ -d "$src/_pkg" ] && mv $src/_pkg $install
pankso@9 696 # QA: compile_rules success so valid.
pankso@9 697 mkdir -p $install
pankso@9 698 else
al@596 699 # QA: no compile_rules so no error, valid.
pankso@9 700 mkdir -p $install
pankso@1 701 fi
al@596 702 separator; newline
pankso@360 703
pankso@360 704 # Execute testsuite.
pankso@360 705 if grep -q ^testsuite $receipt; then
al@596 706 _ "Running testsuite"; separator
pankso@360 707 testsuite $@ || exit 1
al@596 708 separator; newline
pankso@360 709 fi
pankso@1 710 }
pankso@1 711
pankso@1 712 # Cook quality assurance.
pankso@1 713 cookit_quality() {
pankso@9 714 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
al@596 715 _ "ERROR: cook failed" | tee -a $LOGS/$pkg.log
pankso@9 716 fi
pankso@9 717 # ERROR can be echoed any time in cookit()
al@596 718 lerror=$(_n "ERROR")
pascal@618 719 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
pascal@618 720 grep -Eq "(^$lerror|undefined reference to)" ; then
pankso@17 721 debug_info | tee -a $LOGS/$pkg.log
pankso@33 722 rm -f $command && exit 1
pankso@1 723 fi
pankso@1 724 }
pankso@1 725
pankso@16 726 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
paul@62 727 # but it doesn't handle EXTRAVERSION.
pankso@1 728 packit() {
pankso@1 729 set_paths
pankso@359 730
pankso@359 731 # Handle cross compilation
pankso@359 732 case "$ARCH" in
pankso@428 733 arm|x86_64) arch="-$ARCH" ;;
pankso@359 734 esac
pankso@359 735
al@596 736 _ "Pack: \$PACKAGE \${VERSION}\${arch}"; separator
pankso@359 737
pankso@44 738 if grep -q ^genpkg_rules $receipt; then
al@596 739 _ "Executing: genpkg_rules"
pankso@259 740 set -e && cd $pkgdir && mkdir -p $fs
al@596 741 genpkg_rules || (newline; _ "ERROR: genpkg_rules failed"; newline) >> \
pankso@234 742 $LOGS/$pkg.log
pankso@241 743 else
al@596 744 _ "No packages rules: meta package"
pankso@241 745 mkdir -p $fs
pankso@16 746 fi
pankso@98 747
pankso@98 748 # First QA check to stop now if genpkg_rules failed.
al@596 749 lerror=$(_n "ERROR")
pascal@613 750 if fgrep -q ^$lerror $LOGS/$pkg.log; then
pankso@98 751 exit 1
pankso@98 752 fi
pankso@358 753
pankso@44 754 cd $taz
pankso@1 755 for file in receipt description.txt
pankso@1 756 do
pankso@1 757 [ ! -f "../$file" ] && continue
al@596 758 _n "Copying \$file..."
pankso@1 759 cp -f ../$file $pack && chown 0.0 $pack/$file && status
pankso@1 760 done
pankso@119 761 copy_generic_files
pankso@358 762
paul@62 763 # Create files.list with redirecting find output.
al@596 764 _n "Creating the list of files..."
al@596 765 cd $fs
pankso@16 766 find . -type f -print > ../files.list
pankso@16 767 find . -type l -print >> ../files.list
pankso@16 768 cd .. && sed -i s/'^.'/''/ files.list
pankso@16 769 status
pankso@43 770
pankso@119 771 # Strip and stuff files.
pankso@43 772 strip_package
pankso@43 773
pankso@43 774 # Md5sum of files.
al@596 775 _n "Creating md5sum of files..."
pankso@16 776 while read file; do
pankso@16 777 [ -L "fs$file" ] && continue
pankso@16 778 [ -f "fs$file" ] || continue
pankso@16 779 case "$file" in
pankso@232 780 /lib/modules/*/modules.*|*.pyc) continue ;;
pankso@16 781 esac
pankso@16 782 md5sum "fs$file" | sed 's/ fs/ /'
pankso@16 783 done < files.list > md5sum
pankso@16 784 status
pankso@16 785 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
pankso@16 786 description.txt 2> /dev/null | awk \
pankso@16 787 '{ sz=$1 } END { print sz }')
pankso@358 788
pankso@16 789 # Build cpio archives.
al@596 790 _n "Compressing the fs..."
pankso@16 791 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
pankso@16 792 rm -rf fs
pankso@16 793 status
pankso@16 794 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
pankso@16 795 md5sum description.txt 2> /dev/null | awk \
pankso@16 796 '{ sz=$1 } END { print sz }')
al@596 797 _n "Updating receipt sizes..."
pankso@16 798 sed -i s/^PACKED_SIZE.*$// receipt
pankso@16 799 sed -i s/^UNPACKED_SIZE.*$// receipt
pankso@16 800 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
pankso@16 801 status
pankso@16 802
pankso@16 803 # Set extra version.
pankso@16 804 if [ "$EXTRAVERSION" ]; then
al@596 805 _n "Updating receipt EXTRAVERSION: \$EXTRAVERSION"
pankso@16 806 sed -i s/^EXTRAVERSION.*$// receipt
pankso@16 807 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
pankso@16 808 status
pankso@16 809 fi
pankso@16 810
pankso@16 811 # Compress.
al@596 812 _n "Creating full cpio archive..."
pankso@16 813 find . -print | cpio -o -H newc --quiet > \
pankso@428 814 ../$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg
pankso@16 815 status
al@596 816 _n "Restoring original package tree..."
pankso@16 817 unlzma -c fs.cpio.lzma | cpio -idm --quiet
pankso@16 818 status
pankso@16 819 rm fs.cpio.lzma && cd ..
pankso@43 820
pankso@43 821 # QA and give info.
pankso@43 822 tazpkg=$(ls *.tazpkg)
pankso@43 823 packit_quality
al@596 824 separator; _ "Package: \$tazpkg"; newline
pankso@1 825 }
pankso@1 826
paul@62 827 # Verify package quality and consistency.
pankso@8 828 packit_quality() {
al@596 829 #gettext "QA: checking for broken link..."
pankso@157 830 #link=$(find $fs/usr -type l -follow)
pankso@157 831 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
pankso@157 832 #status
pankso@358 833
pankso@142 834 # Exit if any error found in log file.
al@596 835 lerror=$(_n "ERROR")
pascal@613 836 if fgrep -q ^$lerror $LOGS/$pkg.log; then
pankso@32 837 rm -f $command && exit 1
pankso@8 838 fi
pankso@358 839
al@596 840 _n "QA: checking for empty package..."
pankso@45 841 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
pankso@259 842 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
al@596 843 newline; _ "ERROR: empty package"
pankso@32 844 rm -f $command && exit 1
pankso@8 845 else
pankso@134 846 # Ls sort by name so the first file is the one we want.
pankso@136 847 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
pankso@134 848 status
pankso@154 849 if [ -f "$old" ]; then
al@596 850 old_pkg=$(basename $old)
al@596 851 _n "Removing old: \$old_pkg"
pankso@135 852 rm -f $old && status
pankso@154 853 fi
pankso@134 854 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
pankso@11 855 sed -i /^${pkg}$/d $broken
pankso@265 856 #gettext "Removing source tree..."
pankso@265 857 #rm -f $WOK/$pkg/source && status
pankso@8 858 fi
pankso@8 859 }
pankso@8 860
pankso@427 861 # Tic tac, tic tac...
pankso@421 862 tac() {
pascal@285 863 sed '1!G;h;$!d' $1
pascal@285 864 }
pascal@285 865
pankso@428 866 # Install package on --install or update the chroot.
pankso@428 867 install_package() {
pankso@428 868 case "$ARCH" in
pankso@428 869 arm|x86_64)
pankso@428 870 arch="-${ARCH}"
pankso@443 871 root=$CROSS_TREE/sysroot ;;
pankso@428 872 esac
pankso@428 873 # Install package if requested but skip install if target host doesn't
pankso@428 874 # match build system or it will break the build chroot.
pankso@428 875 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
pankso@428 876 if [ "$inst" ] && [ "$build" == "$ARCH" ]; then
pankso@428 877 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
pankso@428 878 cd $PKGS && tazpkg install \
pankso@428 879 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
pankso@428 880 else
al@596 881 _ "Unable to install package, build has failed."; newline
pankso@428 882 exit 1
pankso@428 883 fi
pankso@428 884 fi
pankso@428 885
pankso@428 886 # Install package if part of the chroot to keep env up-to-date.
pankso@428 887 if [ -d "${root}$INSTALLED/$pkg" ]; then
pankso@428 888 . /etc/slitaz/cook.conf
pankso@428 889 . $WOK/$pkg/taz/$pkg-*/receipt
al@596 890 _ "Updating \$ARCH chroot environment..."
al@596 891 _ "Updating chroot: \$pkg (\${VERSION}\${EXTRAVERSION}\${arch})" | log
pankso@428 892 cd $PKGS && tazpkg install \
pankso@428 893 $pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg \
pankso@428 894 --forced --root=$root
pankso@428 895 fi
pankso@428 896 }
pankso@428 897
pascal@285 898 # Launch the cook command into a chroot jail protected by aufs.
pascal@285 899 # The current filesystems are used read-only and updates are
pascal@285 900 # stored in a separate branch.
pascal@285 901 try_aufs_chroot() {
pascal@285 902
pascal@286 903 base=/dev/shm/aufsmnt$$
pascal@286 904
al@596 905 # Can we setup the chroot? Is it already done?
pascal@292 906 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
pascal@594 907 grep -q ^AUFS_NOT_RAMFS $receipt && base=/mnt/aufsmnt$$
pascal@285 908 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
pascal@285 909 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
pascal@286 910 mkdir ${base}root ${base}rw || return
pascal@285 911
al@596 912 _ "Setup aufs chroot..."
pascal@285 913
pascal@285 914 # Sanity check
pascal@286 915 for i in / /proc /sys /dev/shm /home ; do
pascal@285 916 case " $AUFS_MOUNTS " in
pascal@285 917 *\ $i\ *) ;;
pascal@285 918 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
pascal@285 919 esac
pascal@285 920 done
pascal@285 921 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
pascal@285 922 mount --bind $mnt ${base}root$mnt
pascal@285 923 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
al@596 924 _ "Aufs mountage failure"
slaxemulator@519 925 umount ${base}root
pascal@628 926 rm -rf ${base}r*
slaxemulator@519 927 return
pascal@285 928 fi
pascal@285 929 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
pascal@285 930 done
pascal@285 931
pascal@285 932 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
pascal@285 933 status=$?
pascal@285 934
al@596 935 _ "Leaving aufs chroot..."
pascal@285 936 tac ${base}rw/aufs-umount.sh | sh
pascal@285 937 rm -rf ${base}rw
pascal@285 938 umount ${base}root
pascal@285 939 rmdir $base*
pankso@428 940 # Dont install pkg twice... it's done after
pankso@428 941 #install_package
pankso@358 942 exit $status
pascal@285 943 }
pascal@285 944
paul@387 945 # Create a XML feed for freshly built packages.
pankso@310 946 gen_rss() {
pankso@310 947 pubdate=$(date "+%a, %d %b %Y %X")
pankso@310 948 cat > $FEEDS/$pkg.xml << EOT
pankso@310 949 <item>
pankso@310 950 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
pankso@310 951 <link>${COOKER_URL}?pkg=$PACKAGE</link>
pankso@310 952 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
pankso@310 953 <pubDate>$pubdate</pubDate>
pankso@310 954 <description>$SHORT_DESC</description>
pankso@310 955 </item>
pankso@310 956 EOT
pankso@310 957 }
pankso@310 958
pankso@662 959 # Truncate stdout log file to $1 Mb.
pascal@576 960 loglimit()
pascal@576 961 {
pascal@593 962 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
pascal@621 963 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
pascal@593 964 else
pascal@593 965 tee /dev/stderr
pascal@593 966 fi
pascal@576 967 }
pascal@576 968
al@598 969 # Search file in mirrored packages
al@598 970 search_file_mirror()
al@598 971 {
al@598 972 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
al@598 973 }
al@598 974
al@598 975 # Search file in local wok packages
al@598 976 search_file_local()
al@598 977 {
al@598 978 # existing packages have precedence over the package/taz folder
al@598 979 srch=$1
al@598 980 { for package in $(find $PKGS -name '*.tazpkg'); do
al@598 981 if [ ! "x$(busybox cpio --to-stdout --quiet -i files.list < $package | grep /$srch\$)" == "x" ]; then
al@598 982 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
al@598 983 fi
al@598 984 done } | sort -u
al@598 985 }
al@598 986
al@598 987 # Ask in multiple choice
al@598 988 ask_multiple()
al@598 989 {
al@598 990 local multiples first my_choice
al@598 991 multiples="$1"
al@598 992 first=$(echo "$multiples" | head -n1)
al@598 993 newline; _ "Multiple choice:\n$multiples\n"
al@598 994 _ "Select one [$first]: "; read my_choice
al@598 995 [ "x$my_choice" == "x" ] && my_choice="$first"
al@598 996 found=$my_choice
al@598 997 }
al@598 998
al@598 999 # Search file in local cache (fast), local wok packages, mirrored packages
al@598 1000 search_file()
al@598 1001 {
al@598 1002 local srch cache missing
al@598 1003 srch=$1
al@598 1004 cache=/var/cache/ldsearch.cache
al@598 1005 missing=/var/cache/missing.file
al@598 1006 touch $cache $missing
al@598 1007 found=$(grep $srch $cache | cut -d' ' -f2)
al@598 1008 if [ "x$found" == "x" ]; then
al@598 1009 found=$(search_file_local $srch)
al@598 1010 if [ "x$found" != "x" ]; then
al@598 1011 if [ $(echo "$found" | wc -l) -gt 1 ]; then
al@598 1012 ask_multiple "$found"
al@598 1013 fi
al@598 1014 echo "$srch $found" >> $cache
al@598 1015 else
al@598 1016 found=$(search_file_mirror $srch)
al@598 1017 if [ "x$found" != "x" ]; then
al@598 1018 if [ $(echo "$found" | wc -l) -gt 1 ]; then
al@598 1019 ask_multiple "$found"
al@598 1020 fi
al@598 1021 echo "$srch $found" >> $cache
al@598 1022 else
al@598 1023 echo "$srch" >> $missing
al@598 1024 fi
al@598 1025 fi
al@598 1026 fi
al@598 1027 }
al@598 1028
pankso@1 1029 #
pankso@1 1030 # Commands
pankso@1 1031 #
pankso@1 1032
pankso@1 1033 case "$1" in
pankso@32 1034 usage|help|-u|-h)
pankso@1 1035 usage ;;
pankso@1 1036 list-wok)
pankso@642 1037 newline; _ "List of \$ARCH packages in: \$WOK"; separator
pankso@642 1038 cd $WOK
pankso@642 1039 if [ "$ARCH" != "i486" ]; then
pankso@643 1040 count=0
pankso@662 1041 for pkg in $(fgrep 'HOST_ARCH=' */receipt | fgrep $ARCH | cut -d : -f 1)
pankso@643 1042 do
pankso@643 1043 unset HOST_ARCH
pankso@643 1044 . $pkg
pankso@643 1045 count=$(($count + 1))
pankso@643 1046 colorize 34 "$PACKAGE"
pankso@643 1047 done
pankso@642 1048 else
pankso@643 1049 count=$(ls | wc -l)
pankso@643 1050 ls -1
pankso@642 1051 fi
pankso@1 1052 separator
pankso@643 1053 _n "Packages:"; colorize 32 " $count"
pankso@643 1054 newline ;;
pankso@378 1055 activity)
pankso@378 1056 cat $activity ;;
pankso@69 1057 search)
pankso@69 1058 # Just a simple search function, we dont need more actually.
pankso@69 1059 query="$2"
al@596 1060 newline; _ "Search results for: \$query"; separator
pankso@69 1061 cd $WOK && ls -1 | grep "$query"
al@596 1062 separator; newline ;;
pankso@1 1063 setup)
pankso@1 1064 # Setup a build environment
pankso@1 1065 check_root
al@596 1066 _ "Cook: setup environment" | log
al@596 1067 newline; _ "Setting up your environment"; separator
al@596 1068 cd $SLITAZ
pankso@52 1069 init_db_files
al@596 1070 _ "Checking for packages to install..."
pankso@397 1071 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
pankso@645 1072 # ARCH-setup or 'cross check' should be used before: cook setup
pankso@397 1073 case "$ARCH" in
pankso@421 1074 arm|x86_64)
pankso@397 1075 if [ ! -x "/usr/bin/cross" ]; then
al@596 1076 _ "ERROR: cross is not installed"
pankso@397 1077 exit 1
pankso@397 1078 fi
al@596 1079 _ "Using config file: /etc/slitaz/cross.conf"
pankso@397 1080 . /etc/slitaz/cross.conf ;;
pankso@397 1081 esac
pankso@397 1082 for pkg in $SETUP_PKGS; do
pankso@397 1083 if [ "$forced" ]; then
pankso@421 1084 tazpkg -gi $pkg --forced
pankso@397 1085 else
pankso@407 1086 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
pankso@397 1087 fi
pankso@397 1088 done
pankso@1 1089
pankso@1 1090 # Handle --options
pankso@1 1091 case "$2" in
pankso@397 1092 --wok)
pankso@230 1093 hg clone $WOK_URL wok || exit 1 ;;
pankso@230 1094 --stable)
pankso@230 1095 hg clone $WOK_URL-stable wok || exit 1 ;;
pankso@230 1096 --undigest)
pankso@230 1097 hg clone $WOK_URL-undigest wok || exit 1 ;;
pankso@397 1098 --tiny)
pankso@397 1099 hg clone $WOK_URL-tiny wok || exit 1 ;;
pankso@1 1100 esac
pankso@1 1101
pankso@1 1102 # SliTaz group and permissions
pankso@1 1103 if ! grep -q ^slitaz /etc/group; then
al@596 1104 _ "Adding group: slitaz"
pankso@1 1105 addgroup slitaz
pankso@1 1106 fi
al@596 1107 _ "Setting permissions for slitaz group..."
pascal@277 1108 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
pascal@277 1109 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
al@596 1110 separator; _ "All done, ready to cook packages :-)"; newline ;;
pankso@395 1111 *-setup)
pankso@395 1112 # Setup for cross compiling.
pankso@395 1113 arch=${1%-setup}
pankso@397 1114 check_root
pankso@644 1115 . /etc/slitaz/cook.conf
pankso@644 1116 for pkg in $CROSS_SETUP; do
pankso@644 1117 if [ "$forced" ]; then
pankso@644 1118 tazpkg -gi $pkg --forced
pankso@644 1119 else
pankso@644 1120 [ -d "$INSTALLED/$pkg" ] || tazpkg -gi $pkg
pankso@644 1121 fi
pankso@644 1122 done
al@596 1123 _ "Cook: setup \$arch cross environment" | log
al@596 1124 newline; boldify $(_n "Setting up your \$arch cross environment"); separator
pankso@397 1125 init_db_files
pankso@359 1126 sed -i \
pankso@396 1127 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
pankso@443 1128 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
pankso@359 1129 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
pankso@395 1130 /etc/slitaz/cook.conf
pankso@395 1131 case "$arch" in
pankso@395 1132 arm)
pankso@650 1133 flags="-O2 -march=armv6"
pankso@650 1134 host="$ARCH-slitaz-linux-gnueabi" ;;
pankso@650 1135 armv6hf)
pankso@650 1136 flags="-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard"
pankso@650 1137 host="$ARCH-slitaz-linux-gnueabi" ;;
pankso@650 1138 armv7)
pankso@650 1139 flags="-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe"
pankso@650 1140 host="$ARCH-slitaz-linux-gnueabi" ;;
pankso@395 1141 x86_64)
pankso@653 1142 flags="-02 -march=generic -pipe"
pankso@650 1143 host="$ARCH-slitaz-linux" ;;
pankso@395 1144 esac
pankso@650 1145 sed -i \
pankso@650 1146 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
pankso@650 1147 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" \
pankso@650 1148 /etc/slitaz/cook.conf
pankso@359 1149 . /etc/slitaz/cook.conf
pankso@443 1150 sysroot=$CROSS_TREE/sysroot
pankso@443 1151 tools=/cross/$arch/tools
pankso@443 1152 root=$sysroot
pankso@443 1153 CC=$tools/bin/${HOST_SYSTEM}-gcc
al@596 1154 # L10n: keep the same width of translations to get a consistent view
al@596 1155 _ "Target arch : \$ARCH"
al@596 1156 _ "Configure args : \$CONFIGURE_ARGS"
pankso@650 1157 _ "Build flags : \$flags"
al@596 1158 _ "Arch sysroot : \$sysroot"
al@596 1159 _ "Tools prefix : \$tools/bin"
paul@455 1160 # Tell the packages manager where to find packages.
al@596 1161 _ "Packages DB : \${root}\$DB"
pankso@429 1162 mkdir -p ${root}$INSTALLED
pankso@426 1163 cd ${root}$DB && rm -f *.bak
pankso@426 1164 for list in packages.list packages.desc packages.equiv packages.md5
pankso@426 1165 do
pankso@426 1166 rm -f $list && ln -s $SLITAZ/packages/$list $list
pankso@426 1167 done
pankso@429 1168 # We must have the cross compiled glibc-base installed or default
pankso@429 1169 # i486 package will be used as dep by tazpkg and then break the
pankso@429 1170 # cross environment
pankso@429 1171 if [ ! -f "${root}$INSTALLED/glibc-base/receipt" ]; then
al@596 1172 colorize 36 $(_ "WARNING: (e)glibc-base is not installed in sysroot")
pankso@429 1173 fi
pankso@426 1174 # Show GCC version or warn if not yet compiled.
pankso@406 1175 if [ -x $CC ]; then
al@596 1176 _ "Cross compiler : \${HOST_SYSTEM}-gcc"
pankso@359 1177 else
al@596 1178 colorize 36 $(_ "C compiler is missing: \${HOST_SYSTEM}-gcc")
al@596 1179 _ "Run 'cross compile' to cook a toolchain"
pankso@397 1180 fi
al@596 1181 separator; newline ;;
pankso@9 1182 test)
pankso@9 1183 # Test a cook environment.
al@596 1184 _ "Cook test: testing the cook environment" | log
pankso@9 1185 [ ! -d "$WOK" ] && exit 1
pankso@9 1186 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
pankso@9 1187 cook cooktest ;;
pankso@1 1188 new)
pankso@1 1189 # Create the package folder and an empty receipt.
pankso@1 1190 pkg="$2"
pankso@1 1191 [ "$pkg" ] || usage
pankso@427 1192 newline
pankso@1 1193 if [ -d "$WOK/$pkg" ]; then
al@596 1194 _ "\$pkg package already exists."
al@596 1195 exit 1
pankso@1 1196 fi
al@596 1197 _n "Creating \$WOK/\$pkg"
pankso@1 1198 mkdir $WOK/$pkg && cd $WOK/$pkg && status
al@596 1199 _n "Preparing the package receipt..."
pankso@1 1200 cp $DATA/receipt .
pankso@1 1201 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
pankso@427 1202 status && newline
pankso@358 1203
pankso@196 1204 # Interactive mode, asking and seding.
pankso@196 1205 case "$3" in
paul@214 1206 --interactive|-x)
al@596 1207 _ "Entering interactive mode..."
paul@211 1208 separator
al@596 1209 _ "Package : \$pkg"
al@596 1210 _n "Version : " ; read answer
al@596 1211 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
al@596 1212 _n "Category : " ; read answer
al@596 1213 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
al@596 1214 # L10n: Short description
al@596 1215 _n "Short desc : " ; read answer
al@596 1216 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
al@596 1217 _n "Maintainer : " ; read answer
al@596 1218 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
al@596 1219 _n "License : " ; read answer
al@596 1220 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
al@596 1221 _n "Web site : " ; read answer
al@596 1222 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
pankso@427 1223 newline
pankso@196 1224 # Wget URL.
al@596 1225 _ "Wget URL to download source tarball."
al@596 1226 _n "Example : " ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
al@596 1227 _n "Wget url : " ; read answer
al@596 1228 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$answer\""# receipt
pankso@196 1229 # Ask for a stuff dir.
al@596 1230 _n "Do you need a stuff directory? (y/N) : " ; read answer
al@596 1231 if [ "$answer" = "y" ]; then
al@596 1232 _n "Creating the stuff directory..."
pankso@196 1233 mkdir $WOK/$pkg/stuff && status
pankso@196 1234 fi
pankso@196 1235 # Ask for a description file.
al@596 1236 _n "Are you going to write a description? (y/N) : " ; read answer
al@596 1237 if [ "$answer" = "y" ]; then
al@596 1238 _n "Creating the description.txt file..."
pankso@427 1239 newline > $WOK/$pkg/description.txt && status
pankso@196 1240 fi
al@596 1241 separator; _ "Receipt is ready to use."; newline ;;
pankso@196 1242 esac ;;
pankso@1 1243 list)
pankso@1 1244 # Cook a list of packages (better use the Cooker since it will order
pankso@1 1245 # packages before executing cook).
pankso@1 1246 check_root
al@596 1247 [ -z "$2" ] && (newline; _ "No list in argument."; newline) && exit 1
al@596 1248 list2=$2
al@596 1249 [ ! -f "$2" ] && (newline; _ "No list found: \$list2"; newline) && exit 1
al@596 1250 _ "Cook list starting: \$list2" | log
pankso@1 1251 for pkg in $(cat $2)
pankso@1 1252 do
pankso@1 1253 cook $pkg || broken
pankso@1 1254 done ;;
pankso@1 1255 clean-wok)
pankso@1 1256 check_root
al@596 1257 newline; _n "Cleaning all packages files..."
pankso@1 1258 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
al@596 1259 status; newline ;;
pankso@1 1260 clean-src)
pankso@1 1261 check_root
al@596 1262 newline; _n "Cleaning all packages sources..."
pankso@1 1263 rm -rf $WOK/*/source
al@596 1264 status; newline ;;
pankso@662 1265 uncook)
pankso@662 1266 cd $WOK
pankso@662 1267 count=0
pankso@662 1268 newline
paul@665 1269 _ "Checking for uncooked packages"
pankso@662 1270 separator
pankso@662 1271 for pkg in *
pankso@662 1272 do
pankso@664 1273 unset HOST_ARCH EXTRAVERSION
pankso@662 1274 . $pkg/receipt
pankso@662 1275 # Source cooked pkg receipt to get EXTRAVERSION
pankso@663 1276 if [ -d "$WOK/$pkg/taz" ]; then
pankso@663 1277 cd $WOK/$pkg/taz/$pkg-*
pankso@663 1278 . receipt && cd $WOK
pankso@662 1279 fi
pankso@662 1280 case "$ARCH" in
pankso@662 1281 i486)
pankso@662 1282 debug "Package: $PKGS/${PACKAGE}-${VERSION}${EXTRAVERSION}.tazpkg"
pankso@662 1283 if [ ! -f "$PKGS/${PACKAGE}-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
pankso@662 1284 count=$(($count + 1))
pankso@662 1285 colorize 34 "$pkg"
pankso@662 1286 fi ;;
pankso@662 1287 arm)
paul@665 1288 # Check only packages included in arch
pankso@662 1289 if echo "$HOST_ARCH" | fgrep -q "$ARCH"; then
pankso@662 1290 # *.tazpkg
pankso@662 1291 if [ ! -f "$PKGS/${PACKAGE}-${VERSION}${EXTRAVERSION}-${ARCH}.tazpkg" ]; then
pankso@662 1292 count=$(($count + 1))
pankso@662 1293 colorize 34 "$pkg"
pankso@662 1294 fi
pankso@662 1295 fi ;;
pankso@662 1296 esac
pankso@662 1297 done
pankso@662 1298 if [ "$count" -gt "0" ]; then
pankso@662 1299 separator
paul@665 1300 _n "Uncooked packages: "; colorize 31 "$count"
pankso@662 1301 else
pankso@662 1302 _ "All packages are cooked :-)"
pankso@662 1303 fi
pankso@662 1304 newline ;;
pankso@235 1305 pkgdb)
pankso@235 1306 # Create suitable packages list for TazPKG and only for built packages
pankso@235 1307 # as well as flavors files for TazLiTo. We dont need logs since we do it
paul@243 1308 # manually to ensure everything is fine before syncing the mirror.
pankso@239 1309 case "$2" in
pankso@239 1310 --flavors)
pankso@239 1311 continue ;;
pankso@239 1312 *)
pankso@240 1313 [ "$2" ] && PKGS="$2"
pankso@239 1314 [ ! -d "$PKGS" ] && \
al@596 1315 newline && _ "Packages directory doesn't exist" && \
al@596 1316 newline && exit 1 ;;
pankso@239 1317 esac
pankso@226 1318 time=$(date +%s)
pankso@239 1319 flavors=$SLITAZ/flavors
pankso@239 1320 live=$SLITAZ/live
pankso@235 1321 echo "cook:pkgdb" > $command
al@596 1322 _ "Cook pkgdb: Creating all packages lists" | log
al@596 1323 newline; _ "Creating lists for: \$PKGS"; separator
al@596 1324 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
al@596 1325 _ "Cook pkgdb started: \$datenow"
pankso@133 1326 cd $PKGS
pankso@192 1327 rm -f packages.*
al@596 1328 _ "Creating: packages.list"
pankso@85 1329 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
al@596 1330 _ "Creating: packages.md5"
pankso@1 1331 md5sum *.tazpkg > $PKGS/packages.md5
gokhlayeh@297 1332 md5sum packages.md5 | cut -f1 -d' ' > ID
al@596 1333 _ "Creating lists from: \$WOK"
pankso@1 1334 cd $WOK
pankso@1 1335 for pkg in *
pankso@1 1336 do
pankso@1 1337 unset_receipt
pankso@1 1338 . $pkg/receipt
pascal@600 1339 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
pascal@600 1340 if [ -s $pkg/taz/*/receipt ]; then
pascal@600 1341 . $pkg/taz/*/receipt
pascal@600 1342 fi
pankso@1 1343 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
pankso@192 1344 # packages.desc lets us search easily in DB
pankso@1 1345 cat >> $PKGS/packages.desc << EOT
pankso@235 1346 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
pankso@1 1347 EOT
pankso@192 1348 # packages.txt used by tazpkg and tazpkg-web also to provide
pankso@192 1349 # a human readable package list with version and description.
pankso@192 1350 cat >> $PKGS/packages.txt << EOT
pankso@192 1351 $PACKAGE
pankso@235 1352 ${VERSION}$EXTRAVERSION
pankso@235 1353 $SHORT_DESC
pankso@235 1354 $PACKED_SIZE ($UNPACKED_SIZE installed)
pankso@358 1355
pankso@192 1356 EOT
pankso@192 1357 # packages.equiv is used by tazpkg install to check depends.
pankso@1 1358 for i in $PROVIDE; do
pankso@1 1359 DEST=""
pankso@1 1360 echo $i | fgrep -q : && DEST="${i#*:}:"
pankso@1 1361 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
pankso@1 1362 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
pankso@1 1363 $PKGS/packages.equiv
pankso@1 1364 else
pankso@1 1365 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
pankso@1 1366 fi
pankso@1 1367 done
paul@197 1368 # files.list provides a list of all packages files.
pankso@194 1369 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
pankso@194 1370 $PKGS/files.list
pankso@1 1371 fi
pankso@1 1372 done
pankso@358 1373
pankso@213 1374 # Display list size.
al@596 1375 _ "Done: packages.desc"
al@596 1376 _ "Done: packages.txt"
al@596 1377 _ "Done: packages.equiv"
pankso@358 1378
pankso@194 1379 # files.list.lzma
al@596 1380 _ "Creating: files.list.lzma"
pankso@235 1381 cd $PKGS && lzma e files.list files.list.lzma
pankso@194 1382 rm -f files.list
pankso@358 1383
pankso@235 1384 # Display some info.
pankso@1 1385 separator
pankso@1 1386 nb=$(ls $PKGS/*.tazpkg | wc -l)
pankso@226 1387 time=$(($(date +%s) - $time))
al@596 1388 # L10n: 's' is for seconds (cooking time)
al@596 1389 _ "Packages: \$nb - Time: \${time}s"; newline
pankso@358 1390
paul@243 1391 # Create all flavors files at once. Do we really need code to monitor
al@596 1392 # flavors changes? Lets just build them with packages lists before
pankso@235 1393 # syncing the mirror.
pankso@239 1394 [ "$2" == "--flavors" ] || exit 1
al@596 1395 [ ! -d "$flavors" ] && (_ "Missing flavors: \$flavors"; newline) && exit 1
pankso@239 1396 [ -d "$live" ] || mkdir -p $live
al@596 1397 _ "Creating flavors files in: \$live"
al@596 1398 _ "Cook pkgdb: Creating all flavors" | log
pankso@235 1399 separator
al@596 1400 _ "Recharging lists to use latest packages..."
pankso@329 1401 tazpkg recharge >/dev/null 2>/dev/null
pankso@358 1402
pankso@235 1403 # We need a custom tazlito config to set working dir to /home/slitaz.
pankso@235 1404 if [ ! -f "$live/tazlito.conf" ]; then
al@596 1405 _ "Creating configuration file: tazlito.conf"
pankso@235 1406 cp /etc/tazlito/tazlito.conf $live
pankso@235 1407 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
pankso@235 1408 $live/tazlito.conf
pankso@235 1409 fi
pankso@235 1410
pankso@239 1411 # Update Hg flavors repo and pack.
pankso@239 1412 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
pankso@358 1413
pankso@239 1414 cd $live
al@596 1415 _ "Starting to generate flavors..."
pankso@235 1416 rm -f flavors.list *.flavor
pankso@235 1417 for i in $flavors/*
pankso@235 1418 do
pankso@235 1419 fl=$(basename $i)
al@596 1420 _ "Packing flavor: \$fl"
pankso@235 1421 tazlito pack-flavor $fl >/dev/null || exit 1
pankso@235 1422 tazlito show-flavor $fl --brief --noheader 2> \
pankso@235 1423 /dev/null >> flavors.list
pankso@235 1424 done
pankso@237 1425 cp -f $live/*.flavor $live/flavors.list $PKGS
al@596 1426 separator
al@596 1427 fl_size=$(du -sh $live | awk '{print $1}')
al@596 1428 _ "Flavors size: \$fl_size"; newline
al@596 1429 rm -f $command
al@596 1430 separator
al@596 1431 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
al@596 1432 _ "Cook pkgdb end: \$datenow" ;;
pankso@1 1433 *)
pankso@1 1434 # Just cook and generate a package.
pankso@1 1435 check_root
pankso@1 1436 time=$(date +%s)
pankso@1 1437 pkg="$1"
pankso@1 1438 [ -z "$pkg" ] && usage
pankso@44 1439 receipt="$WOK/$pkg/receipt"
pankso@427 1440 check_pkg_in_wok && newline
pankso@47 1441
pankso@377 1442 unset inst
pankso@377 1443 unset_receipt
pankso@377 1444 . $receipt
pankso@377 1445
pankso@377 1446 # Handle cross compilation.
pankso@377 1447 #
pankso@377 1448 # CROSS_NOTE: Actually we are running an ARM cooker but running
paul@647 1449 # the cooker and building each commit in wok is not possible since
pankso@377 1450 # we dont cook the full wok for this arch. For ARM we need a set
paul@387 1451 # of packages to handle a touch screen desktop, servers but not
al@596 1452 # erlang.
pankso@377 1453 #
pankso@377 1454 # The temporary solution is to build only reviewed and tested
pankso@377 1455 # packages with HOST_ARCH set in receipt.
pankso@377 1456 case "$ARCH" in
pankso@377 1457 arm)
pankso@377 1458 if [ ! "$HOST_ARCH" ]; then
al@596 1459 _ "cook: HOST_ARCH is not set in \$pkg receipt"
al@596 1460 _ "cook: This package is not included in: \$ARCH"
al@596 1461 [ "$CROSS_BUGS" ] && _ "bugs: \$CROSS_BUGS"
al@596 1462 _ "Cook skip: \$pkg is not included in: \$ARCH" | log
pankso@427 1463 newline && exit 1
pankso@377 1464 fi ;;
pankso@377 1465 esac
pankso@377 1466
paul@387 1467 # Some packages are not included in some arch or fail to cross compile.
pankso@398 1468 : ${HOST_ARCH=i486}
pankso@662 1469 debug "Host arch $HOST_ARCH"
pankso@381 1470 if ! $(echo "$HOST_ARCH" | fgrep -q $ARCH); then
al@596 1471 _ "cook: HOST_ARCH=\$HOST_ARCH"
al@596 1472 _ "cook: \$pkg doesn't cook or is not included in: \$ARCH"
al@596 1473 [ "$CROSS_BUGS" ] && _ "bugs: \$CROSS_BUGS"
al@596 1474 _ "Cook skip: \$pkg doesn't cook or is not included in: \$ARCH" | log
pankso@427 1475 newline && exit 1
pankso@377 1476 fi
pankso@377 1477
pankso@47 1478 # Skip blocked, 3 lines also for the Cooker.
pankso@151 1479 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
al@596 1480 _ "Blocked package: \$pkg"; newline
al@596 1481 exit 0
pankso@47 1482 fi
pankso@47 1483
pascal@289 1484 try_aufs_chroot "$@"
pascal@289 1485
pankso@47 1486 # Log and source receipt.
al@596 1487 _ "Cook started for: <a href='cooker.cgi?pkg=\$pkg'>\$pkg</a>" | log
pankso@16 1488 echo "cook:$pkg" > $command
pascal@285 1489
pascal@285 1490 # Display and log info if cook process stopped.
paul@647 1491 # FIXME: gettext not working (in single quotes) here!
al@596 1492 trap '_ "\n\nCook stopped: control-C\n\n" | \
pascal@285 1493 tee -a $LOGS/$pkg.log' INT
pascal@285 1494
pankso@1 1495 # Handle --options
pankso@1 1496 case "$2" in
pankso@1 1497 --clean|-c)
al@596 1498 _n "Cleaning: \$pkg"
pankso@1 1499 cd $WOK/$pkg && rm -rf install taz source
pankso@427 1500 status && newline && exit 0 ;;
pankso@1 1501 --install|-i)
pankso@1 1502 inst='yes' ;;
pankso@49 1503 --getsrc|-gs)
al@596 1504 _ "Getting source for: \$pkg"; separator
al@596 1505 get_source
al@596 1506 _ "Tarball: \$SRC/\$TARBALL"; newline
al@596 1507 exit 0 ;;
pankso@49 1508 --block|-b)
al@596 1509 _n "Blocking: \$pkg"
pankso@49 1510 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
pankso@427 1511 status && newline && exit 0 ;;
pankso@49 1512 --unblock|-ub)
al@596 1513 _n "Unblocking: \$pkg"
pankso@49 1514 sed -i "/^${pkg}$/"d $blocked
pankso@427 1515 status && newline && exit 0 ;;
slaxemulator@501 1516 --pack)
slaxemulator@501 1517 if [ -d $WOK/$pkg/taz ]; then
slaxemulator@501 1518 rm -rf $WOK/$pkg/taz
slaxemulator@501 1519 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
slaxemulator@501 1520 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
slaxemulator@501 1521 clean_log
slaxemulator@501 1522 else
al@596 1523 _ "Need to build \$pkg." && exit 0
slaxemulator@501 1524 fi
slaxemulator@501 1525 exit 0 ;;
al@598 1526 --cdeps)
al@598 1527 [ ! -d $WOK/$pkg/taz ] && _ "Need to build \$pkg." && exit 0
al@598 1528 _ "Checking depends"; separator
al@598 1529 lddlist=/tmp/lddlist; touch $lddlist
al@598 1530 missing=/var/cache/missing.file
al@598 1531 # find all deps using ldd
al@598 1532 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
al@598 1533 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
al@598 1534 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
al@598 1535 done
al@598 1536 # remove exe/so duplicates
al@598 1537 sort -u $lddlist > $lddlist.sorted
al@598 1538 # search packages
al@598 1539 for exefile in $(cat $lddlist.sorted); do
al@598 1540 search_file $exefile
al@598 1541 echo $found >> $lddlist.pkgs
al@598 1542 echo -n "."
al@598 1543 done
al@598 1544 echo
al@598 1545 # remove packages duplicates
al@598 1546 sort -u $lddlist.pkgs > $lddlist.final
al@598 1547 sort -u $missing > $missing.final
al@598 1548 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
al@598 1549 exit 0 ;;
pankso@1 1550 esac
pankso@1 1551
paul@62 1552 # Check if wanted is built now so we have separate log files.
pankso@295 1553 for wanted in $WANTED ; do
pascal@291 1554 if grep -q "^$wanted$" $blocked; then
al@596 1555 _ "WANTED package is blocked: \$wanted" | tee $LOGS/$pkg.log
pankso@427 1556 newline && rm -f $command && exit 1
pankso@217 1557 fi
pascal@291 1558 if grep -q "^$wanted$" $broken; then
al@596 1559 _ "WANTED package is broken: \$wanted" | tee $LOGS/$pkg.log
pankso@427 1560 newline && rm -f $command && exit 1
pankso@218 1561 fi
pascal@291 1562 if [ ! -d "$WOK/$wanted/install" ]; then
pascal@291 1563 cook "$wanted" || exit 1
pankso@137 1564 fi
pascal@291 1565 done
pankso@1 1566
pankso@1 1567 # Cook and pack or exit on error and log everything.
pascal@576 1568 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
pankso@15 1569 remove_deps | tee -a $LOGS/$pkg.log
pankso@1 1570 cookit_quality
pascal@576 1571 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
pankso@1 1572 clean_log
pankso@33 1573
pankso@33 1574 # Exit if any error in packing.
al@596 1575 lerror=$(_n "ERROR")
pascal@615 1576 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
pascal@615 1577 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors)"; then
pankso@33 1578 debug_info | tee -a $LOGS/$pkg.log
pankso@33 1579 rm -f $command && exit 1
pankso@33 1580 fi
pankso@358 1581
pankso@310 1582 # Create an XML feed
pankso@310 1583 gen_rss
pankso@358 1584
pankso@1 1585 # Time and summary
pankso@1 1586 time=$(($(date +%s) - $time))
pankso@1 1587 summary | tee -a $LOGS/$pkg.log
pankso@427 1588 newline
pankso@1 1589
pankso@428 1590 # We may want to install/update.
pankso@428 1591 install_package
pankso@358 1592
al@596 1593 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
pankso@17 1594 # You want automation: use the Cooker Build Bot.
pankso@18 1595 rm -f $command ;;
pankso@1 1596 esac
pankso@1 1597
pankso@1 1598 exit 0