]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
Exit with error when cannot push tags
[packages/rpm-build-tools.git] / builder.sh
index 62081db19ce6a967ba98f8cc744fc0c87fb8e501..fbdecf8f44ba827ef44f45c928b87b5a72f625d9 100755 (executable)
@@ -63,7 +63,6 @@ UPDATE=""
 ADD5=""
 NO5=""
 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
-CVSROOT=""
 
 # use rpm 4.4.6+ digest format instead of comments if non-zero
 USEDIGEST=
@@ -107,15 +106,14 @@ ASSUMED_NAME=""
 PROTOCOL="http"
 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
 
-CVS_COMMAND=${CVS_COMMAND:-cvs}
 CVS_FORCE=""
 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=""
+REMOTE_PLD="origin"
+NEW_REPO=""
 
 RES_FILE=""
 
@@ -176,6 +174,10 @@ fi
 
 [ -f "$USER_CFG" ] && . "$USER_CFG"
 
+if [ -n "$GIT_LOGINNAME" ]; then
+       GIT_SERVER="git@github.com:${GIT_LOGINNAME}"
+fi
+
 if [ "$SCHEDTOOL" = "auto" ]; then
        if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
                SCHEDTOOL="schedtool -B -e"
@@ -247,16 +249,16 @@ run_poldek() {
 usage() {
        if [ -n "$DEBUG" ]; then set -xv; fi
        echo "\
-Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--add_cvs] [-b|-ba|--build]
+Usage: builder [-D|--debug] [-V|--version] [--short-version]  [-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>] [--depth <number>]
+[{-cf|--cvs-force}] [{-B|--branch} <branch>] [--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>]
+[-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
 [{-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]
+<package>[.spec][:tag]
 
 -5, --update-md5    - update md5 comments in spec, implies -nd -ncs
 -a5, --add-md5      - add md5 comments to URL sources, implies -nc -nd -ncs
@@ -265,28 +267,25 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 -debug              - produce rpm debug package (same as --opts -debug)
 -V, --version       - output builder version string
 --short-version     - output builder short version
---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
+-a, --add_vcs       - try add new package to PLD repo.
+-b, -ba, --build    - get all files from PLD 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
+-bb, --build-binary - get all files from PLD repo or HTTP/FTP and build binary
                       only package from <package>.spec,
 -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
--bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
+-bs, --build-source - get all files from PLD 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
+                                         SPECS and \$RPM_BUILD_ROOT). Doesn't run
                                          any rpm building.
--cf, --cvs-force       - use -F when tagging (useful when moving branches)
--d <cvsroot>, --cvsroot <cvsroot>
-                    - setup \$CVSROOT,
+-cf, --cvs-force       - use -f when tagging
 --define <macro> <value>
                     - define a macro <macro> with value <value>,
 --depth <number>
@@ -294,7 +293,7 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 --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
+-g, --get           - get <package>.spec and all related files from PLD repo
                       or HTTP/FTP,
 -h, --help          - this message,
 -jN, -j N           - set %_smp_mflags to propagate concurrent jobs
@@ -302,7 +301,7 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 -l <logfile>, --logtofile <logfile>
                     - log all to file,
 -ncs, --no-cvs-specs
-                    - don't check specs in CVS
+                    - don't pull from PLD repo
 -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,
@@ -315,10 +314,10 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 --skip-existing-files - skip existing files in get_files
 --opts <rpm opts>   - additional options for rpm
 -q, --quiet         - be quiet,
---date yyyy-mm-dd   - build package using resources from specified CVS date,
--r <cvstag>, --cvstag <cvstag>
-                    - build package using resources from specified CVS tag,
--A                  - build package using CVS resources as any sticky tags/date/kopts being reset.
+--date yyyy-mm-dd   - build package using resources from specified date,
+-r <tag>, --cvstag <ref>
+                    - build package using resources from specified branch/tag,
+-A                  - build package using master branch as any sticky tags/branch/date being reset.
 -R, --fetch-build-requires
                     - fetch what is BuildRequired,
 -RB, --remove-build-requires
@@ -330,7 +329,7 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
 -sd, --source-distfiles - list sources available from distfiles (intended for offline
                       operations; does not work when Icon field is present
                       but icon file is absent),
--sc, --source-cvs - list sources available from CVS
+-sc, --source-cvs - list sources available from PLD repo
 -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
@@ -343,14 +342,14 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--a
                       but icon file is absent),
 -su, --source-urls  - list urls - urls to sources and patches
                       intended for copying urls with spec with lots of macros in urls
--T <cvstag> , --tag <cvstag>
-                    - add cvs tag <cvstag> for files,
+-T <tag> , --tag <tag>
+                    - add git tag <tag> for files,
 -Tvs, --tag-version-stable
-                    - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
+                    - add git tags STABLE and NAME-VERSION-RELEASE for files,
 -Ts, --tag-stable
-                    - add cvs tag STABLE for files,
+                    - add git tag STABLE for files,
 -Tv, --tag-version
-                    - add cvs tag NAME-VERSION-RELEASE for files,
+                    - add git tag NAME-VERSION-RELEASE for files,
 -Tp, --tag-prefix <prefix>
                     - add <prefix> to NAME-VERSION-RELEASE tags,
 -tt, --test-tag <prefix>
@@ -674,14 +673,14 @@ Exit_error() {
                        exit 2 ;;
                "err_no_spec_in_repo" )
                        remove_build_requires
-                       echo >&2 "Error: spec file not stored in CVS repo."
+                       echo >&2 "Error: spec file not stored in PLD repo."
                        exit 3 ;;
                "err_no_source_in_repo" )
                        remove_build_requires
-                       echo >&2 "Error: some source, patch or icon files not stored in CVS repo. ($2)"
+                       echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
                        exit 4 ;;
                "err_cvs_add_failed" )
-                       echo >&2 "Error: failed to add package to CVS repo."
+                       echo >&2 "Error: failed to add package to PLD repo."
                        exit 4 ;;
                "err_build_fail" )
                        remove_build_requires
@@ -707,6 +706,10 @@ Exit_error() {
                        remove_build_requires
                        echo >&2 "Error: conditions reject building this spec (${2})."
                        exit 12 ;;
+               "err_remote_problem" )
+                       remove_build_requires
+                       echo >&2 "Error: problem with remote (${2})"
+                       exit 13 ;;
                "err_not_implemented" )
                        remove_build_requires
                        echo >&2 "Error: functionality not yet imlemented"
@@ -747,6 +750,26 @@ init_builder() {
        __PWD=$(pwd)
 }
 
+create_git_repo() {
+       update_shell_title "add_package"
+
+       if [ -n "$DEBUG" ]; then
+               set -x
+               set -v
+       fi
+
+       cd "$REPO_DIR"
+       SPECFILE=$(basename $SPECFILE)
+       if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
+               echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
+               exit 101
+       fi
+       [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
+       pldpkg.py add ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
+       git init
+       git remote add $REMOTE_PLD ${GIT_SERVER}/${ASSUMED_NAME}.git || Exit_error err_remote_problem $REMOTE_PLD
+}
+
 get_spec() {
 
        update_shell_title "get_spec"
@@ -765,7 +788,7 @@ get_spec() {
        if [ "$NOCVSSPEC" != "yes" ]; then
                if [ -z "$DEPTH" ]; then
                        if [ -d "$ASSUMED_NAME/.git" ]; then
-                               git fetch origin || Exit_error err_no_spec_in_repo
+                               git fetch $REMOTE_PLD || 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
@@ -775,8 +798,8 @@ get_spec() {
                        else
                                (
                                        unset GIT_WORK_TREE
-                                       git clone  ${GIT_SERVER}/${ASSUMED_NAME}.git || {
-                                               # softfail if new package, i.e not yet added to cvs
+                                       git clone  -o $REMOTE_PLD ${GIT_SERVER}/${ASSUMED_NAME}.git || {
+                                               # softfail if new package, i.e not yet added to PLD rep
                                                [ ! -f "$ASSUMED_NAME/$SPECFILE" ] && Exit_error err_no_spec_in_repo
                                                echo "Warning: package not in CVS - assuming new package"
                                                NOCVSSPEC="yes"
@@ -789,9 +812,10 @@ get_spec() {
                                        mkdir $ASSUMED_NAME
                                fi
                                git init
-                               git remote add origin ${GIT_SERVER}/${ASSUMED_NAME}.git
+                               git remote add $REMOTE_PLD ${GIT_SERVER}/${ASSUMED_NAME}.git
+                               CVSTAG=${CVSTAG:-"master"}
                        fi
-                       git fetch "$DEPTH" origin ${CVSTAG}:remotes/origin/${CVSTAG} || {
+                       git fetch $DEPTH $REMOTE_PLD ${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG} || {
                                echo >&2 "Error: branch $CVSTAG does not exist"
                                exit 3
                        }
@@ -799,7 +823,7 @@ get_spec() {
 
                cvsignore_df .gitignore
 
-               # add default log format to .cvsignore if it is relative to package dir
+               # add default log format to .gitignore 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')
@@ -810,7 +834,7 @@ get_spec() {
 
                # create symlinks for tools
                if [ "$SYMLINK_TOOLS" != "no" ]; then
-                       for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
+                       for a in dropin md5 adapter builder {relup,compile,repackage,pearize}.sh pldnotify.awk; do
                                [ -f $a ] || continue
                                ln -sf ../$a $ASSUMED_NAME
                                cvsignore_df $a
@@ -819,7 +843,7 @@ get_spec() {
        fi
 
        if [ -n "$CVSTAG" ]; then
-               git checkout "$CVSTAG" -- 2>/dev/null || git checkout -t "origin/$CVSTAG" > /dev/null || exit
+               git checkout "$CVSTAG" -- 2>/dev/null || git checkout -t "${REMOTE_PLD}/$CVSTAG" > /dev/null || exit
                git symbolic-ref -q HEAD > /dev/null &&
                        git merge '@{u}'
                if [ -n "$CVSDATE" ]; then
@@ -843,8 +867,8 @@ get_spec() {
 find_mirror() {
        cd "$REPO_DIR"
        local url="$1"
-       if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
-               $CVS_COMMAND update mirrors >&2
+       if [ ! -f "mirrors"  ] ; then
+               ln -s rpm-build-tools/mirrors .
        fi
 
        IFS="|"
@@ -1273,10 +1297,12 @@ tag_files() {
        if [ "$TAG_VERSION" = "yes" ]; then
                update_shell_title "tag sources: $TAGVER"
                git $OPTIONS $TAGVER || exit
+               git push $CVS_FORCE $REMOTE_PLD tag $TAGVER || Exit_error err_remote_problem $REMOTE_PLD
        fi
        if [ -n "$TAG" ]; then
                update_shell_title "tag sources: $TAG"
                git $OPTIONS $TAG $chunk || exit
+               git push $CVS_FORCE $REMOTE_PLD tag $TAG || Exit_error err_remote_problem $REMOTE_PLD
        fi
 }
 
@@ -1670,10 +1696,8 @@ display_bconds() {
 }
 
 display_branches() {
-       if [ "$NOCVSSPEC" != "yes" ]; then
-               echo -n "Available branches: "
-               git branch -r | grep '^  origin' | grep -v origin/HEAD | sed 's#^ *origin/##' | xargs
-       fi
+       echo -n "Available branches: "
+       git branch -r | grep "^  ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
 }
 
 # checks a given list of packages/files/provides agains current rpmdb.
@@ -1918,43 +1942,25 @@ init_rpm_dir() {
        local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
        local tmp
 
-       echo "Initializing rpm directories to $TOP_DIR from $CVSROOT"
+       echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
        mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
 
-       GIT_WORK_TREE=${TOP_DIR}/rpm-build-tools git clone  ${GIT_SERVER}/rpm-build-tools.git || 
-       for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
+       cd "$TOP_DIR"
+       git clone  ${GIT_SERVER}/rpm-build-tools.git ${TOP_DIR}/rpm-build-tools
+       for a in dropin md5 adapter builder mirrors {relup,compile,repackage,pearize}.sh pldnotify.awk; do
                ln -s rpm-build-tools/$a .
        done
        init_builder
 }
 
-# remove entries from CVS/Entries
-cvs_entry_remove() {
-       local cvsdir="$1"; shift
-       if [ ! -d "$cvsdir" ]; then
-               echo >&2 "cvs_entry_remove: $cvsdir is not a directory"
-               exit 1
-       fi
-
-       for file in "$@"; do
-               rm -f $cvsdir/CVS/Entries.new || return 1
-               awk -ve="${file##*/}" -F/ '$2 != e {print}' $cvsdir/CVS/Entries > $cvsdir/CVS/Entries.new || return 1
-               mv -f $cvsdir/CVS/Entries.new $cvsdir/CVS/Entries || return 1
-       done
-       return 0
-}
-
 mr_proper() {
        init_builder
        NOCVSSPEC="yes"
        DONT_PRINT_REVISION="yes"
-       get_spec
-       parse_spec
 
        # 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" $PACKAGE_DIR/$SPECFILE
        rm -rf $PACKAGE_DIR/.git .gitignore
-       cd $__PWD
        rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
 }
 
@@ -1988,8 +1994,6 @@ while [ $# -gt 0 ]; do
                        COMMAND="version"; shift ;;
                --short-version )
                        COMMAND="short-version"; shift ;;
-               --as_anon )
-                       CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
                -a | --add_cvs)
                        COMMAND="add_cvs";
                        shift ;;
@@ -2013,8 +2017,6 @@ while [ $# -gt 0 ]; do
                        CLEAN="--clean"; shift ;;
                -cf | --cvs-force )
                        CVS_FORCE="-f"; shift;;
-               -d | --cvsroot )
-                       shift; CVSROOT="${1}"; shift ;;
                --depth )
                        DEPTH="--depth=$2"
                        shift 2
@@ -2377,14 +2379,14 @@ case "$COMMAND" in
                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"
+                       git show-ref --quiet --verify "refs/tags/$TAGVER" && Exit_error err_tag_exists "$TAGVER"
 
                        # - 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
+                               TAG_STATUS=$(git branch -r | grep -i "${REMOTE_PLD}/$TAG_BRANCH$" | sed "s# *${REMOTE_PLD}/##")
+                               if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != "$CVSTAG" ]; then
                                        Exit_error err_branch_exists "$TAG_STATUS"
                                fi
                        fi
@@ -2427,14 +2429,23 @@ case "$COMMAND" in
                        Exit_error err_no_spec_in_cmdl
                fi
 
-               ADD_PACKAGE_CVS=yes get_spec
-               parse_spec
-
-               if [ -n "$NOSOURCE0" ] ; then
-                       SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
+               create_git_repo
+               if [ -n "$NEW_REPO" ]; then
+                       parse_spec
+                       local file
+                       for file in $SOURCES $PATCHES; do
+                               if [ -z $(src_md5 "$file") ]; then
+                                       git add $file || Exit_error err_no_source_in_repo $file
+                               else
+                                       cvsignore_df `nourl $file`
+                               fi
+                       done
+                       git add $SPECFILE
+                       git commit -m 'Initial commit'
+                       git push --dry-run $REMOTE_PLD master || Exit_error err_cvs_add_failed
+               else
+                       echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
                fi
-               get_files $SOURCES $PATCHES
-               check_md5 $SOURCES
                ;;
        "get" )
                init_builder
This page took 0.089593 seconds and 4 git commands to generate.