##
##  akka.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:         akka
Summary:      Akka Application Server
URL:          http://akka.io/
Vendor:       Typesafe
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Web
License:      Apache Software License 2.0
Version:      2.4.18
Release:      20170502

#   list of sources
Source0:      http://downloads.typesafe.com/akka/akka_2.11-%{version}.zip
Source1:      rc.akka
Source2:      akka.sh
Source3:      akka.conf

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

%description
    Akka is a powerful toolkit and runtime for building highly
    concurrent, distributed, and fault tolerant event-driven
    applications on the JVM. It provides both a Scala and Java API.

%track
    prog akka = {
        version   = %{version}
        url       = http://akka.io/downloads/
        regex     = akka_2\.11-(__VER__)\.zip
    }

%prep
    %setup -q -T -c
    cd ..
    %{l_prefix}/bin/unzip -q -x %{SOURCE0}

%build
    rm -f lib/akka/*i*have*ces.jar

%install
    #   create installation tree
    %{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/akka \
        $RPM_BUILD_ROOT%{l_prefix}/lib/akka/boot \
        $RPM_BUILD_ROOT%{l_prefix}/lib/akka/akka \
        $RPM_BUILD_ROOT%{l_prefix}/var/akka/run \
        $RPM_BUILD_ROOT%{l_prefix}/var/akka/log \
        $RPM_BUILD_ROOT%{l_prefix}/var/akka/deploy

    #   install application JARs
    %{l_shtool} install -c -m 644 \
        lib/*.jar $RPM_BUILD_ROOT%{l_prefix}/lib/akka/boot/
    %{l_shtool} install -c -m 644 \
        lib/akka/*.jar $RPM_BUILD_ROOT%{l_prefix}/lib/akka/akka/

    #   install default configuration
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE akka.conf} $RPM_BUILD_ROOT%{l_prefix}/etc/akka/application.conf

    #   install run-command script
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE akka.sh} $RPM_BUILD_ROOT%{l_prefix}/bin/akka

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

    #   determine package files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/akka/*' \
        '%attr(755,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/akka' \
        '%attr(755,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/akka/*'

%files -f files

%clean

%post
    #   after upgrade, restart service
    if [ $1 -eq 2 ]; then
        eval `%{l_rc} akka status 2>/dev/null`
        [ ".$akka_active" = .yes ] && %{l_rc} akka restart
    fi
    exit 0

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

