]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
Inserts git log instead of %changelog
[packages/rpm-build-tools.git] / builder.sh
old mode 100644 (file)
new mode 100755 (executable)
index 360eb5f..d6595af
 #        9 - Requested tag already exist
 #       10 - Refused to build fractional release
 #      100 - Unknown error (should not happen)
+#   110 - Functions not yet implemented
 
 # Notes (todo/bugs):
-# - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
 # - when Icon: field is present, -5 and -a5 doesn't work
 # - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
 # - does not respect NoSource: X, and tries to cvs up such files [ example: VirtualBox-bin.spec and its Source0 ]
 # TODO:
 # - ability to do ./builder -bb foo.spec foo2.spec foo3.spec
-
-RCSID='$Id$'
-r=${RCSID#* * }
-rev=${r%% *}
+# - funny bug, if source-md5 is set then builder will download from distfiles even if there is no url present:
+#   Source10:  forwardfix.pl
+#   # Source10-md5:    8bf85f7368933a4e0cb4f875bac28733
+# - builder --help:
+#      basename: missing operand
+#      Try `basename --help' for more information.
+#      -- and the normal usage info --
+
+PROGRAM=${0##*/}
+APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
+RCSID='$Id: builder,v 1.645 2011/02/13 17:54:10 glen Exp $' r=${RCSID#* * } rev=${r%% *}
 VERSION="v0.35/$rev"
 VERSIONSTRING="\
-Build package utility from PLD Linux CVS repository
-$VERSION (C) 1999-2009 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"
 
+# required rpm-build-macros
+RPM_MACROS_VER=1.534
+
 COMMAND="build"
 TARGET=""
 
@@ -45,7 +55,6 @@ QUIET=""
 CLEAN=""
 DEBUG=""
 NOURLS=""
-NOCVS=""
 NOCVSSPEC=""
 NODIST=""
 NOINIT=""
@@ -55,7 +64,6 @@ ADD5=""
 NO5=""
 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
 CVSROOT=""
-GREEDSRC=""
 
 # use rpm 4.4.6+ digest format instead of comments if non-zero
 USEDIGEST=
@@ -87,7 +95,7 @@ BCOND=""
 GROUP_BCONDS="no"
 
 # create symlinks for tools in PACKAGE_DIR, see get_spec()
-SYMLINK_TOOLS="yes"
+SYMLINK_TOOLS="no"
 
 PATCHES=""
 SOURCES=""
@@ -96,7 +104,7 @@ PACKAGE_RELEASE=""
 PACKAGE_VERSION=""
 PACKAGE_NAME=""
 ASSUMED_NAME=""
-PROTOCOL="ftp"
+PROTOCOL="http"
 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
 
 CVS_COMMAND=${CVS_COMMAND:-cvs}
@@ -105,6 +113,9 @@ CVSIGNORE_DF="yes"
 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
 CVS_SERVER="cvs.pld-linux.org"
 CVSTAG=""
+GIT_SERVER="git://github.com/draenog"
+HEAD_DETACHED=""
+DEPTH=""
 
 RES_FILE=""
 
@@ -203,17 +214,19 @@ else
 fi
 
 #
-# are we using cvs-nserver ?
+# sanity checks
 #
-CVS_NSERVER=0
-$CVS_COMMAND --version 2>&1 | grep -q 'CVS-nserver'
-[ $? -eq 0 ] && CVS_NSERVER=1
+if [ -d $HOME/rpm/SOURCES ]; then
+       echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
+       echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
+       exit 1
+fi
 
 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
@@ -234,13 +247,13 @@ run_poldek() {
 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]
+[{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [--depth <number>]
+[-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]
+[{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
 <package>[.spec][:cvstag]
@@ -252,7 +265,8 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
 -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
@@ -265,8 +279,8 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
                       them into src.rpm,
 --short-circuit     - short-circuit build
 -B, --branch        - add branch
--c, --clean         - clean all temporarily created files (in BUILD, SOURCES,
-                      SPECS and \$RPM_BUILD_ROOT and CVS/Entries) after rpmbuild commands.
+-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.
@@ -275,16 +289,18 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
                     - setup \$CVSROOT,
 --define <macro> <value>
                     - define a macro <macro> with value <value>,
+--depth <number>
+                                       - make shallow fetch
 --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,
+-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
 -nd, --no-distfiles - don't download from distfiles
@@ -322,7 +338,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
@@ -345,19 +361,21 @@ 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
---use-greed-sources
-                    - try download source from tag head if don't find it in
-                      current tag
+                                       php-pear-Services_Digg/
+--upgrade-version   - upgrade to specified version in try-upgrade
 -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-avail-bconds - show available bconds
 --with/--without <feature>
                     - conditional build package depending on %_with_<feature>/
                       %_without_<feature> macro switch.  You may now use
@@ -369,26 +387,56 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
 "
 }
 
+# create tempfile. as secure as possible
+tempfile() {
+       mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
+}
+
+# inserts git log instead of %changelog
+# outputs name of modified file created by tempfile
+insert_gitlog() {
+       local SPECFILE=$1 specfile=$(tempfile) gitlog=$(tempfile) speclog=$(tempfile) 
+
+       # allow this being customized
+       local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
+
+       # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
+       # otherwise i'd use --date=iso here
+       # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
+       # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c#l31
+       # NOTE: changelog date is always in UTC for rpmbuild
+       # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
+       git log -${log_entries:-20} --format=format:"* %ad %an <%ae> %h%n%s%n" --date=raw > $gitlog
+       gawk '/^\* /{printf("* %s %s\n", strftime("%a %b %d %Y", $2), substr($0, length($1)+length($2)+length($3)+4)); next}{print}' $gitlog > $speclog
+       sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
+                       a%changelog
+                       r $speclog
+               }
+       " > $specfile
+       rm -f $gitlog $speclog
+       echo $specfile
+}
+
 # change dependency to specname
 # common changes:
 # - perl(Package::Name) -> perl-Package-Name
 depspecname() {
        local package="$1"
 
-       package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g}')
+       package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
        echo "$package"
 }
 
 update_shell_title() {
        [ -t 1 ] || return
        local len=${COLUMNS:-80}
-       local msg=$(echo "$*" | cut -c-$len)
+       local msg="$(echo "$*" | cut -c-$len)"
 
        if [ -n "$BE_VERBOSE" ]; then
                echo >&2 "$(date +%s.%N) $*"
        fi
 
-       if [ "x$TITLECHANGE" == "xyes" -o "x$TITLECHANGE" == "x" ]; then
+       if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
                local pkg
                if [ -n "$PACKAGE_NAME" ]; then
                        pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
@@ -438,16 +486,20 @@ minirpm() {
 %x8664 x86_64 amd64 ia32e
 %alt_kernel %{nil}
 %_alt_kernel %{nil}
-%requires_releq_kernel_up %{nil}
-%requires_releq_kernel_smp %{nil}
-%requires_releq_kernel %{nil}
+%bootstrap_release() %{1}
+%requires_releq_kernel_up(s:n:) %{nil}
+%requires_releq_kernel_smp(s:n:) %{nil}
+%requires_releq_kernel(s:n:) %{nil}
 %requires_releq() %{nil}
 %pyrequires_eq() %{nil}
 %requires_eq() %{nil}
 %requires_eq_to() %{nil}
-%releq_kernel_up ERROR
-%releq_kernel_smp ERROR
-%releq_kernel ERROR
+%requires_ge() %{nil}
+%requires_ge_to() %{nil}
+%requires_ge() %{nil}
+%releq_kernel_up(n:) ERROR
+%releq_kernel_smp(n:) ERROR
+%releq_kernel(n:) ERROR
 %kgcc_package ERROR
 %_fontsdir ERROR
 %ruby_version ERROR
@@ -480,6 +532,9 @@ minirpm() {
 %remove_etc_shells(p) %{p:<lua>}
 %lua_add_etc_shells()  %{nil}
 %lua_remove_etc_shells() %{nil}
+%required_jdk %{nil}
+%buildrequires_jdk %{nil}
+%pear_package_print_optionalpackages %{nil}
 EOF
        if [ "$NOINIT" = "yes" ] ; then
                cat >> $BUILDER_MACROS <<'EOF'
@@ -542,7 +597,7 @@ rpm_dump() {
 
 get_icons() {
        update_shell_title "get icons"
-       ICONS=$(awk '/^Icon:/ {print $2}' ${ASSUMED_NAME}/${SPECFILE})
+       ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
        if [ -z "$ICONS" ]; then
                return
        fi
@@ -625,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})"
@@ -649,6 +707,10 @@ Exit_error() {
                        remove_build_requires
                        echo >&2 "Error: conditions reject building this spec (${2})."
                        exit 12 ;;
+               "err_not_implemented" )
+                       remove_build_requires
+                       echo >&2 "Error: functionality not yet imlemented"
+                       exit 110 ;;
        esac
        echo >&2 "Unknown error."
        exit 100
@@ -662,12 +724,25 @@ init_builder() {
 
        if [ "$NOINIT" != "yes" ] ; then
                TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
-               REPO_DIR=$TOP_DIR/packages
-               PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
+
+               local macros_ver=$(rpm -E %?rpm_build_macros)
+               if [ -z "$macros_ver" ]; then
+                       REPO_DIR=$TOP_DIR/packages
+                       PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
+               else
+                       if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
+                               echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
+                               exit 1
+                       fi
+                       REPO_DIR=$TOP_DIR
+                       PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
+               fi
        else
                REPO_DIR="."
                PACKAGE_DIR="."
        fi
+       export GIT_WORK_TREE=$PACKAGE_DIR
+       export GIT_DIR=$PACKAGE_DIR/.git
 
        __PWD=$(pwd)
 }
@@ -683,33 +758,73 @@ get_spec() {
 
        cd "$REPO_DIR"
        if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
-               SPECFILE="$(basename $SPECFILE .spec).spec"
+               # XXX: still needed?
+               SPECFILE=$(basename $SPECFILE)
        fi
-       if [ "$NOCVSSPEC" != "yes" ]; then
 
-               if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
-                       echo "Warning: No CVS access defined - using local .spec file"
-                       NOCVSSPEC="yes"
+       if [ "$NOCVSSPEC" != "yes" ]; then
+               if [ -z "$DEPTH" ]; then
+                       if [ -d "$ASSUMED_NAME/.git" ]; then
+                               git fetch origin || 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
+                               Exit_error err_not_implemented
+                       else
+                               (
+                                       unset GIT_WORK_TREE
+                                       git clone  ${GIT_SERVER}/${ASSUMED_NAME}.git || {
+                                               # softfail if new package, i.e not yet added to cvs
+                                               [ ! -f "$ASSUMED_NAME/$SPECFILE" ] && Exit_error err_no_spec_in_repo
+                                               echo "Warning: package not in CVS - assuming new package"
+                                               NOCVSSPEC="yes"
+                                       }
+                               )
+                       fi
+               else
+                       if [ ! -d "$ASSUMED_NAME/.git" ]; then
+                               if [ ! -d "$ASSUMED_NAME" ]; then
+                                       mkdir $ASSUMED_NAME
+                               fi
+                               git init
+                               git remote add origin ${GIT_SERVER}/${ASSUMED_NAME}.git
+                       fi
+                       git fetch "$DEPTH" origin ${CVSTAG}:remotes/origin/${CVSTAG} || {
+                               echo >&2 "Error: branch $CVSTAG does not exist"
+                               exit 3
+                       }
                fi
 
-               if [ -d "$ASSUMED_NAME" ]; then
-                       cvsup "$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
-               else
-                       cvsup -c -d $ASSUMED_NAME "packages/$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
-
-                       # remove Entries.Static -- so 'cvs up' would update all files in a repo
-                       rm "$ASSUMED_NAME/CVS/Entries.Static"
-                       cvsignore_df .cvsignore
-
-                       # create symlinks for tools
-                       if [ "$SYMLINK_TOOLS" != "no" ]; then
-                               for a in dropin md5 adapter builder {relup,compile,repackage,rsync}.sh; do
-                                       [ -f $a ] || continue
-                                       ln -s ../$a $ASSUMED_NAME
-                                       cvsignore_df $a
-                               done
+               cvsignore_df .gitignore
+
+               # 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
+                               [ -f $a ] || continue
+                               ln -sf ../$a $ASSUMED_NAME
+                               cvsignore_df $a
+                       done
+               fi
+       fi
+
+       if [ -n "$CVSTAG" ]; then
+               git checkout "$CVSTAG" -- 2>/dev/null || git checkout -t "origin/$CVSTAG" > /dev/null || exit
+               git symbolic-ref -q HEAD > /dev/null &&
+                       git merge '@{u}'
+               if [ -n "$CVSDATE" ]; then
+                       git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
+               fi
        fi
 
        if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
@@ -736,7 +851,7 @@ find_mirror() {
        local origin mirror name rest ol prefix
        while read origin mirror name rest; do
                # skip comments and empty lines
-               if [ -z "$origin" ] || [[ $origin == \#* ]]; then
+               if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
                        continue
                fi
                ol=$(echo -n "$origin" | wc -c)
@@ -767,13 +882,8 @@ src_md5() {
        local md5
 
        if [ -f additional-md5sums ]; then
-               local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
-               if [ -z "$spec_rev" ]; then
-                       spec_rev=$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')
-               fi
-               local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
                md5=$(grep -s -v '^#' additional-md5sums | \
-               grep -E "[      ]$(basename "$1")[      ]+${spec}([     ,]|\$)" | \
+               grep -E "[      ]$(basename "$1")([     ,]|\$)" | \
                sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
                grep -E '^[0-9a-f]{32}$')
 
@@ -786,7 +896,7 @@ src_md5() {
                fi
        fi
 
-       source_md5=`grep -i "#[         ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://'`
+       source_md5=`grep -i "^#[        ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://'`
        if [ -n "$source_md5" ]; then
                echo $source_md5
        else
@@ -796,7 +906,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 "^#[       ]*NoSource$no-md5[      ]*:" $SPECFILE | sed -e 's/.*://'`
                        if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[     ]*$no$" $SPECFILE`" ] ; then
                                echo $nosource_md5
                        fi
@@ -831,7 +941,7 @@ cvsignore_df() {
        if [ "$CVSIGNORE_DF" != "yes" ]; then
                return
        fi
-       cvsignore=${PACKAGE_DIR}/.cvsignore
+       cvsignore=${PACKAGE_DIR}/.gitignore
 
        # add only if not yet there
        if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
@@ -839,54 +949,6 @@ cvsignore_df() {
        fi
 }
 
-cvsup() {
-       update_shell_title "cvsup"
-       local OPTIONS="up "
-
-       if [ "$1" = "-c" ]; then
-               OPTIONS="co "
-               shift
-       fi
-       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"
-               fi
-       fi
-
-       local result=1
-       local retries_counter=0
-       if [ $# = 1 ]; then
-               update_shell_title "cvsup: $*"
-       else
-               update_shell_title "cvsup: $# files"
-       fi
-       while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
-               retries_counter=$(( $retries_counter + 1 ))
-               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
-                       echo "Trying again [$*]... ($retries_counter)"
-                       update_shell_title "cvsup: retry #$retries_counter"
-                       sleep 2
-                       continue
-               else
-                       break
-               fi
-       done
-       update_shell_title "cvsup: done!"
-       return $result
-}
-
 # returns true if "$1" is ftp, http or https protocol url
 is_url() {
        case "$1" in
@@ -960,18 +1022,27 @@ update_md5() {
 }
 
 check_md5() {
+       local bad
        [ "$NO5" = "yes" ] && return
 
        update_shell_title "check md5"
 
        for i in "$@"; do
-               if good_md5 "$i" && good_size "$i"; then
-                       continue
+               bad=0
+               if ! good_md5 "$i"; then
+                       echo -n "MD5 sum mismatch."
+                       bad=1
+               fi
+               if ! good_size "$i"; then
+                       echo -n "0 sized file."
+                       bad=1
                fi
 
-               echo "MD5 sum mismatch or 0 size.  Use -U to refetch sources,"
-               echo "or -5 to update md5 sums, if you're sure files are correct."
-               Exit_error err_no_source_in_repo $i
+               if [ $bad -eq 1 ]; then
+                       echo " Use -U to refetch sources,"
+                       echo "or -5 to update md5 sums, if you're sure files are correct."
+                       Exit_error err_no_source_in_repo $i
+               fi
        done
 }
 
@@ -986,11 +1057,6 @@ get_files() {
        if [ $# -gt 0 ]; then
                cd "$PACKAGE_DIR"
 
-               if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
-                       echo "Warning: No CVS access defined for SOURCES"
-                       NOCVS="yes"
-               fi
-
                local nc=0
                local get_files_cvs=""
                for i in "$@"; do
@@ -1015,13 +1081,13 @@ get_files() {
                                if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
                                        echo "Warning: no URL given for $i"
                                fi
+                               target="$fp"
 
                                if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
                                        if good_md5 "$i" && good_size "$i"; then
                                                echo "$fp having proper md5sum already exists"
                                                continue
                                        fi
-                                       target="$fp"
 
                                        # optionally prefer mirror over distfiles if there's mirror
                                        # TODO: build url list and then try each url from the list
@@ -1073,6 +1139,7 @@ get_files() {
                                                                update_shell_title "${GETURI2%% *}: $url_attic"
                                                                ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
                                                        fi
+                                                       test -s "$target" || rm -f "$target"
                                                fi
                                        fi
 
@@ -1082,14 +1149,6 @@ get_files() {
                                                rm -f "$target"
                                                FROM_DISTFILES=0
                                        fi
-                               elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
-                                       if [ $# -gt 1 ]; then
-                                               get_files_cvs="$get_files_cvs $fp"
-                                               update_shell_title "$fp (will cvs up later)"
-                                               cvsup=1
-                                       else
-                                               cvsup $fp
-                                       fi
                                fi
 
                                if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
@@ -1098,13 +1157,13 @@ get_files() {
                                        else
                                                im="$i"
                                        fi
-                                       lf=$(basename $im)
                                        update_shell_title "${GETURI%% *}: $im"
-                                       ${GETURI} "$im" ${OUTFILEOPT} "$lf" || \
+                                       ${GETURI} "$im" ${OUTFILEOPT} "$target" || \
                                        if [ "`echo $im | grep -E 'ftp://'`" ]; then
                                                update_shell_title "${GETURI2%% *}: $im"
-                                               ${GETURI2} "$im" ${OUTFILEOPT} "$lf"
+                                               ${GETURI2} "$im" ${OUTFILEOPT} "$target"
                                        fi
+                                       test -s "$target" || rm -f "$target"
                                fi
 
                                if [ "$cvsup" = 1 ]; then
@@ -1115,11 +1174,7 @@ get_files() {
 
                        # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
                        if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
-                               if [ -n "GREEDSRC" ]; then
-                                       get_greed_sources $i
-                               else
-                                       Exit_error err_no_source_in_repo $i
-                               fi
+                               Exit_error err_no_source_in_repo $i
                        fi
 
                        # we check md5 here just only to refetch immediately
@@ -1151,9 +1206,6 @@ get_files() {
                done
                SHELL_TITLE_PREFIX=""
 
-               if [ "$get_files_cvs" ]; then
-                       cvsup $get_files_cvs
-               fi
 
                if [ "$CHMOD" = "yes" ]; then
                        CHMOD_FILES=$(nourl "$@")
@@ -1189,26 +1241,6 @@ make_tagver() {
        echo -n "$TAGVER"
 }
 
-# bool is_tag_a_branch(tag)
-#
-# returns 1 if a tag is a branch set on SPECFILE
-is_tag_a_branch() {
-       if [ -n "$DEBUG" ]; then
-               set -x
-               set -v
-       fi
-
-       if [ $# -ne 1 ]; then
-               return 0;
-       fi
-
-       TAG=$1
-
-       cd "$PACKAGE_DIR"
-       $CVS_COMMAND status -v $SPECFILE | grep -Eiq "${TAG}.+(branch: [0-9.]+)"
-       return $?
-}
-
 tag_files() {
        TAG_FILES="$@"
 
@@ -1223,114 +1255,45 @@ tag_files() {
        local TAGVER
        if [ "$TAG_VERSION" = "yes" ]; then
                TAGVER=`make_tagver`
-               echo "CVS tag: $TAGVER"
+               echo "tag: $TAGVER"
        fi
        if [ -n "$TAG" ]; then
-               echo "CVS tag: $TAG"
+               echo "tag: $TAG"
        fi
 
        local OPTIONS="tag $CVS_FORCE"
-       if [ -n "$CVSROOT" ]; then
-               OPTIONS="-d $CVSROOT $OPTIONS"
-       fi
 
-       # if a tagname we are about to set already exists
-       # and happens to be a branch (common case with AC-branch)
-       # pass -B (allows -F to disturb branch tag)
        local _tag=$TAG
        if [ "$TAG_VERSION" = "yes" ]; then
                _tag=$TAGVER
        fi;
-       is_tag_a_branch $_tag
-       if [ $? -eq 0 -a $CVS_NSERVER -eq 0 ]; then
-               OPTIONS="$OPTIONS -B"
-       fi;
 
        cd "$PACKAGE_DIR"
-       local tag_files
-       for i in $TAG_FILES; do
-               # don't tag files stored on distfiles
-               [ -n "`src_md5 $i`" ] && continue
-               local fp=`nourl "$i"`
-               if [ -f "$fp" ]; then
-                       tag_files="$tag_files $fp"
-               elif [ -n "GREEDSRC" ]; then
-                       get_greed_sources $i
-               else
-                       Exit_error err_no_source_in_repo $i
-               fi
-       done
 
-       if [ "$tag_files" ]; then
-               if [ "$TAG_VERSION" = "yes" ]; then
-                       update_shell_title "tag sources: $TAGVER"
-                       printf "Tagging %d files\n" $(echo $tag_files | wc -w)
-                       $CVS_COMMAND $OPTIONS $TAGVER $tag_files || exit
-               fi
-               if [ -n "$TAG" ]; then
-                       update_shell_title "tag sources: $TAG"
-
-                       while [ "$tag_files" ]; do
-                               local chunk=$(echo $tag_files | tr ' ' '\n' | head -n 100)
-                               printf "Tagging %d files\n" $(echo $chunk | wc -w)
-                               $CVS_COMMAND $OPTIONS $TAG $chunk || exit
-                               tag_files=$(echo $tag_files | tr ' ' '\n' | tail +101)
-                       done
-               fi
-       fi
-
-       cd "$PACKAGE_DIR"
        if [ "$TAG_VERSION" = "yes" ]; then
-               update_shell_title "tag spec: $TAGVER"
-               $CVS_COMMAND $OPTIONS $TAGVER $SPECFILE || exit
+               update_shell_title "tag sources: $TAGVER"
+               git $OPTIONS $TAGVER || exit
        fi
        if [ -n "$TAG" ]; then
-               update_shell_title "tag spec: $TAG"
-               $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
+               update_shell_title "tag sources: $TAG"
+               git $OPTIONS $TAG $chunk || exit
        fi
 }
 
 branch_files() {
        TAG=$1
-       echo "CVS branch tag: $TAG"
+       echo "Git branch: $TAG"
        shift
 
-       TAG_FILES="$@"
-
        if [ -n "$DEBUG" ]; then
                set -x
                set -v
        fi
 
-       local OPTIONS="tag $CVS_FORCE -b"
-
-       # branch exists?
-       is_tag_a_branch $TAG
-       if [ $? -eq 1 ]; then
-               OPTIONS="$OPTIONS -B"
-       fi
-
-       if [ -n "$CVSROOT" ]; then
-               OPTIONS="-d $CVSROOT $OPTIONS"
-       fi
-       cd "$PACKAGE_DIR"
-       local tag_files
-       for i in $TAG_FILES; do
-               local fp=`nourl "$i"`
-               if [ -f "$fp" ]; then
-                       tag_files="$tag_files $fp"
-               elif [ -n "GREEDSRC" ]; then
-                       get_greed_sources $i
-               else
-                       Exit_error err_no_source_in_repo $i
-               fi
-       done
-       if [ "$tag_files" ]; then
-               $CVS_COMMAND $OPTIONS $TAG $tag_files || exit
-       fi
+       local OPTIONS="branch $CVS_FORCE"
 
        cd "$PACKAGE_DIR"
-       $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
+       git $OPTIONS $TAG || exit
 }
 
 
@@ -1346,41 +1309,89 @@ check_buildarch() {
        fi
 }
 
-build_package() {
-       update_shell_title "build_package"
-       if [ -n "$DEBUG" ]; then
-               set -x
-               set -v
-       fi
+# from relup.sh
+set_release() {
+       local specfile="$1"
+       local rel="$2"
+       local newrel="$3"
+       sed -i -e "
+               s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
+               s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
+       " $specfile
+}
 
-       cd "$PACKAGE_DIR"
+set_version() {
+       local specfile="$1"
+       local ver="$2" subver=$ver
+       local newver="$3" newsubver=$newver
+
+       # try handling subver, everything that's not numeric-dotted in version
+       if grep -Eq '%define\s+subver' $specfile; then
+               subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
+               ver=${ver%$subver}
+               newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
+               newver=${newver%$newsubver}
+       fi
+       sed -i -e "
+               s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
+               s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
+               s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
+       " $specfile
+}
 
+try_upgrade() {
        if [ -n "$TRY_UPGRADE" ]; then
+               local TNOTIFY TNEWVER TOLDVER
                update_shell_title "build_package: try_upgrade"
-               if [ -n "$FLOAT_VERSION" ]; then
-                       TNOTIFY=$(./pldnotify.awk $SPECFILE -n) || exit 1
+
+               cd "$PACKAGE_DIR"
+               
+               if [ "$UPGRADE_VERSION" ]; then
+                       TNEWVER=$UPGRADE_VERSION
                else
-                       TNOTIFY=$(./pldnotify.awk $SPECFILE) || exit 1
-               fi
+                       if [ -n "$FLOAT_VERSION" ]; then
+                               TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
+                       else
+                               TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
+                       fi
+
+                       # pldnotify.awk does not set exit codes, but it has match for ERROR
+                       # in output which means so.
+                       if [[ "$TNOTIFY" = *ERROR* ]]; then
+                               echo >&2 "$TNOTIFY"
+                               exit 1
+                       fi
 
-               TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
+                       TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
+               fi
 
                if [ -n "$TNEWVER" ]; then
                        TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
-                       echo "New version found, updating spec file to version " $TNEWVER
+                       echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
                        if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
                                cp -f $SPECFILE $SPECFILE.bak
                        fi
                        chmod +w $SPECFILE
-                       eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
-                       eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE"
+                       set_release $SPECFILE $PACKAGE_RELEASE 1
+                       set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
                        parse_spec
-                       NODIST="yes" get_files $SOURCES $PATCHES
-                       update_md5 $SOURCES
-
-                       unset TOLDVER TNEWVER TNOTIFY
+                       if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
+                               echo >&2 "Upgrading version failed, you need to update spec yourself"
+                               exit 1
+                       fi
+                       return 1
                fi
        fi
+       return 0
+}
+
+build_package() {
+       update_shell_title "build_package"
+       if [ -n "$DEBUG" ]; then
+               set -x
+               set -v
+       fi
+
        cd "$PACKAGE_DIR"
 
        case "$COMMAND" in
@@ -1412,11 +1423,12 @@ 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)
+               local specfile=$(insert_gitlog $SPECFILE)
 
-               (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
+               (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`
-               rm $RES_FILE
+               rm $RES_FILE $specfile
                if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
                        if [ "$RETVAL" -eq "0" ]; then
                                mv $LOG $LOGDIROK
@@ -1430,10 +1442,12 @@ build_package() {
        fi
        if [ "$RETVAL" -ne "0" ]; then
                if [ -n "$TRY_UPGRADE" ]; then
-                       echo "\n!!! Package with new version cannot be built automagically\n"
+                       echo "\nUpgrade package to new version failed."
                        if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
+                               echo "Restoring old spec file."
                                mv -f $SPECFILE.bak $SPECFILE
                        fi
+                       echo ""
                fi
                Exit_error err_build_fail
        fi
@@ -1516,7 +1530,7 @@ set_bconds_values() {
        AVAIL_BCONDS_WITHOUT=""
        AVAIL_BCONDS_WITH=""
 
-       if egrep -q '^# *_with' ${SPECFILE}; then
+       if grep -Eq '^# *_with' ${SPECFILE}; then
                echo >&2 "ERROR: This spec has old style bconds."
                exit 1
        fi
@@ -1535,19 +1549,25 @@ set_bconds_values() {
                case "$opt" in
                without_*)
                        bcond=${opt#without_}
-                       if [[ "$BCOND" = *--without?${bcond}* ]]; then
+                       case "$BCOND" in
+                       *--without?${bcond}*)
                                AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
-                       else
+                               ;;
+                       *)
                                AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
-                       fi
+                               ;;
+                       esac
                        ;;
                with_*)
                        bcond=${opt#with_}
-                       if [[ "$BCOND" = *--with?${bcond}* ]]; then
+                       case "$BCOND" in
+                       *--with?${bcond}*)
                                AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
-                       else
+                               ;;
+                       *)
                                AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
-                       fi
+                               ;;
+                       esac
                        ;;
                *)
                        echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
@@ -1597,15 +1617,15 @@ spawn_sub_builder() {
        update_shell_title "spawn_sub_builder $package_name"
 
        sub_builder_opts=''
-       if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
+       if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
                sub_builder_opts="${sub_builder_opts} -R"
        fi
-       if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
+       if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
                sub_builder_opts="${sub_builder_opts} -RB"
-       elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
+       elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
                sub_builder_opts="${sub_builder_opts} -FRB"
        fi
-       if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
+       if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
                sub_builder_opts="${sub_builder_opts} -Upi"
        fi
 
@@ -1634,20 +1654,25 @@ remove_build_requires() {
 display_bconds() {
        if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
                if [ "$BCOND" ]; then
-                       echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
-                       echo -ne "$BCOND"
+                       echo ""
+                       echo "Building $SPECFILE with the following conditional flags:"
+                       echo -n "$BCOND"
                else
-                       echo -ne "\nNo conditional flags passed"
+                       echo ""
+                       echo "No conditional flags passed"
                fi
-               echo -ne "\n\nfrom available:\n"
-               echo -ne "--with   :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
+               echo ""
+               echo "from available:"
+               echo "--with   :\t$AVAIL_BCONDS_WITH"
+               echo "--without:\t$AVAIL_BCONDS_WITHOUT"
+               echo ""
        fi
 }
 
 display_branches() {
        if [ "$NOCVSSPEC" != "yes" ]; then
-               echo -ne "Available branches: "
-               $CVS_COMMAND status -v "${SPECFILE}" | awk '!/Sticky Tag:/ && /\(branch:/ { print $1 } ' | xargs
+               echo -n "Available branches: "
+               git branch -r | grep '^  origin' | grep -v origin/HEAD | sed 's#^ *origin/##' | xargs
        fi
 }
 
@@ -1742,10 +1767,12 @@ fetch_build_requires()
        fi
 
                # XXX is this ugliest code written in human history still needed?
-               echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
-               echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
-               echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
-               echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
+               echo "All packages installed by fetch_build_requires() are written to:"
+               echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
+               echo ""
+               echo "If anything fails, you may get rid of them by executing:"
+               echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
+               echo ""
                echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
                for package_item in $(cat $SPECFILE | grep -B100000 ^%changelog|grep -v ^#|grep BuildRequires|grep -v ^-|sed -e "s/^.*BuildRequires://g"|awk '{print $1}'|sed -e s,perl\(,perl-,g -e s,::,-,g -e s,\(.*\),,g -e s,%{,,g -e s,},,g|grep -v OpenGL-devel|sed -e s,sh-utils,coreutils,g -e s,fileutils,coreutils,g -e s,textutils,coreutils,g -e s,kgcc_package,gcc,g -e s,\),,g)
                do
@@ -1818,11 +1845,11 @@ fetch_build_requires()
                                                for package_name in `cat ".$package-req.txt"|grep -v ^#`
                                                do
                                                        if [ "$package_name" = "$package" ]; then
-                                                               echo -ne "Installing BuildRequired package:\t$package_name\n"
+                                                               echo "Installing BuildRequired package:\t$package_name"
                                                                update_shell_title "Installing BuildRequired package: ${package_name}"
                                                                install_required_packages $package
                                                        else
-                                                               echo -ne "Installing (sub)Required package:\t$package_name\n"
+                                                               echo "Installing (sub)Required package:\t$package_name"
                                                                update_shell_title "Installing (sub)Required package: ${package_name}"
                                                                install_required_packages $package_name
                                                        fi
@@ -1833,7 +1860,7 @@ fetch_build_requires()
                                                                        ;;
                                                                *)
                                                                        echo "Attempting to run spawn sub - builder..."
-                                                                       echo -ne "Package installation failed:\t$package_name\n"
+                                                                       echo "Package installation failed:\t$package_name"
                                                                        run_sub_builder $package_name
                                                                        if [ $? -eq 0 ]; then
                                                                                install_required_packages $package_name
@@ -1853,7 +1880,7 @@ fetch_build_requires()
                                                rm -f ".$package-req.txt"
                                        else
                                                echo "Attempting to run spawn sub - builder..."
-                                               echo -ne "Package installation failed:\t$package\n"
+                                               echo "Package installation failed:\t$package"
                                                run_sub_builder $package
                                                if [ $? -eq 0 ]; then
                                                        install_required_packages $package
@@ -1885,13 +1912,23 @@ fetch_build_requires()
 }
 
 init_rpm_dir() {
-       TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
-       CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
-
-       echo "Initialising 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}
+       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 $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
 
@@ -1899,23 +1936,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"
-}
-
-get_greed_sources() {
-       CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
-       if [ -n "BE_VERBOSE" ]; then
-               echo "Try greed download: $1 from: $CVSROOT"
-       fi
-       $CVS_COMMAND -d $CVSROOT get SOURCES/$1
-       if [ $? != 0 ]; then
-               Exit_error err_no_source_in_repo $1
-       fi
-
+       echo "- edit $TOP_DIR/CVS/Root"
 }
 
 # remove entries from CVS/Entries
@@ -1941,11 +1966,11 @@ mr_proper() {
        get_spec
        parse_spec
 
-       # 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" $SPECFILE
+       rm -rf $PACKAGE_DIR/.git .gitignore
+       cd $__PWD
+       rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
 }
 
 #---------------------------------------------
@@ -1966,7 +1991,6 @@ while [ $# -gt 0 ]; do
                -a5 | --add-md5 )
                        COMMAND="update_md5"
                        NODIST="yes"
-                       NOCVS="yes"
                        NOCVSSPEC="yes"
                        ADD5="yes"
                        shift ;;
@@ -1979,8 +2003,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 )
@@ -1998,17 +2025,31 @@ while [ $# -gt 0 ]; do
                -B | --branch )
                        COMMAND="branch"; shift; TAG="${1}"; shift;;
                -c | --clean )
-                       CLEAN="--clean --rmspec --rmsource"; shift ;;
+                       CLEAN="--clean"; shift ;;
                -cf | --cvs-force )
-                       CVS_FORCE="-F"; shift;;
+                       CVS_FORCE="-f"; shift;;
                -d | --cvsroot )
                        shift; CVSROOT="${1}"; shift ;;
+               --depth )
+                       DEPTH="--depth=$2"
+                       shift 2
+                       ;;
                -g | --get )
                        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 )
@@ -2017,8 +2058,6 @@ while [ $# -gt 0 ]; do
                        SKIP_EXISTING_FILES="yes"; shift ;;
                -m | --mr-proper )
                        COMMAND="mr-proper"; shift ;;
-               -nc | --no-cvs )
-                       NOCVS="yes"; shift ;;
                -ncs | --no-cvs-specs )
                        NOCVSSPEC="yes"; shift ;;
                -nd | --no-distfiles )
@@ -2032,7 +2071,6 @@ while [ $# -gt 0 ]; do
                -ns0 | --no-source0 )
                        NOSOURCE0="yes"; shift ;;
                -nn | --no-net )
-                       NOCVS="yes"
                        NOCVSSPEC="yes"
                        NODIST="yes"
                        NOMIRRORS="yes"
@@ -2050,6 +2088,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
@@ -2083,14 +2123,16 @@ while [ $# -gt 0 ]; do
                -q | --quiet )
                        QUIET="--quiet"; shift ;;
                --date )
-                       CVSDATE="${2}"; shift 2 ;;
+                       CVSDATE="${2}"; shift 2
+                       date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
+                       ;;
                -r | --cvstag )
                        CVSTAG="$2"
                        shift 2
                        ;;
                -A)
                        shift
-                       CVSTAG="HEAD"
+                       CVSTAG="master"
                        ;;
                -R | --fetch-build-requires)
                        FETCH_BUILD_REQUIRES="yes"
@@ -2105,19 +2147,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 )
@@ -2162,11 +2204,10 @@ while [ $# -gt 0 ]; do
                --init-rpm-dir)
                        COMMAND="init_rpm_dir"
                        shift ;;
-               --use-greed-sources )
-                       GREEDSRC="1"
-                       shift;;
                -u | --try-upgrade )
                        TRY_UPGRADE="1"; shift ;;
+               --upgrade-version )
+                       shift; UPGRADE_VERSION="$1"; shift;;
                -un | --try-upgrade-with-float-version )
                        TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
                -v | --verbose )
@@ -2200,6 +2241,10 @@ while [ $# -gt 0 ]; do
                        COMMAND="show_bcond_args"
                        shift
                        ;;
+               --show-avail-bconds)
+                       COMMAND="show_avail_bconds"
+                       shift
+                       ;;
                --nodeps)
                        shift
                        RPMOPTS="${RPMOPTS} --nodeps"
@@ -2211,26 +2256,32 @@ while [ $# -gt 0 ]; do
                        Exit_error err_invalid_cmdline "$1"
                        ;;
                *)
-                       SPECFILE="${1}"
+                       SPECFILE=${1%/}; shift
                        # check if specname was passed as specname:cvstag
                        if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
                                CVSTAG="${SPECFILE##*:}"
                                SPECFILE="${SPECFILE%%:*}"
                        fi
+                       # always have SPECFILE ending with .spec extension
+                       SPECFILE=${SPECFILE%%.spec}.spec
                        ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
-                       shift
        esac
 done
 
-[ -d "$ASSUMED_NAME" ] && CVS_ENTRIES="$ASSUMED_NAME/CVS/Entries" || CVS_ENTRIES="CVS/Entries"
-if [ -f "$CVS_ENTRIES" ] && [ -z "$CVSTAG" ]; then
-       CVSTAG=$(awk -vSPECFILE=$(basename ${SPECFILE%.spec}.spec) -F/ '$2 == SPECFILE && $6 ~ /^T/{print substr($6, 2)}' ${CVS_ENTRIES})
-       if [ "$CVSTAG" ]; then
-               echo >&2 "builder: Sticky tag $CVSTAG active. Use -r TAGNAME to override."
+[ -d "$ASSUMED_NAME" ] && GIT_DIR="$ASSUMED_NAME/.git" || GIT_DIR=.git
+if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ]; then
+       if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
+               CVSTAG=${CVSTAG#refs/heads/}
+               if [ "$CVSTAG" != "master" ]; then
+                       echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
+               fi
+       else
+               echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
+               HEAD_DETACHED="yes"
        fi
 elif [ "$CVSTAG" = "HEAD" ]; then
        # assume -r HEAD is same as -A
-       CVSTAG=""
+       CVSTAG="master"
 fi
 
 if [ "$CVSTAG" ]; then
@@ -2262,151 +2313,184 @@ 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"
                ;;
-       "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
+       "show_avail_bconds")
                init_builder
-               if [ -n "$SPECFILE" ]; then
-                       # display SMP make flags if set
-                       smp_mflags=$(rpm -E %{?_smp_mflags})
-                       if [ "$smp_mflags" ]; then
-                               echo >&2 "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
-                       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
 
-                       # ./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
+               ;;
+       "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
+               init_builder
+               if [ -z "$SPECFILE" ]; then
+                       Exit_error err_no_spec_in_cmdl
+               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
+               # 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
 
-                       if [ -n "$NOSOURCE0" ] ; then
-                               SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
-                       fi
-                       get_files $SOURCES $PATCHES
-                       check_md5 $SOURCES
-                       build_package
-                       if [ "$UPDATE_POLDEK_INDEXES" = "yes" -a "$COMMAND" != "build-prep" ]; then
-                               run_poldek --sdir="${POLDEK_INDEX_DIR}" --mkidxz
+               # ./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..."
+                       git show-ref --quiet --verify "refs/tags/$TAGVER" && Exit_error err_tag_exists "$TAGVER" "$TAGREL"
+
+                       # - 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=$(git branch -r | grep -i "origin/$TAG_BRANCH$" | sed 's# *origin/##')
+                               if [ -n "$TAG_STATUS" -a -z "$CVSTAG" ]; then
+                                       Exit_error err_branch_exists "$TAG_STATUS"
+                               fi
                        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
+                               ;;
+               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
+               branch_files $TAG
                ;;
-       "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
                ;;
        "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
+               tag_files
                ;;
        "mr-proper" )
                mr_proper
This page took 0.16638 seconds and 4 git commands to generate.