]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
- no extra subshells
[packages/rpm-build-tools.git] / builder.sh
index 623e66c022844ba4429a0ec319046993258e1839..a1ccb42c391639a33f3ac3f6c4e1fc92934b1096 100644 (file)
@@ -106,6 +106,11 @@ PACKAGE_VERSION=""
 PACKAGE_NAME=""
 ASSUMED_NAME=""
 PROTOCOL="http"
+
+# use lftp by default when available
+USE_LFTP=
+lftp --version > /dev/null 2>&1 && USE_LFTP=yes
+
 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
 
 CVS_COMMAND=${CVS_COMMAND:-cvs}
@@ -190,6 +195,10 @@ elif [ -n "$USE_AXEL" ]; then
        GETURI="axel -a $AXEL_OPTS"
        GETURI2="$GETURI"
        OUTFILEOPT="-o"
+elif [ -n "$USE_LFTP" ]; then
+       GETURI=download_lftp
+       GETURI2=$GETURI
+       OUTFILEOPT=""
 else
        wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
        wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
@@ -203,7 +212,7 @@ fi
 
 GETLOCAL="cp -a"
 
-if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
+if rpm --version 2>&1 | grep -q '4.0.[0-2]'; then
        RPM="rpm"
        RPMBUILD="rpm"
 else
@@ -249,6 +258,21 @@ run_poldek() {
 #---------------------------------------------
 # functions
 
+download_lftp() {
+       local outfile=$1 url=$2 retval tmpfile
+       # TODO: use mktemp
+       tmpfile=$outfile.tmp
+       lftp -c "set net:max-retries $WGET_RETRIES; set http:user-agent \"$USER_AGENT\"; pget -n 10 -c \"$url\" -o \"$tmpfile\""
+
+       retval=$?
+       if [ $retval -eq 0 ]; then
+               mv -f "$tmpfile" "$outfile"
+       else
+               rm -f "$tmpfile"
+       fi
+       return $retval
+}
+
 usage() {
        if [ -n "$DEBUG" ]; then set -xv; fi
        echo "\
@@ -281,34 +305,29 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 -bp, --build-prep   - execute the %prep phase of <package>.spec,
 -bc                 - execute the %build phase of <package>.spec,
 -bi                 - execute the %install phase of <package>.spec
--bl                                    - execute the %files phase of <package>.spec
+-bl                 - execute the %files phase of <package>.spec
 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
                       them into src.rpm,
 --short-circuit     - short-circuit build
 -B, --branch        - add branch
 -c, --clean         - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
                       may be used with building process.
--m, --mr-proper     - clean all temporarily created files (in BUILD, SOURCES,
-                                         SPECS and \$RPM_BUILD_ROOT and CVS/Entries). Doesn't run
-                                         any rpm building.
--cf, --cvs-force       - use -F when tagging (useful when moving branches)
+-m, --mr-proper     - clean all temporarily created files (in BUILD, SOURCES, SPECS and \$RPM_BUILD_ROOT
+                      and CVS/Entries). Doesn't run any rpm building.
+-cf, --cvs-force    - use -F when tagging (useful when moving branches)
 -d <cvsroot>, --cvsroot <cvsroot>
                     - setup \$CVSROOT,
---define <macro> <value>
-                    - define a macro <macro> with value <value>,
---alt_kernel <kernel>
-                    - same as --define 'alt_kernel <kernel>'
+--define <macro> <value> - define a macro <macro> with value <value>,
+--alt_kernel <kernel> - same as --define 'alt_kernel <kernel>'
 --nodeps            - rpm won't check any dependences
--g, --get           - get <package>.spec and all related files from CVS repo
-                      or HTTP/FTP,
--h, --help          - this message,
+-g, --get           - get <package>.spec and all related files from CVS repo or HTTP/FTP
+-h, --help          - this message
 -jN, -j N           - set %_smp_mflags to propagate concurrent jobs
 --ftp, --http       - use ftp or http protocol to access distfiles server
 -l <logfile>, --logtofile <logfile>
                     - log all to file,
 -nc, --no-cvs       - don't download sources from CVS, if source URL is given,
--ncs, --no-cvs-specs
-                    - don't check specs in CVS
+-ncs, --no-cvs-specs - don't check specs in CVS
 -nd, --no-distfiles - don't download from distfiles
 -nm, --no-mirrors   - don't download from mirror, if source URL is given,
 -nu, --no-urls      - don't try to download from FTP/HTTP location,
@@ -336,7 +355,7 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 -sd, --source-distfiles - list sources available from distfiles (intended for offline
                       operations; does not work when Icon field is present
                       but icon file is absent),
--sc, --source-cvs - list sources available from CVS
+-sc, --source-cvs   - list sources available from CVS
 -sdp, --source-distfiles-paths - list sources available from distfiles -
                       paths relative to distfiles directory (intended for offline
                       operations; does not work when Icon field is present
@@ -353,10 +372,8 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
                     - add cvs tag <cvstag> for files,
 -Tvs, --tag-version-stable
                     - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
--Ts, --tag-stable
-                    - add cvs tag STABLE for files,
--Tv, --tag-version
-                    - add cvs tag NAME-VERSION-RELEASE for files,
+-Ts, --tag-stable   - add cvs tag STABLE for files,
+-Tv, --tag-version  - add cvs tag NAME-VERSION-RELEASE for files,
 -Tp, --tag-prefix <prefix>
                     - add <prefix> to NAME-VERSION-RELEASE tags,
 -tt, --test-tag <prefix>
@@ -367,7 +384,7 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 -u, --try-upgrade   - check version, and try to upgrade package
 -un, --try-upgrade-with-float-version
                     - as above, but allow float version
-                                       php-pear-Services_Digg/
+                      php-pear-Services_Digg/
 --upgrade-version   - upgrade to specified version in try-upgrade
 --use-greed-sources
                     - try download source from tag head if don't find it in
@@ -381,9 +398,8 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
                     - abort instead of applying patch <patchnumber>
 --show-bconds       - show available conditional builds, which can be used
                     - with --with and/or --without switches.
---show-bcond-args   - show active bconds, from ~/.bcondrc. this is used by
-                      ./repackage.sh script. in other words, the output is
-                      parseable by scripts.
+--show-bcond-args   - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
+                      In other words, the output is parseable by scripts.
 --show-avail-bconds - show available bconds
 --with/--without <feature>
                     - conditional build package depending on %_with_<feature>/
@@ -391,8 +407,8 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
                       --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
                       constructions. Set GROUP_BCONDS to yes to make use of it.
 --target <platform>, --target=<platform>
-                     - build for platform <platform>.
---init-rpm-dir       - initialize ~/rpm directory structure
+                    - build for platform <platform>.
+--init-rpm-dir      - initialize ~/rpm directory structure
 "
 }
 
@@ -602,7 +618,7 @@ parse_spec() {
        cd $PACKAGE_DIR
        cache_rpm_dump
 
-       if (rpm_dump | grep -qEi ":.*nosource.*1"); then
+       if rpm_dump | grep -qEi ":.*nosource.*1"; then
                FAIL_IF_NO_SOURCES="no"
        fi
 
@@ -742,7 +758,7 @@ get_spec() {
 
        if [ "$NOCVSSPEC" != "yes" ]; then
                if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
-                       echo "Warning: No CVS access defined - using local .spec file"
+                       echo "Warning: No CVS access defined in $(pwd)- using local .spec file"
                        NOCVSSPEC="yes"
                fi
 
@@ -784,8 +800,11 @@ get_spec() {
                # create symlinks for tools
                if [ "$SYMLINK_TOOLS" != "no" ]; then
                        for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
+                               # skip tools that don't exist in top dir
                                [ -f $a ] || continue
-                               ln -sf ../$a $ASSUMED_NAME
+                               # skip tools that already exist
+                               [ -f $ASSUMED_NAME/$a ] && continue
+                               ln -s ../$a $ASSUMED_NAME
                                cvsignore_df $a
                        done
                fi
@@ -831,11 +850,14 @@ find_mirror() {
 
 # Warning: unpredictable results if same URL used twice
 src_no() {
+       local file="$1"
+       # escape some regexp characters if part of file name
+       file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
        cd $PACKAGE_DIR
        rpm_dump | \
-       grep "SOURCEURL[0-9]*[  ]*$1""[         ]*$" | \
-       sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
-       head -n 1 | xargs
+       grep -E "(SOURCE|PATCH)URL[0-9]*[       ]*${file}""[    ]*$" | \
+       sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
+       head -n 1 | tr OURCEATH ourceath | xargs
 }
 
 src_md5() {
@@ -865,7 +887,7 @@ src_md5() {
                fi
        fi
 
-       source_md5=`grep -i "^#[        ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://'`
+       source_md5=`grep -i "^#[        ]*$no-md5[      ]*:" $SPECFILE | sed -e 's/.*://'`
        if [ -n "$source_md5" ]; then
                echo $source_md5
        else
@@ -875,7 +897,7 @@ src_md5() {
                else
                        # we have empty SourceX-md5, but it is still possible
                        # that we have NoSourceX-md5 AND NoSource: X
-                       nosource_md5=`grep -i "^#[       ]*NoSource$no-md5[      ]*:" $SPECFILE | sed -e 's/.*://'`
+                       nosource_md5=`grep -i "^#[       ]*No$no-md5[    ]*:" $SPECFILE | sed -e 's/.*://'`
                        if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[     ]*$no$" $SPECFILE`" ] ; then
                                echo $nosource_md5
                        fi
@@ -1010,10 +1032,10 @@ update_md5() {
                local srcno=$(src_no "$i")
                if [ -n "$ADD5" ]; then
                        [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
-                       grep -qiE '^#[  ]*Source'$srcno'-md5[   ]*:' $PACKAGE_DIR/$SPECFILE && continue
+                       grep -qiE '^#[  ]*'$srcno'-md5[         ]*:' $PACKAGE_DIR/$SPECFILE && continue
                        grep -qiE '^BuildRequires:[     ]*digest[(]%SOURCE'$srcno'[)][  ]*=' $PACKAGE_DIR/$SPECFILE && continue
                else
-                       grep -qiE '^#[  ]*Source'$srcno'-md5[   ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[      ]*digest[(]%SOURCE'$srcno'[)][  ]*=' $PACKAGE_DIR/$SPECFILE || continue
+                       grep -qiE '^#[  ]*'$srcno'-md5[         ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[      ]*digest[(]%SOURCE'$srcno'[)][  ]*=' $PACKAGE_DIR/$SPECFILE || continue
                fi
                if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
                        need_files="$need_files $i"
@@ -1029,22 +1051,22 @@ update_md5() {
        for i in "$@"; do
                local fp=$(nourl "$i")
                local srcno=$(src_no "$i")
-               local md5=$(grep -iE '^#[       ]*(No)?Source'$srcno'-md5[      ]*:' $PACKAGE_DIR/$SPECFILE )
+               local md5=$(grep -iE '^#[       ]*(No)?'$srcno'-md5[    ]*:' $PACKAGE_DIR/$SPECFILE )
                if [ -z "$md5" ]; then
                        md5=$(grep -iE '^[      ]*BuildRequires:[       ]*digest[(]%SOURCE'$srcno'[)][  ]*=' $PACKAGE_DIR/$SPECFILE )
                fi
                if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
-                       local tag="# Source$srcno-md5:\t"
+                       local tag="# $srcno-md5:\t"
                        if [[ "$md5" == *NoSource* ]]; then
                                tag="# NoSource$srcno-md5:\t"
                        elif [ -n "$USEDIGEST" ]; then
                                tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
                        fi
                        md5=$(md5sum "$fp" | cut -f1 -d' ')
-                       echo "Updating Source$srcno ($md5: $fp)."
+                       echo "Updating $srcno ($md5: $fp)."
                        perl -i -ne '
-                               print unless (/^\s*#\s*(No)?Source'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
-                               print "'"$tag$md5"'\n" if /^Source'$srcno'\s*:\s+/;
+                               print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
+                               print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
                        ' \
                        $PACKAGE_DIR/$SPECFILE
                fi
@@ -1201,10 +1223,10 @@ get_files() {
                                                im="$i"
                                        fi
                                        update_shell_title "${GETURI%% *}: $im"
-                                       ${GETURI} "$im" ${OUTFILEOPT} "$target" || \
+                                       ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
                                        if [ "`echo $im | grep -E 'ftp://'`" ]; then
                                                update_shell_title "${GETURI2%% *}: $im"
-                                               ${GETURI2} "$im" ${OUTFILEOPT} "$target"
+                                               ${GETURI2} ${OUTFILEOPT} "$target" "$im"
                                        fi
                                        test -s "$target" || rm -f "$target"
                                fi
@@ -1305,6 +1327,9 @@ is_tag_a_branch() {
        fi
 
        TAG=$1
+       # escape some regexp characters if part of TAG
+       TAG=$(echo "$TAG" | sed -e 's#\([\+\*\.]\)#\\\1#g')
+
 
        cd "$PACKAGE_DIR"
        $CVS_COMMAND status -v $SPECFILE | grep -Eiq "${TAG}.+(branch: [0-9.]+)"
@@ -1622,7 +1647,7 @@ process_bcondrc() {
        # w32codec-installer license_agreement
        # php +mysqli
        # ---
-       if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then
+       if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
                :
        else
                return
@@ -2116,11 +2141,13 @@ mr_proper() {
        get_spec
        parse_spec
 
+       local builddir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
+       
        # remove from CVS/Entries
        cvs_entry_remove $PACKAGE_DIR $SPECFILE $SOURCES $PATCHES
 
        # remove spec and sources
-       $RPMBUILD --clean --rmsource --rmspec --nodeps --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $SPECFILE
+       $RPMBUILD --clean --rmsource --rmspec --nodeps --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" --define "_builddir $builddir" $SPECFILE
 }
 
 #---------------------------------------------
@@ -2543,6 +2570,8 @@ case "$COMMAND" in
                # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
                if [ -n "$TEST_TAG" ]; then
                        local TAGVER=`make_tagver`
+                       # escape some regexp characters if part of TAGVER
+                       TAGVER=$(echo "$TAGVER" | sed -e 's#\([\+\*\.]\)#\\\1#g')
                        echo "Searching for tag $TAGVER..."
                        TAGREL=$($CVS_COMMAND status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
                        if [ -n "$TAGREL" ]; then
@@ -2572,7 +2601,7 @@ case "$COMMAND" in
                                ;;
                        *)
                                NODIST="yes" get_files $SOURCES $PATCHES
-                               update_md5 $SOURCES
+                               update_md5 $SOURCES $PATCHES
                                ;;
                esac
                build_package
@@ -2642,7 +2671,7 @@ case "$COMMAND" in
                if [ -n "$NOSOURCE0" ] ; then
                        SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
                fi
-               update_md5 $SOURCES
+               update_md5 $SOURCES $PATCHES
                ;;
        "tag" )
                NOURLS=1
This page took 0.543844 seconds and 4 git commands to generate.