#!/bin/bash

# SQL-DK
# Copyright © 2013 František Kučera (frantovo.cz)
# 
# This program 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.
# 
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.


# TODO: build .deb package properly; without equivs

mkdir -p TMP/usr/bin/ &&
mkdir -p TMP/usr/share/sql-dk/ &&
mkdir -p TMP/etc/bash_completion.d/ &&

pushd TMP &&

cp ../../../scripts/sql-dk.sh                     sql-dk &&
cp ../../../xml/config.xsd                          config.xsd &&
cp ../../../xml/config.rnc                          config.rnc &&
cp ../../../java/sql-dk/dist/sql-dk.jar           sql-dk.jar &&
cp ../../../java/sql-dk/dist/bash-completion.sh   SQL-DK && # TODO: should be sql-dk – name conflict with sql-dk in /usr/bin/ (equivs bug)

chmod 755 sql-dk &&
chmod 755 SQL-DK &&

EMAIL=`echo c3FsLWRrLmRlYmlhbkBwdWIuZnJhbnRvdm8uY3oK | base64 -d` &&
NAME="Ing. František Kučera <$EMAIL>" &&
CONTROL_FILE="equivs-control" &&
COPYRIGHT_FILE="copyright" &&
URL="https://sql-dk.globalcode.info/" &&
VERSION="0.8" &&

echo "Section: database
Priority: optional
Homepage: $URL
Standards-Version: 3.9.2

Package: sql-dk
Version: $VERSION
Maintainer: $NAME
Depends: java7-runtime-headless | java7-runtime
Suggests: libpostgresql-jdbc-java,libmysql-java
Copyright: $COPYRIGHT_FILE
Extra-Files: config.xsd, config.rnc
Files: sql-dk /usr/bin/
 sql-dk.jar /usr/share/sql-dk/
 SQL-DK /etc/bash_completion.d/
Description: SQL batch client
 SQL-DK is and command-line client for relational databases." > $CONTROL_FILE &&

echo "Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: SQL-DK
Source: https://hg.frantovo.cz/sql-dk/

Files: *
Copyright: Copyright 2014 $NAME
License: GPL-3+
 This program 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.
 .
 This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
 .
 On Debian systems, the full text of the GNU General Public
 License version 3 can be found in the file
 \`/usr/share/common-licenses/GPL-3'." > $COPYRIGHT_FILE &&

equivs-build $CONTROL_FILE &&

lintian sql-dk_*.deb &&

popd &&

mv TMP/sql-dk_*.deb . &&
rm -rf TMP/
