Newer
Older
#!/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/>.
#
for i in "${@:1}"
do
if [[ $i == -* ]] ; then
case $i in
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
;;
-pb|--pbuilder)
export PBUILDER=YES
;;
-cpb|--createpb)
export CREATEPB=YES
;;
-a=*|--arch=*)
export ARCH="${i#*=}"
;;
-r=*|--release=*)
export RELEASE="${i#*=}"
;;
*)
# unknown option
;;
esac
else
export TARBALL=$i
fi
done
if [[ ! -z $HELP ]] && [[ -z $PACKAGE ]] ; then
echo "Error: PACKAGE variable is not defined"
fi
if [[ ! -z $HELP ]] || [[ -z $PACKAGE ]] ; then
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. stretch, jessie, wheezy"
echo " -m, --merge upstream/* merged into debian/*"
echo " by default: replace is performed"
echo " -p, --patch the patching procedure"
echo " -pb, --pbuilder use gbp pbuilder"
echo " -cpb, --createpb create gbp pbuilder environment"
echo " -a=, --arch= git-pbuilder architecture"
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 -v=1.3.2-4"
echo ""
else
if [ -z $CONTINUE ] ; then
CDIR=${PWD##*/}
if ! [[ "$CDIR" == "$PACKAGE" ]] ; then
cd $PACKAGE
git clean -f -d
if [ -z $NODEBENV ] ; then
if [[ -z $DEBEMAIL ]] ; then
export DEBEMAIL="fsec-devel@desy.de"
if [[ ! -z $FULLNAME ]] ; then
export DEBFULLNAME=$FULLNAME
if [[ ! -z $EMAIL ]] ; then
export DEBEMAIL=$EMAIL
if [[ -z $RELEASE ]] ; then
export RELEASE=$DEFRELEASE
echo ""
echo " DEBFULLNAME=\"$DEBFULLNAME\""
echo " DEBEMAIL=\"$DEBEMAIL\""
echo ""
if [[ -z $CREATEPB ]] ; then
DIST=$RELEASE git-pbuilder update
else
DIST=$RELEASE git-pbuilder create
fi
fi
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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
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
GBPV=$(gbp --version)
IFS=' ' read -r GBPNAME GBPVERSION <<< $GBPV
IFS='.' read -r VMAJ VMIN VPATCH <<< $GBPVERSION
if [[ "$VMAJ" -eq "0" ]] && [[ "$VMIN" -lt "8" ]] ; then
else
if [[ -z $MERGE ]] ; then
gbp import-orig "$TARBALL" --merge-mode=replace
else
gbp import-orig "$TARBALL" --merge-mode=merge
fi
echo "Error: $TARBALL cannot be found" ; exit 1
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
if [[ $TARBALL == *".orig.tar.gz" ]]; then
TB=${TARBALL::-12}
elif [[ $TARBALL == *".tar.gz" ]]; then
TB=${TARBALL::-7}
elif [[ $TARBALL == *".orig.tgz" ]]; then
TB=${TARBALL::-9}
elif [[ $TARBALL == *".tgz" ]]; then
TB=${TARBALL::-4}
elif [[ $TARBALL == *".orig.tar.lzma" ]]; then
TB=${TARBALL::-14}
elif [[ $TARBALL == *".tar.lzma" ]]; then
TB=${TARBALL::-9}
elif [[ $TARBALL == *".orig.tbz2" ]]; then
TB=${TARBALL::-10}
elif [[ $TARBALL == *".tbz2" ]]; then
TB=${TARBALL::-5}
elif [[ $TARBALL == *".orig.tbz" ]]; then
TB=${TARBALL::-10}
elif [[ $TARBALL == *".tbz" ]]; then
TB=${TARBALL::-5}
elif [[ $TARBALL == *".orig.shar.gz" ]]; then
TB=${TARBALL::-13}
elif [[ $TARBALL == *".shar.gz" ]]; then
TB=${TARBALL::-8}
elif [[ $TARBALL == *".orig.tar.bz2" ]]; then
TB=${TARBALL::-13}
elif [[ $TARBALL == *".tar.bz2" ]]; then
TB=${TARBALL::-8}
elif [[ $TARBALL == *".orig.tar.bz" ]]; then
TB=${TARBALL::-12}
elif [[ $TARBALL == *".tar.bz" ]]; then
TB=${TARBALL::-7}
elif [[ $TARBALL == *".orig.tar.xz" ]]; then
TB=${TARBALL::-12}
elif [[ $TARBALL == *".tar.xz" ]]; then
TB=${TARBALL::-7}
elif [[ $TARBALL == *".orig.cpio.gz" ]]; then
TB=${TARBALL::-13}
elif [[ $TARBALL == *".cpio.gz" ]]; then
TB=${TARBALL::-8}
else
TB=${TARBALL::-7}
fi
if [[ -n $VERSION1B ]] ; then
VERSION1=0.1
else
VERSION1=1
fi
SRCVERSION=${VER##*_}
NEWVERSION=$SRCVERSION-$VERSION1
if [[ -n $VERSION2 ]] ; then
NEWVERSION=$NEWVERSION+$VERSION2
fi
if [[ -n $VERSION3 ]] ; then
NEWVERSION=$NEWVERSION~$VERSION3
fi
if ! [[ -z $NEWVERSION ]] ; then
VERSION=$NEWVERSION
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
if [[ $MGITFILES == *"rebase"* ]]; 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
if [[ -z $PBUILDER ]] ; then
gbp buildpackage --git-tag
else
gbp buildpackage --git-tag --git-pbuilder --git-dist=$RELEASE
lintian
debsign
fi
if [[ -z $PBUILDER ]] ; then
gbp buildpackage -us -uc --git-tag
else
gbp buildpackage --git-tag --git-pbuilder --git-dist=$RELEASE
lintian
fi
if [[ -z $VERSION ]] ; then
read -r FIRSTLINE < debian/changelog
ARR=($FIRSTLINE)
VER=(${ARR[1]})
VERSION=$(echo $VER | tr -d '()')
fi
PTAGNAME=debian/$RELEASE/$VERSION
TAGNAME=${PTAGNAME/\~/_}
echo "resetting to: $TAGNAME"
git reset --hard "$TAGNAME"
(sleep 1 && kill -TERM $PPID $PIDTOKILL > /dev/null 2>&1 &)