##
##  jsqsh.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package versions
%define       V_jsqsh         2.3
%define       V_jdbc_mysql    5.1.49
%define       V_jdbc_pgsql    42.5.0
%define       V_jdbc_h2_vers  2.4.240
%define       V_jdbc_h2_date  2025-09-22

#   package information
Name:         jsqsh
Summary:      JDBC Driver Command Line Interface
URL:          https://github.com/scgray/jsqsh/
Vendor:       Scott Gray
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Database
License:      GPL
Version:      %{V_jsqsh}
Release:      20250925

#   list of sources
Source0:      https://github.com/scgray/jsqsh/releases/download/jsqsh-%{V_jsqsh}/jsqsh-%{V_jsqsh}-bin.zip
Source1:      https://github.com/h2database/h2database/releases/download/version-%{V_jdbc_h2_vers}/h2-%{V_jdbc_h2_date}.zip
Source2:      http://ftp.gwdg.de/pub/misc/mysql/Downloads/Connector-J/mysql-connector-java-%{V_jdbc_mysql}.tar.gz
Source3:      http://jdbc.postgresql.org/download/postgresql-%{V_jdbc_pgsql}.jar
Source4:      jsqsh.sh

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101, java, JAVA-JDK

%description
    JSQSH is a command-line client to RDBMS via JDBC.

%track
    prog jsqsh = {
        version   = %{V_jsqsh}
        url       = https://github.com/scgray/jsqsh/releases
        regex     = jsqsh-(__VER__)-bin\.zip
    }
    prog jsqsh:jdbc-mysql = {
        version   = %{V_jdbc_mysql}
        url       = http://dev.mysql.com/downloads/connector/j/5.1.html
        regex     = mysql-connector-java-(__VER__)\.tar\.gz
    }
    prog jsqsh:jdbc-pgsql = {
        version   = %{V_jdbc_pgsql}
        url       = https://jdbc.postgresql.org/download.html
        regex     = postgresql-(\d+\.\d+\.\d+)\.jar
    }
    prog jsqsh:jdbc-h2 = {
        version   = %{V_jdbc_h2_date}
        url       = http://www.h2database.com/html/download.html
        regex     = h2-(\d+-\d+-\d+)\.zip
    }

%prep
    %setup -q -n jsqsh-dist-%{V_jsqsh}
    %setup -q -n jsqsh-dist-%{V_jsqsh} -T -D -a 1
    %setup -q -n jsqsh-dist-%{V_jsqsh} -T -D -a 2

%build

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/lib/jsqsh
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE jsqsh.sh} \
        $RPM_BUILD_ROOT%{l_prefix}/bin/jsqsh
    %{l_shtool} install -c -m 644 \
        share/jsqsh/*.jar \
        $RPM_BUILD_ROOT%{l_prefix}/lib/jsqsh/
    %{l_shtool} install -c -m 644 \
        h2/bin/h2-*.jar \
        $RPM_BUILD_ROOT%{l_prefix}/lib/jsqsh/jdbc-h2-%{V_jdbc_h2_date}.jar
    %{l_shtool} install -c -m 644 \
        mysql-*/mysql-connector-java-*-bin.jar \
        $RPM_BUILD_ROOT%{l_prefix}/lib/jsqsh/jdbc-mysql-%{V_jdbc_mysql}.jar
    %{l_shtool} install -c -m 644 \
        %{SOURCE3} \
        $RPM_BUILD_ROOT%{l_prefix}/lib/jsqsh/jdbc-pgsql-%{V_jdbc_pgsql}.jar
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

