]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
- tmpfile todo for lftp
[packages/rpm-build-tools.git] / builder.sh
index a8b365716676d51b309e97840b5b4e9ede2b511d..82843462a683b1a5243ec949e84e354fd169d128 100644 (file)
@@ -37,8 +37,8 @@ APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
 RCSID='$Id$' r=${RCSID#* * } rev=${r%% *}
 VERSION="v0.35/$rev"
 VERSIONSTRING="\
-Build package utility from PLD Linux CVS repository
-$VERSION (C) 1999-2010 Free Penguins".
+Build package utility from PLD Linux Packages repository
+$VERSION (C) 1999-2011 Free Penguins".
 
 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
 
@@ -105,7 +105,12 @@ PACKAGE_RELEASE=""
 PACKAGE_VERSION=""
 PACKAGE_NAME=""
 ASSUMED_NAME=""
-PROTOCOL="ftp"
+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"
@@ -231,7 +240,7 @@ POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
 
 run_poldek() {
-       RES_FILE=$(mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM)
+       RES_FILE=$(tempfile)
        if [ -n "$LOGFILE" ]; then
                LOG=`eval echo $LOGFILE`
                if [ -n "$LASTLOG_FILE" ]; then
@@ -249,13 +258,28 @@ run_poldek() {
 #---------------------------------------------
 # functions
 
+download_lftp() {
+       local url=$1 outfile=$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 "\
-Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|-ba|--build]
+Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--add_cvs] [-b|-ba|--build]
 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
-[-g|--get] [-h|--help] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
+[-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>]
 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] [--use-greed-sources]
@@ -263,14 +287,17 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
 <package>[.spec][:cvstag]
 
+-4                  - force ipv4 when transferring files
 -5, --update-md5    - update md5 comments in spec, implies -nd -ncs
+-6                  - force ipv6 when transferring files
 -a5, --add-md5      - add md5 comments to URL sources, implies -nc -nd -ncs
 -n5, --no-md5       - ignore md5 comments in spec
 -D, --debug         - enable builder script debugging mode,
 -debug              - produce rpm debug package (same as --opts -debug)
 -V, --version       - output builder version string
 --short-version     - output builder short version
--a, --as_anon       - get files via pserver as cvs@$CVS_SERVER,
+--as_anon           - get files via pserver as cvs@$CVS_SERVER,
+-a, --add_cvs       - try add new package to CVS.
 -b, -ba, --build    - get all files from CVS repo or HTTP/FTP and build package
                       from <package>.spec,
 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
@@ -278,33 +305,29 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
 -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,
---http              - use http instead of ftp,
+-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,
@@ -332,7 +355,7 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
 -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
@@ -340,7 +363,7 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
 -sf, --source-files - list sources - bare filenames (intended for offline
                       operations; does not work when Icon field is present
                       but icon file is absent),
--sp, --source-paths - list sources - filenames with full local paths (intended for
+-lsp, --source-paths - list sources - filenames with full local paths (intended for
                       offline operations; does not work when Icon field is present
                       but icon file is absent),
 -su, --source-urls  - list urls - urls to sources and patches
@@ -349,10 +372,8 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
                     - 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>
@@ -363,7 +384,7 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
 -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
@@ -371,13 +392,14 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
 -U, --update        - refetch sources, don't use distfiles, and update md5 comments
 -Upi, --update-poldek-indexes
                     - refresh or make poldek package index files.
+-sp, --skip-patch <patchnumber>
+                    - don't apply <patchnumber>. may be repeated.
 -np, --nopatch <patchnumber>
-                    - don't apply <patchnumber>
+                    - 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>/
@@ -385,11 +407,16 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
                       --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
 "
 }
 
+# create tempfile. as secure as possible
+tempfile() {
+       mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
+}
+
 # change dependency to specname
 # common changes:
 # - perl(Package::Name) -> perl-Package-Name
@@ -653,6 +680,9 @@ Exit_error() {
                        remove_build_requires
                        echo >&2 "Error: some source, patch or icon files not stored in CVS repo. ($2)"
                        exit 4 ;;
+               "err_cvs_add_failed" )
+                       echo >&2 "Error: failed to add package to CVS repo."
+                       exit 4 ;;
                "err_build_fail" )
                        remove_build_requires
                        echo >&2 "Error: package build failed. (${2:-no more info})"
@@ -734,6 +764,15 @@ get_spec() {
 
                if [ -d "$ASSUMED_NAME" -a -s "$ASSUMED_NAME/CVS/Root" ]; then
                        cvsup "$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
+               elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
+                       if [ ! -r "$ASSUMED_NAME/$SPECFILE" ]; then
+                               echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
+                               exit 101
+                       fi
+                       if [ ! -s "$ASSUMED_NAME/CVS/Root" ]; then
+                               cvsup -a $ASSUMED_NAME || Exit_error err_cvs_add_failed
+                       fi
+                       cvsup -a "$ASSUMED_NAME/$SPECFILE" || Exit_error err_cvs_add_failed
                else
                        cvsup -c -d $ASSUMED_NAME "packages/$ASSUMED_NAME/$SPECFILE" || {
                                # softfail if new package, i.e not yet added to cvs
@@ -745,26 +784,30 @@ get_spec() {
 
                        # remove Entries.Static -- so 'cvs up' would update all files in a repo
                        rm -f "$ASSUMED_NAME/CVS/Entries.Static"
-                       cvsignore_df .cvsignore
-
-                       # add default log format to .cvsignore if it is relative to package dir
-                       if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
-                               # substitute known "macros" to glob
-                               local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\),*,g')
-                               if [ "$logfile" ]; then
-                                       cvsignore_df "$logfile"
-                               fi
-                       fi
+               fi
 
-                       # 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
-                                       [ -f $a ] || continue
-                                       ln -sf ../$a $ASSUMED_NAME
-                                       cvsignore_df $a
-                               done
+               cvsignore_df .cvsignore
+
+               # add default log format to .cvsignore if it is relative to package dir
+               if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
+                       # substitute known "macros" to glob
+                       local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\),*,g')
+                       if [ "$logfile" ]; then
+                               cvsignore_df "$logfile"
                        fi
                fi
+
+               # 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
+                               # skip tools that already exist
+                               [ -f $ASSUMED_NAME/$a ] && continue
+                               ln -s ../$a $ASSUMED_NAME
+                               cvsignore_df $a
+                       done
+               fi
        fi
 
        if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
@@ -807,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() {
@@ -841,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
@@ -851,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
@@ -896,24 +942,36 @@ cvsignore_df() {
 
 cvsup() {
        update_shell_title "cvsup"
-       local OPTIONS="up "
+       local OPTIONS="" ACTION="up"
 
+       # checkout
        if [ "$1" = "-c" ]; then
-               OPTIONS="co "
+               ACTION="co"
+               shift
+       fi
+       # add
+       if [ "$1" = "-a" ]; then
+               ACTION="add"
                shift
        fi
+
+       OPTIONS="$ACTION "
+
        if [ -n "$CVSROOT" ]; then
                OPTIONS="-d $CVSROOT $OPTIONS"
        fi
 
-       if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
-               OPTIONS="$OPTIONS -A"
-       else
-               if [ -n "$CVSDATE" ]; then
-                       OPTIONS="$OPTIONS -D $CVSDATE"
-               fi
-               if [ -n "$CVSTAG" ]; then
-                       OPTIONS="$OPTIONS -r $CVSTAG"
+       if [ "$ACTION" != "add" ]; then
+               if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
+                       OPTIONS="$OPTIONS -A"
+               else
+                       if [ -n "$CVSDATE" ]; then
+                               OPTIONS="$OPTIONS -D $CVSDATE"
+                       fi
+                       if [ -n "$CVSTAG" ]; then
+                               # FIXME: cvs add actually works with -r ?
+                               OPTIONS="$OPTIONS -r $CVSTAG"
+                       fi
                fi
        fi
 
@@ -929,7 +987,8 @@ cvsup() {
                output=$(LC_ALL=C $CVS_COMMAND $OPTIONS "$@" 2>&1)
                result=$?
                [ -n "$output" ] && echo "$output"
-               if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
+               if echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)" \
+                       && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
                        echo "Trying again [$*]... ($retries_counter)"
                        update_shell_title "cvsup: retry #$retries_counter"
                        sleep 2
@@ -973,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"
@@ -992,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
@@ -1268,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.]+)"
@@ -1477,6 +1539,10 @@ try_upgrade() {
                        set_release $SPECFILE $PACKAGE_RELEASE 1
                        set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
                        parse_spec
+                       if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
+                               echo >&2 "Upgrading version failed, you need to update spec yourself"
+                               exit 1
+                       fi
                        return 1
                fi
        fi
@@ -1521,7 +1587,7 @@ build_package() {
                if [ -n "$LASTLOG_FILE" ]; then
                        echo "LASTLOG=$LOG" > $LASTLOG_FILE
                fi
-               RES_FILE=$(mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM)
+               RES_FILE=$(tempfile)
 
                (time eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
                RETVAL=`cat $RES_FILE`
@@ -2009,13 +2075,23 @@ fetch_build_requires()
 }
 
 init_rpm_dir() {
-       TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
-       CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
+       local CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
+       local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
+       local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
+       local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
+       local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
+       local tmp
 
        echo "Initializing rpm directories to $TOP_DIR from $CVSROOT"
-       mkdir -p $TOP_DIR/{RPMS,BUILD,SRPMS}
-       cd $TOP_DIR
-       $CVS_COMMAND -d $CVSROOT co packages/{.cvsignore,rpm.groups,dropin,mirrors,md5,adapter{,.awk},fetchsrc_request,builder,{relup,compile,repackage}.sh}
+       mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
+
+       # need to checkout to tmp dir or we can't name our topdir
+       tmp=$(TMPDIR= TEMPDIR= mktemp -p $TOP_DIR -d) || exit 1
+       cd $tmp
+       $CVS_COMMAND -d $CVSROOT co packages/{.cvsignore,rpm.groups,dropin,mirrors,md5,adapter{,.awk},fetchsrc_request,builder,{relup,compile,repackage}.sh,ci,civim}
+       cd -
+       mv $tmp/packages/* $TOP_DIR
+       rm -rf $tmp
 
        init_builder
 
@@ -2023,11 +2099,11 @@ init_rpm_dir() {
        echo "- run cvs co SPECS"
 
        echo "To checkout *all* packages:"
-       echo "- run cvs up -dP in $TOP_DIR/packages dir"
+       echo "- run cvs up -dP in $TOP_DIR dir"
 
        echo ""
        echo "To commit with your developer account:"
-       echo "- edit $TOP_DIR/packages/CVS/Root"
+       echo "- edit $TOP_DIR/CVS/Root"
 }
 
 get_greed_sources() {
@@ -2065,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
 }
 
 #---------------------------------------------
@@ -2082,6 +2160,12 @@ fi
 
 while [ $# -gt 0 ]; do
        case "${1}" in
+               -4|-6)
+                       # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
+                       # unfortunately $GETURI is already formed
+                       GETURI="$GETURI $1"
+                       shift
+                       ;;
                -5 | --update-md5)
                        COMMAND="update_md5"
                        NODIST="yes"
@@ -2103,8 +2187,11 @@ while [ $# -gt 0 ]; do
                        COMMAND="version"; shift ;;
                --short-version )
                        COMMAND="short-version"; shift ;;
-               -a | --as_anon )
+               --as_anon )
                        CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
+               -a | --add_cvs)
+                       COMMAND="add_cvs";
+                       shift ;;
                -b | -ba | --build )
                        COMMAND="build"; shift ;;
                -bb | --build-binary )
@@ -2131,8 +2218,18 @@ while [ $# -gt 0 ]; do
                        COMMAND="get"; shift ;;
                -h | --help )
                        COMMAND="usage"; shift ;;
+               --ftp )
+                       PROTOCOL="ftp"; shift ;;
                --http )
                        PROTOCOL="http"; shift ;;
+               -j)
+                       RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
+                       shift 2
+                       ;;
+               -j[0-9]*)
+                       RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
+                       shift
+                       ;;
                -l | --logtofile )
                        shift; LOGFILE="${1}"; shift ;;
                -ni| --nice )
@@ -2174,6 +2271,8 @@ while [ $# -gt 0 ]; do
                        shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
                --nopatch | -np )
                        shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
+               --skip-patch | -sp )
+                       shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
                --topdir)
                        RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
                        shift 2
@@ -2229,19 +2328,19 @@ while [ $# -gt 0 ]; do
                -sc | --sources-cvs)
                        COMMAND="list-sources-cvs"
                        shift ;;
-               -sd | --sources-distfiles)
+               -sd | --source-distfiles)
                        COMMAND="list-sources-distfiles"
                        shift ;;
-               -sdp | --sources-distfiles-paths)
+               -sdp | --source-distfiles-paths)
                        COMMAND="list-sources-distfiles-paths"
                        shift ;;
-               -sf | --sources-files)
+               -sf | --source-files)
                        COMMAND="list-sources-files"
                        shift ;;
-               -sp | --sources-paths)
+               -lsp | --source-paths)
                        COMMAND="list-sources-local-paths"
                        shift ;;
-               -su | --sources-urls)
+               -su | --source-urls)
                        COMMAND="list-sources-urls"
                        shift ;;
                -Tvs | --tag-version-stable )
@@ -2393,187 +2492,208 @@ update_shell_title "$COMMAND"
 case "$COMMAND" in
        "show_bconds")
                init_builder
-               if [ -n "$SPECFILE" ]; then
-                       get_spec > /dev/null
-                       parse_spec
-                       set_bconds_values
-                       display_bconds
+               if [ -z "$SPECFILE" ]; then
+                       Exit_error err_no_spec_in_cmdl
                fi
+               get_spec > /dev/null
+               parse_spec
+               set_bconds_values
+               display_bconds
                ;;
        "show_bcond_args")
                init_builder
-               if [ -n "$SPECFILE" ]; then
-                       get_spec > /dev/null
-                       parse_spec
-                       set_bconds_values
-                       echo "$BCOND"
+               if [ -z "$SPECFILE" ]; then
+                       Exit_error err_no_spec_in_cmdl
                fi
+               get_spec > /dev/null
+               parse_spec
+               set_bconds_values
+               echo "$BCOND"
                ;;
        "show_avail_bconds")
                init_builder
-               if [ -n "$SPECFILE" ]; then
-                       get_spec > /dev/null
-                       parse_spec
-                       local bcond_avail=$(find_spec_bcond $SPECFILE)
-                       local opt bcond bconds
-                       for opt in $bcond_avail; do
-                               case "$opt" in
-                               without_*)
-                                       bcond=${opt#without_}
-                                       bconds="$bconds $bcond"
-                                       ;;
-                               with_*)
-                                       bcond=${opt#with_}
-                                       bconds="$bconds $bcond"
-                                       ;;
-                               *)
-                                       echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
-                                       exit 1
-                                       ;;
-                               esac
-                       done
-                       echo $bconds
+               if [ -z "$SPECFILE" ]; then
+                       Exit_error err_no_spec_in_cmdl
                fi
 
+               get_spec > /dev/null
+               parse_spec
+               local bcond_avail=$(find_spec_bcond $SPECFILE)
+               local opt bcond bconds
+               for opt in $bcond_avail; do
+                       case "$opt" in
+                       without_*)
+                               bcond=${opt#without_}
+                               bconds="$bconds $bcond"
+                               ;;
+                       with_*)
+                               bcond=${opt#with_}
+                               bconds="$bconds $bcond"
+                               ;;
+                       *)
+                               echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
+                               exit 1
+                               ;;
+                       esac
+               done
+               echo $bconds
+
                ;;
        "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
                init_builder
-               if [ -n "$SPECFILE" ]; then
-                       # display SMP make flags if set
-                       smp_mflags=$(rpm -E %{?_smp_mflags})
-                       if [ "$smp_mflags" ]; then
-                               echo "builder: SMP make flags are set to $smp_mflags"
-                       fi
+               if [ -z "$SPECFILE" ]; then
+                       Exit_error err_no_spec_in_cmdl
+               fi
 
-                       get_spec
-                       parse_spec
-                       set_bconds_values
-                       display_bconds
-                       display_branches
-                       if [ "$COMMAND" != "build-source" ]; then
-                               check_buildarch
-                       fi
-                       fetch_build_requires
-                       if [ "$INTEGER_RELEASE" = "yes" ]; then
-                               echo "Checking release $PACKAGE_RELEASE..."
-                               if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
-                                       Exit_error err_fract_rel "$PACKAGE_RELEASE"
-                               fi
+               # display SMP make flags if set
+               smp_mflags=$(rpm -E %{?_smp_mflags})
+               if [ "$smp_mflags" ]; then
+                       echo "builder: SMP make flags are set to $smp_mflags"
+               fi
+
+               get_spec
+               parse_spec
+               set_bconds_values
+               display_bconds
+               display_branches
+               if [ "$COMMAND" != "build-source" ]; then
+                       check_buildarch
+               fi
+               fetch_build_requires
+               if [ "$INTEGER_RELEASE" = "yes" ]; then
+                       echo "Checking release $PACKAGE_RELEASE..."
+                       if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
+                               Exit_error err_fract_rel "$PACKAGE_RELEASE"
                        fi
+               fi
 
-                       # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
-                       if [ -n "$TEST_TAG" ]; then
-                               local TAGVER=`make_tagver`
-                               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
-                                       Exit_error err_tag_exists "$TAGVER" "$TAGREL"
-                               fi
+               # ./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
+                               Exit_error err_tag_exists "$TAGVER" "$TAGREL"
+                       fi
 
-                               # - do not allow to build from HEAD when XX-branch exists
-                               TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto-\([a-zA-Z]\+\)-.*#\1#g')
-                               if [ "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
-                                       TAG_BRANCH="${TREE_PREFIX}-branch"
-                                       TAG_STATUS=$($CVS_COMMAND status -v $SPECFILE | grep -Ei "${TAG_BRANCH}.+(branch: [0-9.]+)")
-                                       if [ -n "$TAG_STATUS" -a "$CVSTAG" = "HEAD" ]; then
-                                               Exit_error err_branch_exists "$TAG_STATUS"
-                                       fi
+                       # - do not allow to build from HEAD when XX-branch exists
+                       TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto-\([a-zA-Z]\+\)-.*#\1#g')
+                       if [ "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
+                               TAG_BRANCH="${TREE_PREFIX}-branch"
+                               TAG_STATUS=$($CVS_COMMAND status -v $SPECFILE | grep -Ei "${TAG_BRANCH}.+(branch: [0-9.]+)")
+                               if [ -n "$TAG_STATUS" -a "$CVSTAG" = "HEAD" ]; then
+                                       Exit_error err_branch_exists "$TAG_STATUS"
                                fi
-
                        fi
 
-                       if [ -n "$NOSOURCE0" ] ; then
-                               SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
-                       fi
-                       try_upgrade
-                       case $? in
-                               0)
-                                       get_files $SOURCES $PATCHES
-                                       check_md5 $SOURCES
-                                       ;;
-                               *)
-                                       NODIST="yes" get_files $SOURCES $PATCHES
-                                       update_md5 $SOURCES
-                                       ;;
-                       esac
-                       build_package
-                       if [ "$UPDATE_POLDEK_INDEXES" = "yes" -a "$COMMAND" != "build-prep" ]; then
-                               run_poldek --sdir="${POLDEK_INDEX_DIR}" --mkidxz
-                       fi
-                       remove_build_requires
-               else
-                       Exit_error err_no_spec_in_cmdl
                fi
+
+               if [ -n "$NOSOURCE0" ] ; then
+                       SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
+               fi
+               try_upgrade
+               case $? in
+                       0)
+                               get_files $SOURCES $PATCHES
+                               check_md5 $SOURCES
+                               ;;
+                       *)
+                               NODIST="yes" get_files $SOURCES $PATCHES
+                               update_md5 $SOURCES $PATCHES
+                               ;;
+               esac
+               build_package
+               if [ "$UPDATE_POLDEK_INDEXES" = "yes" -a "$COMMAND" != "build-prep" ]; then
+                       run_poldek --sdir="${POLDEK_INDEX_DIR}" --mkidxz
+               fi
+               remove_build_requires
                ;;
        "branch" )
                init_builder
-               if [ -n "$SPECFILE" ]; then
-                       get_spec
-                       parse_spec
-                       # don't fetch sources from remote locations
-                       new_SOURCES=""
-                       for file in $SOURCES; do
-                               [ -n "`src_md5 $file`" ] && continue
-                               new_SOURCES="$new_SOURCES $file"
-                       done
-                       SOURCES="$new_SOURCES"
-                       get_files $SOURCES $PATCHES
-                       check_md5 $SOURCES
-                       branch_files $TAG $SOURCES $PATCHES $ICONS
-               else
+               if [ -z "$SPECFILE" ]; then
                        Exit_error err_no_spec_in_cmdl
                fi
+
+               get_spec
+               parse_spec
+               # don't fetch sources from remote locations
+               new_SOURCES=""
+               for file in $SOURCES; do
+                       [ -n "`src_md5 $file`" ] && continue
+                       new_SOURCES="$new_SOURCES $file"
+               done
+               SOURCES="$new_SOURCES"
+               get_files $SOURCES $PATCHES
+               check_md5 $SOURCES
+               branch_files $TAG $SOURCES $PATCHES $ICONS
                ;;
-       "get" )
+       "add_cvs" )
                init_builder
-               if [ -n "$SPECFILE" ]; then
-                       get_spec
-                       parse_spec
+               if [ -z "$SPECFILE" ]; then
+                       Exit_error err_no_spec_in_cmdl
+               fi
 
-                       if [ -n "$NOSOURCE0" ] ; then
-                               SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
-                       fi
-                       get_files $SOURCES $PATCHES
-                       check_md5 $SOURCES
-               else
+               ADD_PACKAGE_CVS=yes get_spec
+               parse_spec
+
+               if [ -n "$NOSOURCE0" ] ; then
+                       SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
+               fi
+               get_files $SOURCES $PATCHES
+               check_md5 $SOURCES
+               ;;
+       "get" )
+               init_builder
+               if [ -z "$SPECFILE" ]; then
                        Exit_error err_no_spec_in_cmdl
                fi
+
+               get_spec
+               parse_spec
+
+               if [ -n "$NOSOURCE0" ] ; then
+                       SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
+               fi
+               get_files $SOURCES $PATCHES
+               check_md5 $SOURCES
                ;;
        "update_md5" )
                init_builder
-               if [ -n "$SPECFILE" ]; then
-                       get_spec
-                       parse_spec
-
-                       if [ -n "$NOSOURCE0" ] ; then
-                               SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
-                       fi
-                       update_md5 $SOURCES
-               else
+               if [ -z "$SPECFILE" ]; then
                        Exit_error err_no_spec_in_cmdl
                fi
+
+               get_spec
+               parse_spec
+
+               if [ -n "$NOSOURCE0" ] ; then
+                       SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
+               fi
+               update_md5 $SOURCES $PATCHES
                ;;
        "tag" )
                NOURLS=1
                NODIST="yes"
                init_builder
-               if [ -n "$SPECFILE" ]; then
-                       get_spec
-                       parse_spec
-
-                       # don't fetch sources from remote locations
-                       new_SOURCES=""
-                       for file in $SOURCES; do
-                               [ -n "`src_md5 $file`" ] && continue
-                               new_SOURCES="$new_SOURCES $file"
-                       done
-                       SOURCES="$new_SOURCES"
-                       get_files $SOURCES $PATCHES
-                       check_md5 $SOURCES
-                       tag_files $SOURCES $PATCHES $ICONS
-               else
+               if [ -z "$SPECFILE" ]; then
                        Exit_error err_no_spec_in_cmdl
                fi
+
+               get_spec
+               parse_spec
+
+               # don't fetch sources from remote locations
+               new_SOURCES=""
+               for file in $SOURCES; do
+                       [ -n "`src_md5 $file`" ] && continue
+                       new_SOURCES="$new_SOURCES $file"
+               done
+               SOURCES="$new_SOURCES"
+               get_files $SOURCES $PATCHES
+               check_md5 $SOURCES
+               tag_files $SOURCES $PATCHES $ICONS
                ;;
        "mr-proper" )
                mr_proper
This page took 0.068065 seconds and 4 git commands to generate.