##
##  sqlshell.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 version
%define       V_sqlshell      0.8.1
%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:         sqlshell
Summary:      Shell SQL RDBMS
URL:          http://software.clapper.org/sqlshell/
Vendor:       Brian M. Clapper
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Database
License:      BSD
Version:      %{V_sqlshell}
Release:      20250924

#   list of sources
Source0:      http://cloud.github.com/downloads/bmc/sqlshell/sqlshell-%{V_sqlshell}-installer.jar
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:      auto-install.xml
Source5:      sqlshell.sh
Source6:      sqlshell.cfg

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

%description
    SQLShell is a Scala-based SQL command-line tool, similar in concept
    to tools like Oracle’s SQL Plus, the PostgreSQL psql(1) command,
    and MySQL’s mysql(1) command.

%track
    prog sqlshell = {
        version   = %{V_sqlshell}
        url       = http://github.com/bmc/sqlshell/downloads
        regex     = sqlshell-(__VER__)-installer\.jar
    }
    prog sqlshell: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 sqlshell:jdbc-pgsql = {
        version   = %{V_jdbc_pgsql}
        url       = https://jdbc.postgresql.org/download.html
        regex     = postgresql-(\d+\.\d+\.\d+)\.jar
    }
    prog sqlshell:jdbc-h2 = {
        version   = %{V_jdbc_h2_date}
        url       = http://www.h2database.com/html/download.html
        regex     = h2-(\d+-\d+-\d+)\.zip
    }

%prep
    %setup -q -T -c
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2

%build
    %{l_shtool} install -c -m 644 \
        -e "s;@installpath@;`pwd`;g" \
        %{SOURCE auto-install.xml} auto-install.xml
    %{l_prefix}/bin/java -jar %{SOURCE0} auto-install.xml

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/sqlshell \
        $RPM_BUILD_ROOT%{l_prefix}/lib/sqlshell
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE sqlshell.sh} \
        $RPM_BUILD_ROOT%{l_prefix}/bin/sqlshell
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE sqlshell.cfg} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/sqlshell/
    %{l_shtool} install -c -m 644 \
        lib/*.jar \
        $RPM_BUILD_ROOT%{l_prefix}/lib/sqlshell/
    %{l_shtool} install -c -m 644 \
        h2/bin/h2-*.jar \
        $RPM_BUILD_ROOT%{l_prefix}/lib/sqlshell/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/sqlshell/jdbc-mysql-%{V_jdbc_mysql}.jar
    %{l_shtool} install -c -m 644 \
        %{SOURCE3} \
        $RPM_BUILD_ROOT%{l_prefix}/lib/sqlshell/jdbc-pgsql-%{V_jdbc_pgsql}.jar
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/sqlshell/*'

%files -f files

%clean

