| 1 | #!/bin/bash |
| 2 | # |
| 3 | # pkgutils |
| 4 | # |
| 5 | # Copyright (c) 2000-2005 Per Liden |
| 6 | # Copyright (c) 2006-2007 by CRUX team (http://crux.nu) |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | # This program is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with this program; if not, write to the Free Software |
| 20 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 21 | # USA. |
| 22 | # |
| 23 | |
| 24 | info() { |
| 25 | echo "=======> $1" |
| 26 | } |
| 27 | |
| 28 | warning() { |
| 29 | info "WARNING: $1" >&2 |
| 30 | } |
| 31 | |
| 32 | error() { |
| 33 | info "ERROR: $1" >&2 |
| 34 | } |
| 35 | |
| 36 | get_filename() { |
| 37 | local FILE="`echo $1 | sed 's|^.*://.*/||g'`" |
| 38 | |
| 39 | if [ "$FILE" != "$1" ]; then |
| 40 | FILE="$PKGMK_SOURCE_DIR/$FILE" |
| 41 | fi |
| 42 | |
| 43 | echo $FILE |
| 44 | } |
| 45 | |
| 46 | get_basename() { |
| 47 | local FILE="`echo $1 | sed 's|^.*://.*/||g'`" |
| 48 | echo $FILE |
| 49 | } |
| 50 | |
| 51 | check_pkgfile() { |
| 52 | if [ ! "$name" ]; then |
| 53 | error "Variable 'name' not specified in $PKGMK_PKGFILE." |
| 54 | exit 1 |
| 55 | elif [ ! "$version" ]; then |
| 56 | error "Variable 'version' not specified in $PKGMK_PKGFILE." |
| 57 | exit 1 |
| 58 | elif [ ! "$release" ]; then |
| 59 | error "Variable 'release' not specified in $PKGMK_PKGFILE." |
| 60 | exit 1 |
| 61 | elif [ "`type -t build`" != "function" ]; then |
| 62 | error "Function 'build' not specified in $PKGMK_PKGFILE." |
| 63 | exit 1 |
| 64 | fi |
| 65 | } |
| 66 | |
| 67 | check_directory() { |
| 68 | if [ ! -d $1 ]; then |
| 69 | error "Directory '$1' does not exist." |
| 70 | exit 1 |
| 71 | elif [ ! -w $1 ]; then |
| 72 | error "Directory '$1' not writable." |
| 73 | exit 1 |
| 74 | elif [ ! -x $1 ] || [ ! -r $1 ]; then |
| 75 | error "Directory '$1' not readable." |
| 76 | exit 1 |
| 77 | fi |
| 78 | } |
| 79 | |
| 80 | download_file() { |
| 81 | info "Downloading '$1'." |
| 82 | |
| 83 | if [ ! "`type -p wget`" ]; then |
| 84 | error "Command 'wget' not found." |
| 85 | exit 1 |
| 86 | fi |
| 87 | |
| 88 | LOCAL_FILENAME=`get_filename $1` |
| 89 | LOCAL_FILENAME_PARTIAL="$LOCAL_FILENAME.partial" |
| 90 | DOWNLOAD_OPTS="--passive-ftp --no-directories --tries=3 --waitretry=3 \ |
| 91 | --directory-prefix=$PKGMK_SOURCE_DIR \ |
| 92 | --output-document=$LOCAL_FILENAME_PARTIAL --no-check-certificate" |
| 93 | |
| 94 | if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then |
| 95 | info "Partial download found, trying to resume" |
| 96 | RESUME_CMD="-c" |
| 97 | fi |
| 98 | |
| 99 | error=1 |
| 100 | |
| 101 | BASENAME=`get_basename $1` |
| 102 | for REPO in ${PKGMK_SOURCE_MIRRORS[@]}; do |
| 103 | REPO="`echo $REPO | sed 's|/$||'`" |
| 104 | wget $RESUME_CMD $DOWNLOAD_OPTS $REPO/$BASENAME |
| 105 | error=$? |
| 106 | if [ $error == 0 ]; then |
| 107 | break |
| 108 | fi |
| 109 | done |
| 110 | |
| 111 | if [ $error != 0 ]; then |
| 112 | while true; do |
| 113 | wget $RESUME_CMD $DOWNLOAD_OPTS $1 |
| 114 | error=$? |
| 115 | if [ $error != 0 ] && [ "$RESUME_CMD" ]; then |
| 116 | info "Partial download failed, restarting" |
| 117 | rm -f "$LOCAL_FILENAME_PARTIAL" |
| 118 | RESUME_CMD="" |
| 119 | else |
| 120 | break |
| 121 | fi |
| 122 | done |
| 123 | fi |
| 124 | |
| 125 | if [ $error != 0 ]; then |
| 126 | error "Downloading '$1' failed." |
| 127 | exit 1 |
| 128 | fi |
| 129 | |
| 130 | mv -f "$LOCAL_FILENAME_PARTIAL" "$LOCAL_FILENAME" |
| 131 | } |
| 132 | |
| 133 | download_source() { |
| 134 | local FILE LOCAL_FILENAME |
| 135 | |
| 136 | for FILE in ${source[@]}; do |
| 137 | LOCAL_FILENAME=`get_filename $FILE` |
| 138 | if [ ! -e $LOCAL_FILENAME ]; then |
| 139 | if [ "$LOCAL_FILENAME" = "$FILE" ]; then |
| 140 | error "Source file '$LOCAL_FILENAME' not found (can not be downloaded, URL not specified)." |
| 141 | exit 1 |
| 142 | else |
| 143 | if [ "$PKGMK_DOWNLOAD" = "yes" ]; then |
| 144 | download_file $FILE |
| 145 | else |
| 146 | error "Source file '$LOCAL_FILENAME' not found (use option -d to download)." |
| 147 | exit 1 |
| 148 | fi |
| 149 | fi |
| 150 | fi |
| 151 | done |
| 152 | } |
| 153 | |
| 154 | unpack_source() { |
| 155 | local FILE LOCAL_FILENAME COMMAND |
| 156 | |
| 157 | for FILE in ${source[@]}; do |
| 158 | LOCAL_FILENAME=`get_filename $FILE` |
| 159 | case $LOCAL_FILENAME in |
| 160 | *.tar.gz|*.tar.Z|*.tgz) |
| 161 | COMMAND="tar -C $SRC --use-compress-program=gzip -xf $LOCAL_FILENAME" ;; |
| 162 | *.tar.bz2) |
| 163 | COMMAND="tar -C $SRC --use-compress-program=bzip2 -xf $LOCAL_FILENAME" ;; |
| 164 | *.zip) |
| 165 | COMMAND="unzip -qq -o -d $SRC $LOCAL_FILENAME" ;; |
| 166 | *) |
| 167 | COMMAND="cp $LOCAL_FILENAME $SRC" ;; |
| 168 | esac |
| 169 | |
| 170 | echo "$COMMAND" |
| 171 | |
| 172 | $COMMAND |
| 173 | |
| 174 | if [ $? != 0 ]; then |
| 175 | if [ "$PKGMK_KEEP_WORK" = "no" ]; then |
| 176 | rm -rf $PKGMK_WORK_DIR |
| 177 | fi |
| 178 | error "Building '$TARGET' failed." |
| 179 | exit 1 |
| 180 | fi |
| 181 | done |
| 182 | } |
| 183 | |
| 184 | make_md5sum() { |
| 185 | local FILE LOCAL_FILENAMES |
| 186 | |
| 187 | if [ "$source" ]; then |
| 188 | for FILE in ${source[@]}; do |
| 189 | LOCAL_FILENAMES="$LOCAL_FILENAMES `get_filename $FILE`" |
| 190 | done |
| 191 | |
| 192 | md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2 |
| 193 | fi |
| 194 | } |
| 195 | |
| 196 | make_footprint() { |
| 197 | pkginfo --footprint $TARGET | \ |
| 198 | sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \ |
| 199 | sort -k 3 |
| 200 | } |
| 201 | |
| 202 | check_md5sum() { |
| 203 | local FILE="$PKGMK_WORK_DIR/.tmp" |
| 204 | |
| 205 | cd $PKGMK_ROOT |
| 206 | |
| 207 | if [ -f $PKGMK_MD5SUM ]; then |
| 208 | make_md5sum > $FILE.md5sum |
| 209 | sort -k 2 $PKGMK_MD5SUM > $FILE.md5sum.orig |
| 210 | diff -w -t -U 0 $FILE.md5sum.orig $FILE.md5sum | \ |
| 211 | sed '/^@@/d' | \ |
| 212 | sed '/^+++/d' | \ |
| 213 | sed '/^---/d' | \ |
| 214 | sed 's/^+/NEW /g' | \ |
| 215 | sed 's/^-/MISSING /g' > $FILE.md5sum.diff |
| 216 | if [ -s $FILE.md5sum.diff ]; then |
| 217 | error "Md5sum mismatch found:" |
| 218 | cat $FILE.md5sum.diff >&2 |
| 219 | |
| 220 | if [ "$PKGMK_KEEP_WORK" = "no" ]; then |
| 221 | rm -rf $PKGMK_WORK_DIR |
| 222 | fi |
| 223 | |
| 224 | if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then |
| 225 | error "Md5sum not ok." |
| 226 | exit 1 |
| 227 | fi |
| 228 | |
| 229 | error "Building '$TARGET' failed." |
| 230 | exit 1 |
| 231 | fi |
| 232 | else |
| 233 | if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then |
| 234 | if [ "$PKGMK_KEEP_WORK" = "no" ]; then |
| 235 | rm -rf $PKGMK_WORK_DIR |
| 236 | fi |
| 237 | info "Md5sum not found." |
| 238 | exit 1 |
| 239 | fi |
| 240 | |
| 241 | warning "Md5sum not found, creating new." |
| 242 | make_md5sum > $PKGMK_MD5SUM |
| 243 | fi |
| 244 | |
| 245 | if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then |
| 246 | if [ "$PKGMK_KEEP_WORK" = "no" ]; then |
| 247 | rm -rf $PKGMK_WORK_DIR |
| 248 | fi |
| 249 | info "Md5sum ok." |
| 250 | exit 0 |
| 251 | fi |
| 252 | } |
| 253 | |
| 254 | strip_files() { |
| 255 | local FILE FILTER |
| 256 | |
| 257 | cd $PKG |
| 258 | |
| 259 | if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then |
| 260 | FILTER="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP" |
| 261 | else |
| 262 | FILTER="cat" |
| 263 | fi |
| 264 | |
| 265 | find . -type f -printf "%P\n" | $FILTER | while read FILE; do |
| 266 | case $(file -b "$FILE") in |
| 267 | *ELF*executable*not\ stripped) |
| 268 | strip --strip-all "$FILE" |
| 269 | ;; |
| 270 | *ELF*shared\ object*not\ stripped) |
| 271 | strip --strip-unneeded "$FILE" |
| 272 | ;; |
| 273 | current\ ar\ archive) |
| 274 | strip --strip-debug "$FILE" |
| 275 | esac |
| 276 | done |
| 277 | } |
| 278 | |
| 279 | compress_manpages() { |
| 280 | local FILE DIR TARGET |
| 281 | |
| 282 | cd $PKG |
| 283 | |
| 284 | find . -type f -path "*/man/man*/*" | while read FILE; do |
| 285 | if [ "$FILE" = "${FILE%%.gz}" ]; then |
| 286 | gzip -9 "$FILE" |
| 287 | fi |
| 288 | done |
| 289 | |
| 290 | find . -type l -path "*/man/man*/*" | while read FILE; do |
| 291 | TARGET=`readlink -n "$FILE"` |
| 292 | TARGET="${TARGET##*/}" |
| 293 | TARGET="${TARGET%%.gz}.gz" |
| 294 | rm -f "$FILE" |
| 295 | FILE="${FILE%%.gz}.gz" |
| 296 | DIR=`dirname "$FILE"` |
| 297 | |
| 298 | if [ -e "$DIR/$TARGET" ]; then |
| 299 | ln -sf "$TARGET" "$FILE" |
| 300 | fi |
| 301 | done |
| 302 | } |
| 303 | |
| 304 | check_footprint() { |
| 305 | local FILE="$PKGMK_WORK_DIR/.tmp" |
| 306 | |
| 307 | cd $PKGMK_ROOT |
| 308 | |
| 309 | if [ -f $TARGET ]; then |
| 310 | make_footprint > $FILE.footprint |
| 311 | if [ -f $PKGMK_FOOTPRINT ]; then |
| 312 | sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig |
| 313 | diff -w -t -U 0 $FILE.footprint.orig $FILE.footprint | \ |
| 314 | sed '/^@@/d' | \ |
| 315 | sed '/^+++/d' | \ |
| 316 | sed '/^---/d' | \ |
| 317 | sed 's/^+/NEW /g' | \ |
| 318 | sed 's/^-/MISSING /g' > $FILE.footprint.diff |
| 319 | if [ -s $FILE.footprint.diff ]; then |
| 320 | error "Footprint mismatch found:" |
| 321 | cat $FILE.footprint.diff >&2 |
| 322 | BUILD_SUCCESSFUL="no" |
| 323 | fi |
| 324 | else |
| 325 | warning "Footprint not found, creating new." |
| 326 | mv $FILE.footprint $PKGMK_FOOTPRINT |
| 327 | fi |
| 328 | else |
| 329 | error "Package '$TARGET' was not found." |
| 330 | BUILD_SUCCESSFUL="no" |
| 331 | fi |
| 332 | } |
| 333 | |
| 334 | build_package() { |
| 335 | local BUILD_SUCCESSFUL="no" |
| 336 | |
| 337 | export PKG="$PKGMK_WORK_DIR/pkg" |
| 338 | export SRC="$PKGMK_WORK_DIR/src" |
| 339 | umask 022 |
| 340 | |
| 341 | cd $PKGMK_ROOT |
| 342 | rm -rf $PKGMK_WORK_DIR |
| 343 | mkdir -p $SRC $PKG |
| 344 | |
| 345 | if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then |
| 346 | check_md5sum |
| 347 | fi |
| 348 | |
| 349 | if [ "$UID" != "0" ]; then |
| 350 | warning "Packages should be built as root." |
| 351 | fi |
| 352 | |
| 353 | info "Building '$TARGET'." |
| 354 | |
| 355 | unpack_source |
| 356 | |
| 357 | cd $SRC |
| 358 | (set -e -x ; build) |
| 359 | |
| 360 | if [ $? = 0 ]; then |
| 361 | if [ "$PKGMK_NO_STRIP" = "no" ]; then |
| 362 | strip_files |
| 363 | fi |
| 364 | |
| 365 | compress_manpages |
| 366 | |
| 367 | cd $PKG |
| 368 | info "Build result:" |
| 369 | tar czvvf $TARGET * |
| 370 | |
| 371 | if [ $? = 0 ]; then |
| 372 | BUILD_SUCCESSFUL="yes" |
| 373 | |
| 374 | if [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ]; then |
| 375 | warning "Footprint ignored." |
| 376 | else |
| 377 | check_footprint |
| 378 | fi |
| 379 | fi |
| 380 | fi |
| 381 | |
| 382 | if [ "$PKGMK_KEEP_WORK" = "no" ]; then |
| 383 | rm -rf $PKGMK_WORK_DIR |
| 384 | fi |
| 385 | |
| 386 | if [ "$BUILD_SUCCESSFUL" = "yes" ]; then |
| 387 | info "Building '$TARGET' succeeded." |
| 388 | else |
| 389 | if [ -f $TARGET ]; then |
| 390 | touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev/null |
| 391 | fi |
| 392 | error "Building '$TARGET' failed." |
| 393 | exit 1 |
| 394 | fi |
| 395 | } |
| 396 | |
| 397 | install_package() { |
| 398 | local COMMAND |
| 399 | |
| 400 | info "Installing '$TARGET'." |
| 401 | |
| 402 | if [ "$PKGMK_INSTALL" = "install" ]; then |
| 403 | COMMAND="pkgadd $TARGET" |
| 404 | else |
| 405 | COMMAND="pkgadd -u $TARGET" |
| 406 | fi |
| 407 | |
| 408 | cd $PKGMK_ROOT |
| 409 | echo "$COMMAND" |
| 410 | $COMMAND |
| 411 | |
| 412 | if [ $? = 0 ]; then |
| 413 | info "Installing '$TARGET' succeeded." |
| 414 | else |
| 415 | error "Installing '$TARGET' failed." |
| 416 | exit 1 |
| 417 | fi |
| 418 | } |
| 419 | |
| 420 | recursive() { |
| 421 | local ARGS FILE DIR |
| 422 | |
| 423 | ARGS=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"` |
| 424 | |
| 425 | for FILE in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do |
| 426 | DIR="`dirname $FILE`/" |
| 427 | if [ -d $DIR ]; then |
| 428 | info "Entering directory '$DIR'." |
| 429 | (cd $DIR && $PKGMK_COMMAND $ARGS) |
| 430 | info "Leaving directory '$DIR'." |
| 431 | fi |
| 432 | done |
| 433 | } |
| 434 | |
| 435 | clean() { |
| 436 | local FILE LOCAL_FILENAME |
| 437 | |
| 438 | if [ -f $TARGET ]; then |
| 439 | info "Removing $TARGET" |
| 440 | rm -f $TARGET |
| 441 | fi |
| 442 | |
| 443 | for FILE in ${source[@]}; do |
| 444 | LOCAL_FILENAME=`get_filename $FILE` |
| 445 | if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then |
| 446 | info "Removing $LOCAL_FILENAME" |
| 447 | rm -f $LOCAL_FILENAME |
| 448 | fi |
| 449 | done |
| 450 | } |
| 451 | |
| 452 | update_footprint() { |
| 453 | if [ ! -f $TARGET ]; then |
| 454 | error "Unable to update footprint. File '$TARGET' not found." |
| 455 | exit 1 |
| 456 | fi |
| 457 | |
| 458 | make_footprint > $PKGMK_FOOTPRINT |
| 459 | touch $TARGET |
| 460 | |
| 461 | info "Footprint updated." |
| 462 | } |
| 463 | |
| 464 | build_needed() { |
| 465 | local FILE RESULT |
| 466 | |
| 467 | RESULT="yes" |
| 468 | if [ -f $TARGET ]; then |
| 469 | RESULT="no" |
| 470 | for FILE in $PKGMK_PKGFILE ${source[@]}; do |
| 471 | FILE=`get_filename $FILE` |
| 472 | if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then |
| 473 | RESULT="yes" |
| 474 | break |
| 475 | fi |
| 476 | done |
| 477 | fi |
| 478 | |
| 479 | echo $RESULT |
| 480 | } |
| 481 | |
| 482 | interrupted() { |
| 483 | echo "" |
| 484 | error "Interrupted." |
| 485 | |
| 486 | if [ "$PKGMK_KEEP_WORK" = "no" ]; then |
| 487 | rm -rf $PKGMK_WORK_DIR |
| 488 | fi |
| 489 | |
| 490 | exit 1 |
| 491 | } |
| 492 | |
| 493 | print_help() { |
| 494 | echo "usage: `basename $PKGMK_COMMAND` [options]" |
| 495 | echo "options:" |
| 496 | echo " -i, --install build and install package" |
| 497 | echo " -u, --upgrade build and install package (as upgrade)" |
| 498 | echo " -r, --recursive search for and build packages recursively" |
| 499 | echo " -d, --download download missing source file(s)" |
| 500 | echo " -do, --download-only do not build, only download missing source file(s)" |
| 501 | echo " -utd, --up-to-date do not build, only check if package is up to date" |
| 502 | echo " -uf, --update-footprint update footprint using result from last build" |
| 503 | echo " -if, --ignore-footprint build package without checking footprint" |
| 504 | echo " -um, --update-md5sum update md5sum" |
| 505 | echo " -im, --ignore-md5sum build package without checking md5sum" |
| 506 | echo " -cm, --check-md5sum do not build, only check md5sum" |
| 507 | echo " -ns, --no-strip do not strip executable binaries or libraries" |
| 508 | echo " -f, --force build package even if it appears to be up to date" |
| 509 | echo " -c, --clean remove package and downloaded files" |
| 510 | echo " -kw, --keep-work keep temporary working directory" |
| 511 | echo " -cf, --config-file <file> use alternative configuration file" |
| 512 | echo " -v, --version print version and exit " |
| 513 | echo " -h, --help print help and exit" |
| 514 | } |
| 515 | |
| 516 | parse_options() { |
| 517 | while [ "$1" ]; do |
| 518 | case $1 in |
| 519 | -i|--install) |
| 520 | PKGMK_INSTALL="install" ;; |
| 521 | -u|--upgrade) |
| 522 | PKGMK_INSTALL="upgrade" ;; |
| 523 | -r|--recursive) |
| 524 | PKGMK_RECURSIVE="yes" ;; |
| 525 | -d|--download) |
| 526 | PKGMK_DOWNLOAD="yes" ;; |
| 527 | -do|--download-only) |
| 528 | PKGMK_DOWNLOAD="yes" |
| 529 | PKGMK_DOWNLOAD_ONLY="yes" ;; |
| 530 | -utd|--up-to-date) |
| 531 | PKGMK_UP_TO_DATE="yes" ;; |
| 532 | -uf|--update-footprint) |
| 533 | PKGMK_UPDATE_FOOTPRINT="yes" ;; |
| 534 | -if|--ignore-footprint) |
| 535 | PKGMK_IGNORE_FOOTPRINT="yes" ;; |
| 536 | -um|--update-md5sum) |
| 537 | PKGMK_UPDATE_MD5SUM="yes" ;; |
| 538 | -im|--ignore-md5sum) |
| 539 | PKGMK_IGNORE_MD5SUM="yes" ;; |
| 540 | -cm|--check-md5sum) |
| 541 | PKGMK_CHECK_MD5SUM="yes" ;; |
| 542 | -ns|--no-strip) |
| 543 | PKGMK_NO_STRIP="yes" ;; |
| 544 | -f|--force) |
| 545 | PKGMK_FORCE="yes" ;; |
| 546 | -c|--clean) |
| 547 | PKGMK_CLEAN="yes" ;; |
| 548 | -kw|--keep-work) |
| 549 | PKGMK_KEEP_WORK="yes" ;; |
| 550 | -cf|--config-file) |
| 551 | if [ ! "$2" ]; then |
| 552 | echo "`basename $PKGMK_COMMAND`: option $1 requires an argument" |
| 553 | exit 1 |
| 554 | fi |
| 555 | PKGMK_CONFFILE="$2" |
| 556 | shift ;; |
| 557 | -v|--version) |
| 558 | echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION" |
| 559 | exit 0 ;; |
| 560 | -h|--help) |
| 561 | print_help |
| 562 | exit 0 ;; |
| 563 | *) |
| 564 | echo "`basename $PKGMK_COMMAND`: invalid option $1" |
| 565 | exit 1 ;; |
| 566 | esac |
| 567 | shift |
| 568 | done |
| 569 | } |
| 570 | |
| 571 | main() { |
| 572 | local FILE TARGET |
| 573 | |
| 574 | parse_options "$@" |
| 575 | |
| 576 | if [ "$PKGMK_RECURSIVE" = "yes" ]; then |
| 577 | recursive "$@" |
| 578 | exit 0 |
| 579 | fi |
| 580 | |
| 581 | for FILE in $PKGMK_PKGFILE $PKGMK_CONFFILE; do |
| 582 | if [ ! -f $FILE ]; then |
| 583 | error "File '$FILE' not found." |
| 584 | exit 1 |
| 585 | fi |
| 586 | . $FILE |
| 587 | done |
| 588 | |
| 589 | check_directory "$PKGMK_SOURCE_DIR" |
| 590 | check_directory "$PKGMK_PACKAGE_DIR" |
| 591 | check_directory "`dirname $PKGMK_WORK_DIR`" |
| 592 | |
| 593 | check_pkgfile |
| 594 | |
| 595 | TARGET="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.gz" |
| 596 | |
| 597 | if [ "$PKGMK_CLEAN" = "yes" ]; then |
| 598 | clean |
| 599 | exit 0 |
| 600 | fi |
| 601 | |
| 602 | if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then |
| 603 | update_footprint |
| 604 | exit 0 |
| 605 | fi |
| 606 | |
| 607 | if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then |
| 608 | download_source |
| 609 | make_md5sum > $PKGMK_MD5SUM |
| 610 | info "Md5sum updated." |
| 611 | exit 0 |
| 612 | fi |
| 613 | |
| 614 | if [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ]; then |
| 615 | download_source |
| 616 | exit 0 |
| 617 | fi |
| 618 | |
| 619 | if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then |
| 620 | if [ "`build_needed`" = "yes" ]; then |
| 621 | info "Package '$TARGET' is not up to date." |
| 622 | else |
| 623 | info "Package '$TARGET' is up to date." |
| 624 | fi |
| 625 | exit 0 |
| 626 | fi |
| 627 | |
| 628 | if [ "`build_needed`" = "no" ] && [ "$PKGMK_FORCE" = "no" ] && [ "$PKGMK_CHECK_MD5SUM" = "no" ]; then |
| 629 | info "Package '$TARGET' is up to date." |
| 630 | else |
| 631 | download_source |
| 632 | build_package |
| 633 | fi |
| 634 | |
| 635 | if [ "$PKGMK_INSTALL" != "no" ]; then |
| 636 | install_package |
| 637 | fi |
| 638 | |
| 639 | exit 0 |
| 640 | } |
| 641 | |
| 642 | trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM |
| 643 | |
| 644 | export LC_ALL=POSIX |
| 645 | |
| 646 | readonly PKGMK_VERSION="#VERSION#" |
| 647 | readonly PKGMK_COMMAND="$0" |
| 648 | readonly PKGMK_ROOT="$PWD" |
| 649 | |
| 650 | PKGMK_CONFFILE="/etc/pkgmk.conf" |
| 651 | PKGMK_PKGFILE="Pkgfile" |
| 652 | PKGMK_FOOTPRINT=".footprint" |
| 653 | PKGMK_MD5SUM=".md5sum" |
| 654 | PKGMK_NOSTRIP=".nostrip" |
| 655 | |
| 656 | PKGMK_SOURCE_MIRRORS=() |
| 657 | PKGMK_SOURCE_DIR="$PWD" |
| 658 | PKGMK_PACKAGE_DIR="$PWD" |
| 659 | PKGMK_WORK_DIR="$PWD/work" |
| 660 | |
| 661 | PKGMK_INSTALL="no" |
| 662 | PKGMK_RECURSIVE="no" |
| 663 | PKGMK_DOWNLOAD="no" |
| 664 | PKGMK_DOWNLOAD_ONLY="no" |
| 665 | PKGMK_UP_TO_DATE="no" |
| 666 | PKGMK_UPDATE_FOOTPRINT="no" |
| 667 | PKGMK_IGNORE_FOOTPRINT="no" |
| 668 | PKGMK_FORCE="no" |
| 669 | PKGMK_KEEP_WORK="no" |
| 670 | PKGMK_UPDATE_MD5SUM="no" |
| 671 | PKGMK_IGNORE_MD5SUM="no" |
| 672 | PKGMK_CHECK_MD5SUM="no" |
| 673 | PKGMK_NO_STRIP="no" |
| 674 | PKGMK_CLEAN="no" |
| 675 | |
| 676 | main "$@" |
| 677 | |
| 678 | # End of file |