##
##  verapdf.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 information
Name:         verapdf
Summary:      PDF/A Verification Tool
URL:          http://verapdf.org/
Vendor:       veraPDF Consortium
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Typesetting
License:      MPL/GPL
Version:      1.14.8
Release:      20191025

#   list of sources
Source0:      https://software.verapdf.org/releases/1.14/verapdf-pdfbox-%{version}-installer.zip

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

%description
    Designed to meet the needs of digital preservationists, and
    supported by leading members of the PDF software developer
    community, veraPDF is a purpose-built file-format validator covering
    all PDF/A parts and conformance levels.

%track
    prog verapdf = {
        version   = %{version}
        url       = https://software.verapdf.org/releases/1.14/
        regex     = verapdf-pdfbox-(__VER__)-installer\.zip
    }

%prep
    %setup -q -n verapdf-pdfbox-%{version}

%build

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/verapdf

    #   perform a batch installation
    (   echo '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
        echo '<AutomatedInstallation langpack="eng">'
        echo '    <com.izforge.izpack.panels.htmlinfo.HTMLInfoPanel id="welcome"/>'
        echo '    <com.izforge.izpack.panels.target.TargetPanel id="install_dir">'
        echo "        <installpath>$RPM_BUILD_ROOT%{l_prefix}/libexec/verapdf</installpath>"
        echo '    </com.izforge.izpack.panels.target.TargetPanel>'
        echo '    <com.izforge.izpack.panels.packs.PacksPanel id="sdk_pack_select">'
        echo '        <pack index="0" name="veraPDF GUI" selected="false"/>'
        echo '        <pack index="1" name="veraPDF Mac and *nix Scripts" selected="true"/>'
        echo '        <pack index="2" name="veraPDF Corpus and Validation model" selected="false"/>'
        echo '        <pack index="3" name="veraPDF Documentation" selected="false"/>'
        echo '        <pack index="4" name="veraPDF Sample Plugins" selected="false"/>'
        echo '    </com.izforge.izpack.panels.packs.PacksPanel>'
        echo '    <com.izforge.izpack.panels.install.InstallPanel id="install"/>'
        echo '    <com.izforge.izpack.panels.finish.FinishPanel id="finish"/>'
        echo '</AutomatedInstallation>'
    ) >auto-install.xml
    %{l_prefix}/bin/java -jar *.jar auto-install.xml

    #   strip down installation
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/libexec/verapdf/Uninstaller
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/libexec/verapdf/plugins
    rm -f $RPM_BUILD_ROOT%{l_prefix}/libexec/verapdf/verapdf-gui

    #   post-adjust installation
    (   cd $RPM_BUILD_ROOT%{l_prefix}/libexec/verapdf/profiles
        IFS="
"
        for p in `find . -name "* *" -type f -depth -print`; do
            file=`echo "$p" | sed -e 's;^.*/;;'`
            dir=`echo "$p" | sed -e 's;[^/]*$;;'`
            filenew=`echo "$file" | sed -e 's; ;-;g'`
            mv "$dir$file" "$dir$filenew"
        done
        for p in `find . -name "* *" -type d -depth -print`; do
            dirlast=`echo "$p" | sed -e 's;^.*/;;'`
            dirprefix=`echo "$p" | sed -e 's;[^/]*$;;'`
            dirlastnew=`echo "$dirlast" | sed -e 's; ;-;g'`
            mv "$dirprefix$dirlast" "$dirprefix$dirlastnew"
        done
    ) || exit $?

    #   provide CLI wrapper script
    (   echo "#!/bin/sh"
        echo "exec %{l_prefix}/libexec/verapdf/verapdf \${1+\"\$@\"}"
    ) >verapdf.sh
    %{l_shtool} install -c -m 755 \
        verapdf.sh $RPM_BUILD_ROOT%{l_prefix}/bin/verapdf

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

