##
##  zope-plone.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_major  2.5.4
%define       V_minor  final

#   package information
Name:         zope-plone
Summary:      Zope Content Management Framework
URL:          http://plone.org/
Vendor:       The Plone Team
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        CMS
License:      Zope Public License
Version:      %{V_major}
Release:      20080101

#   list of sources
Source0:      http://plone.googlecode.com/files/Plone-%{V_major}-%{V_minor}.tar.gz

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  python, perl
PreReq:       python, zope
Conflicts:    zope-cmf

%description
    Plone is a user friendly Content Management System (CMS) for the
    Zope application server.

%track
    prog zope-plone = {
        version   = %{V_major}-%{V_minor}
        url       = http://plone.googlecode.com/
        regex     = Plone-(\d+\.\d+\.\d+-(?:rc\d+|final))\.tar\.gz
    }

%prep
    %setup -q -n Plone-%{V_major}-%{V_minor}

%build
    #   fix bug in distribution ownership
    find CMFFormController | xargs chmod a+rx

%install

    #   set of products to install
    CMF_PRODUCTS="\
        ATContentTypes \
        ATReferenceBrowserWidget \
        Archetypes \
        CMFActionIcons \
        CMFCalendar \
        CMFCore \
        CMFDefault \
        CMFDynamicViewFTI \
        CMFFormController \
        CMFPlacefulWorkflow \
        CMFPlone \
        CMFQuickInstallerTool \
        CMFSetup \
        CMFTopic \
        CMFUid \
        CacheFu \
        DCWorkflow \
        ExtendedPathIndex \
        ExternalEditor \
        GenericSetup \
        GroupUserFolder \
        Marshall \
        MimetypesRegistry \
        PasswordResetTool \
        PlacelessTranslationService \
        PloneErrorReporting \
        PloneLanguageTool \
        PlonePAS \
        PloneTestCase \
        PloneTranslations \
        PluggableAuthService \
        PluginRegistry \
        PortalTransforms \
        ResourceRegistries \
        SecureMailHost \
        kupu \
        statusmessages \
        validation"

    #   install product libraries
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/var/zope/Products \
        $RPM_BUILD_ROOT%{l_prefix}/lib/zope-plone
    for product in $CMF_PRODUCTS; do
        cp -r $product $RPM_BUILD_ROOT%{l_prefix}/lib/zope-plone/
    done

    #   link products into Zope instance home
    for product in $CMF_PRODUCTS; do
        ln -s \
            %{l_prefix}/lib/zope-plone/$product \
            $RPM_BUILD_ROOT%{l_prefix}/var/zope/Products/$product
    done

    #   link products into Zope instance home (special cases)
    for product in \
        CacheFu/CacheSetup \
        CacheFu/PageCacheManager \
        CacheFu/CMFSquidTool \
        CacheFu/PolicyHTTPCacheManager; \
    do
        ln -s \
            %{l_prefix}/lib/zope-plone/$product \
            $RPM_BUILD_ROOT%{l_prefix}/var/zope/Products/`basename $product`
    done

    #   install zope external editor
    %{l_shtool} install -c -m 755 \
        -e '1s;.*;#!%{l_prefix}/bin/python;' \
        ExternalEditor/zopeedit.py \
        $RPM_BUILD_ROOT%{l_prefix}/bin/

    #   fix files with spaces in the file name which break rpmtool
    find $RPM_BUILD_ROOT -name '* *' |\
        perl -n -e 'chomp; ($new = $_) =~ s/\s/_/g; rename($_, $new);'

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

%files -f files

%clean

%post
    if [ $1 -eq 1 ]; then
        ( echo "You have successfully installed Zope-Plone."
          echo "In order to use it, first restart Zope:"
          echo "    \$ $RPM_INSTALL_PREFIX/bin/openpkg rc zope restart"
          echo "Then, login to its management interface under"
          echo "    http://localhost:8080/manage"
          echo "to add and configure a Plone site."
        ) | %{l_rpmtool} msg -b -t notice
    elif [ $1 -eq 2 -o $1 -eq 0 ]; then
        eval `%{l_rc} zope status 2>/dev/null`
        [ ".$zope_active" = .yes ] && %{l_rc} zope restart
    fi
    exit 0

