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#*=}"
;;
--hdri)
export HDRI=YES
;;
--othermirror=*)
export MYOTHERMIRROR="${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 " --hdri add the HDRI repository to the othermirror parameter"
echo " --othermirror= add a repository to the othermirror parameter"
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 $RELEASE ]] ; then
export TRRELEASE=$DEFRELEASE
else
if [[ "$RELEASE" == *-backports ]] ; then
export TRRELEASE=${RELEASE: : -10}
else
export TRRELEASE=$RELEASE
fi
fi
if ! [[ -z $HDRI ]] ; then
if [[ -z $MYOTHERMIRROR ]] ; then
MYOTHERMIRROR="deb http://repos.pni-hdri.de/apt/debian $TRRELEASE main"
else
MYOTHERMIRROR=$MYOTHERMIRROR" | deb http://repos.pni-hdri.de/apt/debian $TRRELEASE main"
fi
fi
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"
if [[ -z $DEBFULLNAME ]] ; then
export DEBFULLNAME="FS-EC DESY Group"
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 $PBUILDER ]] ; then
if [[ -z $MYOTHERMIRROR ]] ; then
if [[ -z $CREATEPB ]] ; then
if [[ -z $ARCH ]] ; then
DIST=$RELEASE git-pbuilder update
else
ARCH=$ARCH DIST=$RELEASE git-pbuilder update
fi
else
if [[ -z $ARCH ]] ; then
DIST=$RELEASE git-pbuilder create
ARCH=$ARCH DIST=$RELEASE git-pbuilder create
fi
fi
else
if [[ -z $CREATEPB ]] ; then
if [[ -z $ARCH ]] ; then
DIST=$RELEASE git-pbuilder update --othermirror="$MYOTHERMIRROR"
else
ARCH=$ARCH DIST=$RELEASE git-pbuilder update --othermirror="$MYOTHERMIRROR"
if [[ -z $ARCH ]] ; then
DIST=$RELEASE git-pbuilder create --othermirror="$MYOTHERMIRROR"
ARCH=$ARCH DIST=$RELEASE git-pbuilder create --othermirror="$MYOTHERMIRROR"
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
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
if [[ -z $ARCH ]] ; then
gbp buildpackage --git-tag --git-pbuilder --git-dist=$RELEASE
else
gbp buildpackage --git-tag --git-pbuilder --git-dist=$RELEASE --git-arch=$ARCH
fi
if [[ -z $PBUILDER ]] ; then
gbp buildpackage -us -uc --git-tag
else
if [[ -z $ARCH ]] ; then
gbp buildpackage --git-tag --git-pbuilder --git-dist=$RELEASE
else
gbp buildpackage --git-tag --git-pbuilder --git-dist=$RELEASE --git-arch=$ARCH
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 &)