##
##  modsurvey.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:         modsurvey
Summary:      Website Survey Framework
URL:          http://www.modsurvey.org/
Vendor:       Joel Palmius
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Web
License:      GPL
Version:      3.2.6
Release:      20091122

#   list of sources
Source0:      http://www.modsurvey.org/download/tarballs/modsurvey-%{version}.tgz
Source1:      http://www.modsurvey.org/download/tarballs/modsurvey-docs-%{version}.tgz
Patch0:       modsurvey.patch

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

%description
    mod_survey is a website survey framework for Apache. It is used
    as a mod_perl content-handler for "survey" files which contain
    questionnaires describe the survey in an XML-based tag notation.

%track
    prog modsurvey = {
        version   = %{version}
        url       = http://www.modsurvey.org/download.php
        regex     = modsurvey-(__VER__)\.tgz
    }

%prep
    %setup -q -c
    %setup -q -D -T -a 1
    %patch -p0

%build

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/modsurvey \
        $RPM_BUILD_ROOT%{l_prefix}/lib/modsurvey \
        $RPM_BUILD_ROOT%{l_prefix}/share/modsurvey \
        $RPM_BUILD_ROOT%{l_prefix}/var/modsurvey

    #   perform standard installation procedure
    %{l_shtool} install -c %{l_value -s -a} \
        modsurvey-%{version}/installer.pl modsurvey-%{version}/installer
    ( cd modsurvey-%{version}
      %{l_prefix}/bin/perl installer </dev/null
    ) || exit $?

    #   post-adust installation paths
    mv  $RPM_BUILD_ROOT%{l_prefix}/lib/modsurvey/survey.conf \
        $RPM_BUILD_ROOT%{l_prefix}/etc/modsurvey/survey.conf
    mv  $RPM_BUILD_ROOT%{l_prefix}/lib/modsurvey/data \
        $RPM_BUILD_ROOT%{l_prefix}/var/modsurvey/data
    mv  $RPM_BUILD_ROOT%{l_prefix}/lib/modsurvey/webroot \
        $RPM_BUILD_ROOT%{l_prefix}/share/modsurvey/webroot

    #   remove some installation files
    rm -f  $RPM_BUILD_ROOT%{l_prefix}/lib/modsurvey/README.txt
    rm -f  $RPM_BUILD_ROOT%{l_prefix}/lib/modsurvey/survey.conf.sample
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/modsurvey/docs

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/modsurvey/survey.conf' \
        '%doc %{l_prefix}/share/modsurvey/webroot/docs/*.pdf' \
        '%attr(700,%{l_nusr},%{l_ngrp}) %{l_prefix}/var/modsurvey/data'

%files -f files

%clean

%post
    if [ $1 -eq 1 ]; then
        #   add hook to Apache configuration
        apacheconf="$RPM_INSTALL_PREFIX/etc/apache/apache.conf"
        if [ -f $apacheconf ]; then
            ( echo "<IfModule mod_perl.c>"
              echo "  Include $RPM_INSTALL_PREFIX/etc/modsurvey/survey.conf"
              echo "</IfModule>"
            ) | $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
                -a -i "$RPM_INSTALL_PREFIX:modsurvey" $apacheconf
        fi

        #   display final hints
        ( echo "Your next step should be to run Apache with..."
          echo "    \$ $RPM_INSTALL_PREFIX/bin/openpkg rc apache start"
          echo "...and then access the mod_survey examples under"
          echo "    http://127.0.0.1/mod_survey/"
        ) | %{l_rpmtool} msg -b -t notice
    fi
    exit 0

%preun
    if [ $1 -eq 0 ]; then
        #   remove hook from Apache configuration
        apacheconf="$RPM_INSTALL_PREFIX/etc/apache/apache.conf"
        if [ -f $apacheconf ]; then
            $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
                -r -i "$RPM_INSTALL_PREFIX:modsurvey" $apacheconf
        fi

        #   before erase, stop service and remove log files
        rm -rf $RPM_INSTALL_PREFIX/var/sympa/data/* >/dev/null 2>&1 || true
    fi
    exit 0

