##
##  x509.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:         x509
Summary:      X.509 Certificates
URL:          http://www.openpkg.org/
Vendor:       OpenPKG
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Cryptography
License:      GPL/MPL
Version:      0
Release:      20231028

#   list of sources
Source0:      x509-ca.sh
Source1:      x509-ca.pl
Source2:      x509-ca.crt
Source3:      x509-example.sh
Source4:      x509-example.txt
Source5:      x509-util.sh
Source6:      x509-util.pod

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, perl
PreReq:       OpenPKG, openpkg >= 20160101

%description
    This packages provides both example X.509 certificates and a small
    utility for easy generating X.509 certificates.

%track

%prep
    %setup -q -T -c

%build
    #   just make linting happy ;-)
    cat %{SOURCE x509-ca.sh} %{SOURCE x509-ca.pl} %{SOURCE x509-example.sh} >/dev/null

    #   generate manual page
    sed %{l_value -s -a} <%{SOURCE x509-util.pod} >x509-util.pod
    pod2man x509-util.pod >x509-util.1

%install
    #   create installation area
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/x509 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1

    #   install X.509 utility
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE x509-util.sh} \
        $RPM_BUILD_ROOT%{l_prefix}/bin/x509-util
    %{l_shtool} install -c -m 644 \
        x509-util.1 $RPM_BUILD_ROOT%{l_prefix}/man/man1/

    #   install public CA certificate bundle
    %{l_shtool} install -c -m 644 \
        %{SOURCE x509-ca.crt} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/x509/public-ca.crt.pem

    #   install example certificates/keys
    for name in `grep "^<file" %{SOURCE x509-example.txt} | sed -e 's;^.*name=";;' -e 's;".*$;;'`; do
        (echo ""; cat %{SOURCE x509-example.txt}; echo "") |\
            sed -e "1,/^<file name=\"$name\">/d" -e "/<\/file>/,\$d" >$name
        %{l_shtool} install -c -m 644 %{l_value -s -a} \
            $name $RPM_BUILD_ROOT%{l_prefix}/etc/x509/
    done

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/x509/*'

%files -f files

%clean

