Skip to content
Snippets Groups Projects
pidpclone 6.91 KiB
Newer Older
#!/bin/bash -e
#   This file is part of nexdatas - Tango Server for NeXus data writer
#
#    Copyright (C) 2017-2017 DESY, Jan Kotanski <jkotan@mail.desy.de>
#
#    nexdatas is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    nexdatas is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with nexdatas.  If not, see <http://www.gnu.org/licenses/>.
#
PIDPVERSION="1.6.1"
for i in "${@:1}"
do
    if [[ $i == -* ]] ; then
	case $i in
	    -h*|--help*)
		HELP=YES
		;;
	    -e=*|--email=*)
		EMAIL="${i#*=}"
		;;
	    -f=*|--fullname=*)
		FULLNAME="${i#*=}"
		;;
	    -u=*|--user=*)
		export USER="${i#*=}"
		;;
	    -r=*|--release=*)
		export RELEASE="${i#*=}"
		;;
	    -t=*|--template=*)
		export TEMPRELEASE="${i#*=}"
		;;
	    -g=*|--giturl=*)
		export GITURL="${i#*=}"
		;;
	    -ne|--nodebenv)
		export NODEBENV=YES
		;;
	    -nb|--nonewbash)
		export NONEWBASH=YES
		;;
	    -np|--nopull)
		export NOPULL=YES
		;;
	    -p|--patch)
		export PATCH=YES
		;;
	    *)
		# unknown option
		;;
	esac
    else
	export PACKAGE=$1
    fi
done

DEFRELEASE=jessie

if [[ ! -z $HELP ]] && [[ -z $PACKAGE ]] ; then
    echo "Error: PACKAGE variable is not defined"
fi
if [[ ! -z $HELP ]] || [[ -z $PACKAGE  ]] ; then
    echo "pidpclone version $PIDPVERSION"
    echo ""
    echo "usage: pidpclone <DEB-PACKAGE-NAME> [-p|--patch] [-u=<USER>] [-h|--help]"
    echo "                  [-e=<DEBEMAIL>] [-f=<DEBFULLNAME>] [-ne|--nodebenv] "
    echo ""
    echo "clone the gbp package repository from stash into the local directory"
    echo "and start the patching procedure if the --patch option is given"
    echo "(see also pidpbuild)"
    echo ""
    echo "possible arguments:"
    echo "  DEB-PACKAGE-NAME      debian package name (mandatory)"
    echo ""
    echo "optional arguments:"
    echo "  -h, --help            show this help message and exit"
    echo "  -p, --patch           start the patching procedure"
    echo "  -u=, --user=          stash user name"
    echo "                          (default: the local user name)"
    echo "  -ne, --nodebenv       don't set default DEBFULLNAME and DEBEMAIL"
    echo "  -nb, --nonewbash      don't open a new bash in the package directory"
    echo "  -np, --nopull         don't pull from the repository"
    echo "  -f=, --fullname=      debian fullname of the gpg signature,"
    echo "                          i.e. DEBFULLNAME"
    echo "  -e=, --email=         debian email of the gpg signature,"
    echo "                          i.e.  DEBEMAIL"
    echo "  -r=, --release=       debian release flavour, e.g. stretch, jessie, wheezy"
    echo "  -t=, --template=      copy branches from template release to new flavour"
    echo "  -g=, --giturl=        repository url, default:"
    echo "                          https://$USER@stash.desy.de/scm/pidp/$PACKAGE.git"
    echo ""
    echo "examples:"
    echo "  pidpclone python-nxstools-extras-p09 --patch"
    echo "  pidpclone python-nxstools-extras-p06"
    echo ""
else
    if [ -z $NODEBENV ] ; then
	if [[ -z $DEBEMAIL ]] ; then
            export DEBEMAIL="fsec-devel@desy.de"
	fi
	if [[ -z $DEBFULLNAME ]] ; then
            export DEBFULLNAME="FS-EC DESY Group"
	fi
    fi
    if [[ ! -z $FULLNAME ]] ; then
        export DEBFULLNAME=$FULLNAME
    fi
    if [[ ! -z $EMAIL ]] ; then
        export DEBEMAIL=$EMAIL
    fi
    echo ""
    echo "  DEBFULLNAME=\"$DEBFULLNAME\""
    echo "  DEBEMAIL=\"$DEBEMAIL\""
    echo ""
    if [ -z $USER ] ; then
	export USER=$(whoami)
    fi
    if [ -z $RELEASE ] ; then
	export RELEASE=$DEFRELEASE
    fi
    if [[ -z $GITURL ]] ; then
        export GITURL="https://$USER@stash.desy.de/scm/pidp/$PACKAGE.git"
    fi
    if ! [[ -d $PACKAGE ]]; then
	git clone $GITURL
    cd $PACKAGE
    if [[ -z $NOPULL ]] ; then
	git fetch --all
    fi
    if ! [[ -z $TEMPRELEASE ]] ; then
	echo "TEMPLATE RELEASE: $TEMPRELEASE"
	set +e
	git checkout -b upstream/$TEMPRELEASE origin/upstream/$TEMPRELEASE 2> /dev/null
	set -e
	git checkout upstream/$TEMPRELEASE
	if [[ -z $NOPULL ]] ; then
	    git pull origin upstream/$TEMPRELEASE
	git checkout -b upstream/$RELEASE
	TEMPTAGS=(`git tag | grep upstream/$TEMPRELEASE`)
	#	echo "TAGS: $TEMPTAGS"
	for ((i=0; i<${#TEMPTAGS[@]}; i++)); do
            OLDTAG="${TEMPTAGS[$i]}"
	    IFS='' read -r PRETAG POSTTAG <<< $OLDTAG
            NEWTAG="upstream/${RELEASE}${OLDTAG#upstream/${TEMPRELEASE}}"
            echo "$OLDTAG => $NEWTAG"
            git tag $NEWTAG $OLDTAG
	done
	# git config branch.upstream/$RELEASE.remote origin
	# git config branch.upstream/$RELEASE.merge refs/heads/upstream/$RELEASE
	set +e
	git checkout -b pristine-tar origin/pristine-tar  2> /dev/null
	set -e
	git checkout pristine-tar
	if [[ -z $NOPULL ]] ; then
	    git pull origin pristine-tar
	set +e
	git checkout -b debian/$TEMPRELEASE origin/debian/$TEMPRELEASE  2> /dev/null
	set -e
	git checkout debian/$TEMPRELEASE
	if [[ -z $NOPULL ]] ; then
	    git pull origin debian/$TEMPRELEASE
	git checkout -b debian/$RELEASE
	TEMPTAGS=(`git tag | grep debian/$TEMPRELEASE`)
	#	echo "TAGS: $TEMPTAGS"
	for ((i=0; i<${#TEMPTAGS[@]}; i++)); do
            OLDTAG="${TEMPTAGS[$i]}"
            NEWTAG="debian/${RELEASE}${OLDTAG#debian/${TEMPRELEASE}}"
            echo "$OLDTAG => $NEWTAG"
            git tag $NEWTAG $OLDTAG
	done
	# git config branch.debian/$RELEASE.remote origin
	# git config branch.debian/$RELEASE.merge refs/heads/debian/$RELEASE
    else
	set +e
	git checkout -b upstream/$RELEASE origin/upstream/$RELEASE  2> /dev/null
	set -e
	git checkout upstream/$RELEASE
	if [[ -z $NOPULL ]] ; then
	    git pull origin upstream/$RELEASE
	set +e
	git checkout -b pristine-tar origin/pristine-tar  2> /dev/null
	set -e
	git checkout pristine-tar
	if [[ -z $NOPULL ]] ; then
	    git pull origin pristine-tar
	set +e
	git checkout -b debian/$RELEASE origin/debian/$RELEASE  2> /dev/null
	set -e
	git checkout debian/$RELEASE
	if [[ -z $NOPULL ]] ; then
	    git pull origin debian/$RELEASE
    fi
    git clean -f -d
    if ! [[ -z $TEMPRELEASE ]] ; then
	MSTR="s/${TEMPRELEASE}/${RELEASE}/g"
	sed -i $MSTR debian/gbp.conf
    fi
    git commit -a -m 'clean the repository' > /dev/null 2>&1 || true
    export PIDTOKILL=$$
    if [ -z $PATCH ] ; then
	echo ""
	echo "1) Edit the debian/ configuration"
	echo "2) Commit your changes"
	echo "3) Execute \"pidpbuild\""
    else
	gbp pq import
	export IMPORT=YES
	export PIDTOKILL=$$
	echo ""
	echo "1) Edit the source files"
	echo "2) Commit your changes"
	echo "3) Execute \"pidpbuild\""
    if [[ -z $NONEWBASH ]] ; then
	exec bash
    fi