cookutils annotate cook @ rev 474

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