X-Git-Url: http://gitweb/?a=blobdiff_plain;f=pkgmk.in;h=bf7d7532e22e06a0745d52c1af95c4bb3af74199;hb=698c42e2a069018285395a53e21f7c0dabfec88c;hp=62a74188f61c2bd1340128f106b277bec9e7c6d7;hpb=9ac667e68d3e36eb99272eac57219002ee2318e6;p=pkgutils-cross.git diff --git a/pkgmk.in b/pkgmk.in index 62a7418..bf7d753 100755 --- a/pkgmk.in +++ b/pkgmk.in @@ -3,6 +3,7 @@ # pkgutils # # Copyright (c) 2000-2005 Per Liden +# Copyright (c) 2006-2007 by CRUX team (http://crux.nu) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,20 +26,23 @@ info() { } warning() { - info "WARNING: $1" + info "WARNING: $1" >&2 } error() { - info "ERROR: $1" + info "ERROR: $1" >&2 } get_filename() { - local FILE="`echo $1 | sed 's|^.*://.*/||g'`" - - if [ "$FILE" != "$1" ]; then - FILE="$PKGMK_SOURCE_DIR/$FILE" + if [[ $1 =~ ^(http|https|ftp|file)://.*/(.+) ]]; then + echo "$PKGMK_SOURCE_DIR/${BASH_REMATCH[2]}" + else + echo $1 fi +} +get_basename() { + local FILE="`echo $1 | sed 's|^.*://.*/||g'`" echo $FILE } @@ -71,6 +75,13 @@ check_directory() { fi } +check_file() { + if [ -e $1 ] && [ ! -w $1 ]; then + error "File '$1' is not writable." + exit 1 + fi +} + download_file() { info "Downloading '$1'." @@ -81,25 +92,40 @@ download_file() { LOCAL_FILENAME=`get_filename $1` LOCAL_FILENAME_PARTIAL="$LOCAL_FILENAME.partial" - DOWNLOAD_CMD="--passive-ftp --no-directories --tries=3 --waitretry=3 \ - --directory-prefix=$PKGMK_SOURCE_DIR --output-document=$LOCAL_FILENAME_PARTIAL $1" + DOWNLOAD_OPTS="--passive-ftp --no-directories --tries=3 --waitretry=3 \ + --directory-prefix=$PKGMK_SOURCE_DIR \ + --output-document=$LOCAL_FILENAME_PARTIAL --no-check-certificate" if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then info "Partial download found, trying to resume" RESUME_CMD="-c" fi - while true; do - wget $RESUME_CMD $DOWNLOAD_CMD + error=1 + + BASENAME=`get_basename $1` + for REPO in ${PKGMK_SOURCE_MIRRORS[@]}; do + REPO="`echo $REPO | sed 's|/$||'`" + wget $RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $REPO/$BASENAME error=$? - if [ $error != 0 ] && [ "$RESUME_CMD" ]; then - info "Partial download failed, restarting" - rm -f "$LOCAL_FILENAME_PARTIAL" - RESUME_CMD="" - else + if [ $error == 0 ]; then break fi done + + if [ $error != 0 ]; then + while true; do + wget $RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $1 + error=$? + if [ $error != 0 ] && [ "$RESUME_CMD" ]; then + info "Partial download failed, restarting" + rm -f "$LOCAL_FILENAME_PARTIAL" + RESUME_CMD="" + else + break + fi + done + fi if [ $error != 0 ]; then error "Downloading '$1' failed." @@ -136,12 +162,8 @@ unpack_source() { for FILE in ${source[@]}; do LOCAL_FILENAME=`get_filename $FILE` case $LOCAL_FILENAME in - *.tar.gz|*.tar.Z|*.tgz) - COMMAND="tar -C $SRC --use-compress-program=gzip -xf $LOCAL_FILENAME" ;; - *.tar.bz2) - COMMAND="tar -C $SRC --use-compress-program=bzip2 -xf $LOCAL_FILENAME" ;; - *.zip) - COMMAND="unzip -qq -o -d $SRC $LOCAL_FILENAME" ;; + *.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tar.xz|*.zip) + COMMAND="bsdtar -p -o -C $SRC -xf $LOCAL_FILENAME" ;; *) COMMAND="cp $LOCAL_FILENAME $SRC" ;; esac @@ -194,7 +216,7 @@ check_md5sum() { sed 's/^-/MISSING /g' > $FILE.md5sum.diff if [ -s $FILE.md5sum.diff ]; then error "Md5sum mismatch found:" - cat $FILE.md5sum.diff + cat $FILE.md5sum.diff >&2 if [ "$PKGMK_KEEP_WORK" = "no" ]; then rm -rf $PKGMK_WORK_DIR @@ -242,13 +264,16 @@ strip_files() { fi find . -type f -printf "%P\n" | $FILTER | while read FILE; do - if file -b "$FILE" | grep '^.*ELF.*executable.*not stripped$' &> /dev/null; then + case $(file -b "$FILE") in + *ELF*executable*not\ stripped) strip --strip-all "$FILE" - elif file -b "$FILE" | grep '^.*ELF.*shared object.*not stripped$' &> /dev/null; then + ;; + *ELF*shared\ object*not\ stripped) strip --strip-unneeded "$FILE" - elif file -b "$FILE" | grep '^current ar archive$' &> /dev/null; then + ;; + current\ ar\ archive) strip --strip-debug "$FILE" - fi + esac done } @@ -294,7 +319,7 @@ check_footprint() { sed 's/^-/MISSING /g' > $FILE.footprint.diff if [ -s $FILE.footprint.diff ]; then error "Footprint mismatch found:" - cat $FILE.footprint.diff + cat $FILE.footprint.diff >&2 BUILD_SUCCESSFUL="no" fi else @@ -307,20 +332,30 @@ check_footprint() { fi } -build_package() { - local BUILD_SUCCESSFUL="no" - +make_work_dir() { export PKG="$PKGMK_WORK_DIR/pkg" export SRC="$PKGMK_WORK_DIR/src" umask 022 cd $PKGMK_ROOT - rm -rf $PKGMK_WORK_DIR + remove_work_dir mkdir -p $SRC $PKG - + if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then check_md5sum fi +} + +remove_work_dir() { + rm -rf $PKGMK_WORK_DIR +} + + +build_package() { + local BUILD_SUCCESSFUL="no" + + check_file "$TARGET" + make_work_dir if [ "$UID" != "0" ]; then warning "Packages should be built as root." @@ -356,7 +391,7 @@ build_package() { fi if [ "$PKGMK_KEEP_WORK" = "no" ]; then - rm -rf $PKGMK_WORK_DIR + remove_work_dir fi if [ "$BUILD_SUCCESSFUL" = "yes" ]; then @@ -431,6 +466,7 @@ update_footprint() { exit 1 fi + check_file "$PKGMK_FOOTPRINT" make_footprint > $PKGMK_FOOTPRINT touch $TARGET @@ -474,6 +510,7 @@ print_help() { echo " -r, --recursive search for and build packages recursively" echo " -d, --download download missing source file(s)" echo " -do, --download-only do not build, only download missing source file(s)" + echo " -eo, --extract-only do not build, only extract source file(s)" echo " -utd, --up-to-date do not build, only check if package is up to date" echo " -uf, --update-footprint update footprint using result from last build" echo " -if, --ignore-footprint build package without checking footprint" @@ -503,6 +540,8 @@ parse_options() { -do|--download-only) PKGMK_DOWNLOAD="yes" PKGMK_DOWNLOAD_ONLY="yes" ;; + -eo|--extract-only) + PKGMK_EXTRACT_ONLY="yes" ;; -utd|--up-to-date) PKGMK_UP_TO_DATE="yes" ;; -uf|--update-footprint) @@ -582,6 +621,7 @@ main() { if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then download_source + check_file "$PKGMK_MD5SUM" make_md5sum > $PKGMK_MD5SUM info "Md5sum updated." exit 0 @@ -592,6 +632,14 @@ main() { exit 0 fi + if [ "$PKGMK_EXTRACT_ONLY" = "yes" ]; then + download_source + make_work_dir + info "Extracting sources of package '$name-$version'." + unpack_source + exit 0 + fi + if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then if [ "`build_needed`" = "yes" ]; then info "Package '$TARGET' is not up to date." @@ -629,6 +677,7 @@ PKGMK_FOOTPRINT=".footprint" PKGMK_MD5SUM=".md5sum" PKGMK_NOSTRIP=".nostrip" +PKGMK_SOURCE_MIRRORS=() PKGMK_SOURCE_DIR="$PWD" PKGMK_PACKAGE_DIR="$PWD" PKGMK_WORK_DIR="$PWD/work" @@ -637,6 +686,7 @@ PKGMK_INSTALL="no" PKGMK_RECURSIVE="no" PKGMK_DOWNLOAD="no" PKGMK_DOWNLOAD_ONLY="no" +PKGMK_EXTRACT_ONLY="no" PKGMK_UP_TO_DATE="no" PKGMK_UPDATE_FOOTPRINT="no" PKGMK_IGNORE_FOOTPRINT="no"