#!/bin/bash # 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/>. # set -e for i in "${@:1}" do if [[ $i == -* ]] ; then case $i in -h=*|--help=*) HELP=YES ;; -e=*|--email=*) EMAIL="${i#*=}" ;; -f=*|--fullname=*) FULLNAME="${i#*=}" ;; -v=*|--version=*) export VERSION="${i#*=}" ;; -ne|--nodebenv) export NODEBENV=YES ;; -ns|--nosignature) export NOSIGNATURE=YES ;; -m|--merge) export MERGE=YES ;; -p|--patch) export PATCH=YES ;; -c|--continue) export CONTINUE=YES ;; -r=*|--release=*) export RELEASE="${i#*=}" ;; *) # unknown option ;; esac else export TARBALL=$i 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 "pidpbuild version 1.3.1" echo "" echo "usage: pidpbuild [<TARBALL>] [-v=<VERSION>] [-ns|--no-signature]" echo " [-e=<DEBEMAIL>] [-f=<DEBFULLNAME>] [-ne|--nodebenv]" echo " [-p|--patch] [-c|--continue] [-h|--help]" echo "" echo "build the new debian package (after running pidpclone):" echo " if TARBALL is present the new source is used" echo " if pidpclone --patch option was used the new patch is created" echo "" echo "possible arguments:" echo " TARBALL source tarball, i.e. *.tar.gz (optional)" echo "" echo "optional arguments:" echo " -h, --help show this help message and exit" echo " -v=, --version= new debian package version, i.e. 1.1.2-4" echo " -ns, --nosiganture don't sign the package" echo " -ne, --nodebenv don't set default DEBFULLNAME and DEBEMAIL" 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. jessie, wheezy" echo " -m, --merge upstream/* merged into debian/*" echo " by default: replace is performed" echo " -p, --patch the patching procedure" echo " -c, --continue continue the built of the debian package, e.g.:" echo " after a conflict detected between patches " echo " and the new source tarball or " echo " after creating a new repository " echo "" echo "examples:" echo " pidpbuild" echo " pidpbuild ../nexdatas.extrasp09-1.2.4.tar.gz" echo " pidpbuild --continue" echo " pidpbuild -v=1.3.2-4" echo "" else if [ -z $CONTINUE ] ; then CDIR=${PWD##*/} if ! [[ "$CDIR" == "$PACKAGE" ]] ; then cd $PACKAGE fi git clean -f -d 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 if [[ -z $RELEASE ]] ; then export RELEASE=$DEFRELEASE fi echo "" echo " DEBFULLNAME=\"$DEBFULLNAME\"" echo " DEBEMAIL=\"$DEBEMAIL\"" echo "" if [[ -z $VERSION ]] ; then RE='^[0-9]+$' read -r FIRSTLINE < debian/changelog ARR=($FIRSTLINE) VER=(${ARR[1]}) OLDVERSION=$(echo $VER | tr -d '()') # OLDVERSION=2016.10.12-0.2+deb8u1~fsec IFS='-' read -r SRCVERSION DEBVERSION <<< $OLDVERSION IFS='~' read -r PREVERSION VERSION3 <<< $DEBVERSION IFS='+' read -r VERSION1 VERSION2 <<< $PREVERSION IFS='.' read -r VERSION1A VERSION1B <<< $VERSION1 IFS='\n' if [[ -n $VERSION1B ]] ; then if [[ $VERSION1B =~ $RE ]] ; then VERSION1B=$((VERSION1B+1)) VERSION1=$VERSION1A.$VERSION1B else echo "ERROR: Wrong version number" >&2; exit 1 exit fi else if [[ $VERSION1A =~ $RE ]] ; then VERSION1A=$((VERSION1A+1)) VERSION1=$VERSION1A else echo "ERROR: Wrong version number" >&2; exit 1 fi fi NEWVERSION=$SRCVERSION-$VERSION1 if [[ -n $VERSION2 ]] ; then NEWVERSION=$NEWVERSION+$VERSION2 fi if [[ -n $VERSION3 ]] ; then NEWVERSION=$NEWVERSION+$VERSION3 fi fi if ! [[ -z $PATCH ]] ; then git commit -a -m 'fast fix' || true gbp pq export git add debian/patches || true if [[ $(git diff --cached --exit-code) && $? ]] ; then git commit fi gbp pq drop fi if ! [[ -z $TARBALL ]] ; then if [[ -d "debian/patches" ]] ; then if [[ "$(ls -A debian/patches)" ]] ; then gbp pq import git checkout debian/$RELEASE fi fi git clean -f -d if [[ -f $TARBALL ]] ; then if [[ -z $MERGE ]] ; then gbp import-orig "$TARBALL" --merge-mode=replace else gbp import-orig "$TARBALL" --merge-mode=merge fi else echo "Error: $TARBALL cannot be found" ; exit 1 fi if [[ -z $VERSION ]] ; then TB=${TARBALL::-7} VER=${TB##*-} NEWVERSION=${VER##*_}-1 fi echo "VERSION $NEWVERSION" fi if ! [[ -z $NEWVERSION ]] ; then VERSION=$NEWVERSION fi gbp dch -R -N $VERSION git commit -a -m "update changelog" git clean -f -d if ! [[ -z $TARBALL ]] ; then if [[ -d "debian/patches" ]] ; then if [[ "$(ls -A debian/patches)" ]] ; then set +e gbp pq rebase if [[ ! $? -eq 0 ]]; then echo "" echo "Conflict between tarball and patches" echo "1) Correct the source files or/and patches" echo "2) Stage your changes, i.e. with git add ..." echo "3) Execute \"pidpbuild --continue\"" exit 1 fi set -e gbp pq export git add debian/patches if [[ $(git diff --cached --exit-code) && $? ]] ; then git commit fi fi fi fi else if [[ -d "debian/patches" ]] ; then if [[ "$(ls -A debian/patches)" ]] ; then git rebase --continue if ! [[ $? -eq 0 ]]; then echo "Conflict between tarball and patches" echo "1) Correct the source files or/and patches" echo "2) Stage your changes, i.e. with git add ..." echo "3) Execute \"pidpbuild --continue\"" exit 1 fi gbp pq export git add debian/patches || true if [[ $(git diff --cached --exit-code) && $? ]] ; then git commit fi fi fi fi git clean -f -d if [[ -z $NOSIGNATURE ]] ; then gbp buildpackage --git-tag else gbp buildpackage -us -uc --git-tag fi if [[ ! -z $PIDTOKILL ]] ; then (sleep 1 && kill -TERM $PPID $PIDTOKILL &) fi fi