1#!/bin/bash
2
3test -z "$DEBFULLNAME" && export DEBFULLNAME="Alexander Pozdnyakov"
4test -z "$DEBEMAIL" && export DEBEMAIL="kvircbot@gmail.com"
5
6#export DEBEMAIL="kvircbot@gmail.com"
7#export GPGPASS=secret
8#export AESPASS=secret
9
10bin_debuild=$(which debuild 2>/dev/null)
11
12while getopts "p" Option
13do
14    case $Option in
15        p) PPA=1 ;;
16    esac
17done
18shift $((OPTIND - 1))
19
20if [ ! -x "$bin_debuild" ]
21then
22    echo "Please install debuild (package devscripts)."
23    exit 1
24fi
25
26DIR=$(pwd)
27BUILDDIR="${DIR}/build"
28cd .. && GITDIR=$(pwd)
29PKG_NAME=kvirc
30SVNGITBZR="~git-"
31VERSION='4:5.0.1'
32VERSION1='5.0.1'
33TMPFILE=$(mktemp)
34TMPGPG=$(mktemp)
35DIST_PPA="xenial bionic cosmic"
36PPANAME=kvirc
37
38dchppa_pkg(){
39NEW_VER=$(dpkg-parsechangelog | awk '/^Version: / {print $2}')
40cd "$BUILDDIR/${PKG_NAME}-${VERSION1}${SVNGITBZR}${dat}/" || exit 1
41cp -f debian/changelog "${TMPFILE}"
42for i in ${DIST_PPA}
43do
44cp -f "${TMPFILE}" debian/changelog
45dch -b --force-distribution --distribution "$i" -v "${NEW_VER}ppa1~${i}1" \
46  "Automated backport upload; no source changes."
47echo "$SOURCEUP" | grep -q YES && debuild --no-lintian -p"gpg --passphrase-file $TMPGPG --batch --no-use-agent" -S -sa
48echo "$SOURCEUP" | grep -q YES || debuild --no-lintian -p"gpg --passphrase-file $TMPGPG --batch --no-use-agent" -S -sd
49SOURCEUP=YES
50done
51unset SOURCEUP
52for i in ${DIST_PPA}
53do
54dput "${PPANAME}" "../${PKG_NAME}_*${i}1_source.changes"
55sleep 10
56done
57cp -f "${TMPFILE}" debian/changelog
58}
59
60dputcf(){
61cat > ~/.dput.cf << EOF
62[kvirc]
63fqdn = ppa.launchpad.net
64method = ftp
65incoming = ~kvirc/kvirc/ubuntu/
66login = anonymous
67allow_unsigned_uploads = 0
68
69EOF
70}
71
72tmpgpg(){
73cat > "$TMPGPG" << EOF
74$GPGPASS
75EOF
76}
77gpgkey(){
78openssl enc -d -aes-256-cbc -in "${DIR}/secret.enc" -out "${DIR}/secret.gpg" -k "${AESPASS}"
79gpg --import "${DIR}/public.gpg"
80gpg --allow-secret-key-import --import "${DIR}/secret.gpg"
81}
82
83test -d "$BUILDDIR" && rm -rf "${BUILDDIR}"
84mkdir -p "$BUILDDIR"
85cd "$GITDIR" || exit 1
86abbrevcommit=$(git log -1 --abbrev-commit | grep -i "^commit" | awk '{print $2}')
87numcommit=$(git log | grep -c "^Date:")
88dat="${numcommit}-${abbrevcommit}"
89#dat=$(git describe --dirty)
90branch=$(git branch | grep "\*" | sed 's/\* //g')
91commit=$(git log -1 | grep -i "^commit" | awk '{print $2}')
92datct=$(git log -n 1 --format=%ct)
93
94test -z "${dat}" && dat="git-99999-$(git describe --always)"
95test -z "${branch}" && branch="travis_debian"
96
97if [ ! -z "$PPA" ]
98then
99    branch="${TRAVIS_BRANCH}"
100fi
101
102tar -cpf  "${BUILDDIR}/${PKG_NAME}_${VERSION1}${SVNGITBZR}${dat}.orig.tar" --exclude ".git" --exclude "dist" .
103cd "${BUILDDIR}" || exit 1
104xz -9 "${PKG_NAME}_${VERSION1}${SVNGITBZR}${dat}.orig.tar"
105mkdir "${PKG_NAME}-${VERSION1}${SVNGITBZR}${dat}"
106tar -xpJf "${PKG_NAME}_${VERSION1}${SVNGITBZR}${dat}.orig.tar.xz" -C "${PKG_NAME}-${VERSION1}${SVNGITBZR}${dat}"
107cd "$DIR" || exit 1
108cp -r debian "$BUILDDIR/${PKG_NAME}-${VERSION1}${SVNGITBZR}${dat}/debian"
109cd "$BUILDDIR/${PKG_NAME}-${VERSION1}${SVNGITBZR}${dat}/" || exit 1
110dch -v "${VERSION}${SVNGITBZR}${dat}-1" -D "unstable" --force-distribution "Compile"
111dch -a "Branch: $branch"
112dch -a "Commit: $commit"
113dch -a "Date: $datct"
114
115if [ -z "$PPA" ]
116then
117    if [ ! -z "${TRAVIS_BRANCH}" ]
118    then
119        sed -i '/^ cmake (>= 3.1),/d' debian/control
120        debuild --no-lintian --preserve-env --prepend-path="${PATH}" -us -uc
121    else
122        debuild --no-lintian -us -uc
123    fi
124else
125    gpgkey
126    tmpgpg
127    test -f ~/.dput.cf || dputcf
128    dchppa_pkg
129fi
130
131
132