##
##  quorum-bootnode.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:         quorum-bootnode
Summary:      Quorum Blockchain Service (P2P Network Boot Node)
URL:          https://www.jpmorgan.com/quorum
Vendor:       JP Morgan Chase
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        P2P
License:      LGPL
Version:      2.5.0
Release:      20200304

#   list of sources
Source0:      https://github.com/jpmorganchase/quorum/archive/v%{version}.tar.gz
Source1:      rc.quorum-bootnode

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

%description
    Quorum is a decentralized platform that runs smart contracts,
    applications that run exactly as programmed without possibility of
    downtime, censorship, fraud or third party interference. Quorum is
    a fork of the Ethereum code-base and adds: Privacy: Quorum supports
    private transactions and private contracts through public/private
    state separation and utilising Constellation, a peer-to-peer
    encrypted message exchange for directed transfer of private data
    to network participants; Alternative Consensus Mechanisms: with
    no need for POW/POS in a permissioned network, Quorum instead
    offers multiple consensus mechanisms that are more appropriate
    for consortium chains: Raft-based Consensus, a consensus model
    for faster blocktimes, transaction finality, and on-demand block
    creation and Istanbul BFT, a PBFT-inspired consensus algorithm with
    transaction finality; Peer Permissioning: node/peer permissioning
    using smart contracts, ensuring only known parties can join the
    network; and Higher Performance: Quorum offers significantly higher
    performance than public Ethereum. This is just the Quorum P2P
    network Boot Node service.

%track
    prog quorum-bootnode = {
        version   = %{version}
        url       = https://github.com/jpmorganchase/quorum/releases
        regex     = v(__VER__)\.tar\.gz
    }

%prep
    %setup -q -n quorum-%{version}

%build
    #   build program
    ./build/env.sh go run build/ci.go install ./cmd/bootnode

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/quorum-bootnode \
        $RPM_BUILD_ROOT%{l_prefix}/var/quorum-bootnode/log \
        $RPM_BUILD_ROOT%{l_prefix}/var/quorum-bootnode/run

    #   install program
    %{l_shtool} install -c -s -m 775 \
        build/bin/bootnode $RPM_BUILD_ROOT%{l_prefix}/bin/quorum-bootnode

    #   install run-command script
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.quorum-bootnode} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/etc/quorum-bootnode/' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/quorum-bootnode/*'

%files -f files

%clean

%post
    if [ $1 -eq 1 ]; then
        #   on initial installation, generate the private key
        su - %{l_rusr} -c \
            "$RPM_INSTALL_PREFIX/bin/quorum-bootnode \
                -genkey $RPM_INSTALL_PREFIX/etc/quorum-bootnode/quorum-bootnode.key"
    elif [ $1 -eq 2 ]; then
        #   after upgrade, restart service
        eval `%{l_rc} quorum-bootnode status 2>/dev/null`
        [ ".$quorum_bootnode_active" = .yes ] && %{l_rc} quorum-bootnode restart
    fi
    exit 0

%preun
    if [ $1 -eq 0 ]; then
        #   before erase, stop service and remove log files
        %{l_rc} quorum-bootnode stop 2>/dev/null
        rm -f  $RPM_INSTALL_PREFIX/etc/quorum-bootnode/*     >/dev/null 2>&1 || true
        rm -rf $RPM_INSTALL_PREFIX/var/quorum-bootnode/log/* >/dev/null 2>&1 || true
        rm -rf $RPM_INSTALL_PREFIX/var/quorum-bootnode/run/* >/dev/null 2>&1 || true
    fi
    exit 0

