##
##  apache-suphp.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:         apache-suphp
Summary:      Apache Extension: PHP script executions wrapper
URL:          http://www.suphp.org/
Vendor:       Sebastian Marsching
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Web
License:      GPL
Version:      0.7.2
Release:      20150117

#   package options
%option       with_suphp_caller         %{l_nusr}
%option       with_suphp_phpcgi         %{l_prefix}/cgi/php
%option       with_suphp_ugid_mode      paranoid

#   list of sources
Source0:      http://www.suphp.org/download/suphp-%{version}.tar.gz
Source1:      apache-suphp.conf
Source2:      suphp.conf
Patch0:       apache-suphp.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, gcc::with_cxx = yes, autoconf, automake, libtool
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  apache, apr, php
PreReq:       apache, apr, php

%description
    The suPHP Apache module together with suPHP itself provides an easy
    way to run PHP scripts with different users on the same server.

    It provides security, because the PHP scripts are not run with the
    rights of the webserver's user. In addition to that you probably
    won't have to use PHP's "safe mode", which applies many restrictions
    on the scripts.

%track
    prog apache-suphp = {
        version   = %{version}
        url       = http://www.suphp.org/Download.html
        regex     = suphp-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -n suphp-%{version}
    %{l_sed} <%{PATCH0} -e 's;@l_prefix@;%{l_prefix};g' | %{l_patch} -p0 -b

%build
    aclocal
    automake --add-missing
    libtoolize
    autoconf
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    ./configure \
        --prefix=%{l_prefix} \
        --sysconfdir=%{l_prefix}/etc/apache \
        --with-apr="%{l_prefix}/bin/apr-1-config" \
        --with-apxs="%{l_prefix}/sbin/apxs" \
        --with-apache-user=%{with_suphp_caller} \
        --with-logfile=%{l_prefix}/var/apache/log/apache-suphp.log \
        --with-setid-mode=%{with_suphp_ugid_mode} \
        --enable-shared
    %{l_make} %{l_mflags -O}

%install

    #   install suPHP
    %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT

    #   install default configuration files
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/apache/apache.d
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE suphp.conf} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/apache/
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE apache-suphp.conf} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/apache/apache.d/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/apache/suphp.conf' \
        '%config %{l_prefix}/etc/apache/apache.d/apache-suphp.conf' \
        '%attr(4755,%{l_susr},%{l_sgrp}) %{l_prefix}/sbin/suphp'

%files -f files

%clean

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

