CRUX-ARM : Home

Home :: Documentation :: Download :: Development :: Community :: Ports :: Packages :: Bugs :: Links :: About :: Donors
Be less strict about the package name suffix.
[pkgutils-cross.git] / pkgmk.in
index df50de84ecd29ef87241cac7546745ce503f8acc..b8e3e4e1957086b9b255e31973dfdb64f8a5206d 100755 (executable)
--- a/pkgmk.in
+++ b/pkgmk.in
@@ -34,13 +34,11 @@ error() {
 }
 
 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
-
-       echo $FILE
 }
 
 get_basename() {
@@ -77,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'."
 
@@ -101,7 +106,7 @@ download_file() {
        BASENAME=`get_basename $1`
        for REPO in ${PKGMK_SOURCE_MIRRORS[@]}; do
                REPO="`echo $REPO | sed 's|/$||'`"
-               wget $RESUME_CMD $DOWNLOAD_OPTS $REPO/$BASENAME
+               wget $RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $REPO/$BASENAME
                error=$?
                if [ $error == 0 ]; then
                        break
@@ -110,7 +115,7 @@ download_file() {
 
        if [ $error != 0 ]; then
                while true; do
-                       wget $RESUME_CMD $DOWNLOAD_OPTS $1
+                       wget $RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $1
                        error=$?
                        if [ $error != 0 ] && [ "$RESUME_CMD" ]; then
                                info "Partial download failed, restarting"
@@ -157,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|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.zip|*.rpm)
+                               COMMAND="bsdtar -p -o -C $SRC -xf $LOCAL_FILENAME" ;;
                        *)
                                COMMAND="cp $LOCAL_FILENAME $SRC" ;;
                esac
@@ -331,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."
@@ -380,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
@@ -455,6 +466,7 @@ update_footprint() {
                exit 1
        fi
        
+       check_file "$PKGMK_FOOTPRINT"
        make_footprint > $PKGMK_FOOTPRINT
        touch $TARGET
        
@@ -498,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"
@@ -527,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)
@@ -606,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
@@ -616,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."
@@ -662,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"