##
##  liferay.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_opkg 7.3.0
%define       V_dir  7.3.0%20GA1
%define       V_zip  7.3.0-ga1-20200127150653953

#   package information
Name:         liferay
Summary:      Liferay Portal
URL:          http://www.liferay.org/
Vendor:       Liferay Inc.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Web
License:      LGPL
Version:      %{V_opkg}
Release:      20200131

#   list of sources
Source0:      http://download.sourceforge.net/project/lportal/Liferay%20Portal/%{V_dir}/liferay-ce-portal-%{V_zip}.war

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

%description
    Liferay Portal is an enterprise web platform for building business
    solutions that deliver immediate results and long-term value. It
    provides: Content & Document Management with Microsoft Office
    integration, Web Publishing and Shared Workspaces, Enterprise
    Collaboration, Social Networking and Mashups and Enterprise Portals
    and Identity Management.

%track
    prog liferay = {
        version   = %{V_opkg}
        url       = http://sourceforge.net/projects/lportal/files/Liferay%20Portal/
        regex     = (\d+\.\d+\.\d+)
    }

%prep
    %setup -q -T -c

%build

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/var/tomcat/webapps/liferay \
        $RPM_BUILD_ROOT%{l_prefix}/var/liferay/db

    #   install application into application server area
    cp %{SOURCE0} \
        $RPM_BUILD_ROOT%{l_prefix}/var/tomcat/webapps/liferay.war

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/liferay/db' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/tomcat/webapps/*' \
        '%not %dir %{l_prefix}/var/tomcat/webapps' \
        '%not %dir %{l_prefix}/var/tomcat'

%files -f files

%clean

%post
    #   after upgrade, restart application server
    [ $1 -eq 2 ] || exit 0
    eval `%{l_rc} tomcat status 2>/dev/null`
    [ ".$tomcat_active" = .yes ] && %{l_rc} tomcat restart
    exit 0

%preun
    #   before erase, stop service and remove log files
    if [ $1 -eq 0 ]; then
        rm -rf $RPM_INSTALL_PREFIX/var/liferay/db*/*           >/dev/null 2>&1 || true
        rm -f  $RPM_INSTALL_PREFIX/var/tomcat/log/liferay*log  >/dev/null 2>&1 || true
    fi
    exit 0

