##
##  cherokee.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 1.2
%define       V_minor 101

#   package information
Name:         cherokee
Summary:      Cherokee Webserver
URL:          http://www.cherokee.org/
Vendor:       Alvaro Lopez Ortega
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Web
License:      GPL
Version:      %{V_major}.%{V_minor}
Release:      20111020

#   package options
%option       with_ssl     no
%option       with_ldap    no
%option       with_geoip   no
%option       with_ffmpeg  no

#   list of sources
Source0:      http://www.cherokee-project.com/download/%{V_major}/%{version}/cherokee-%{version}.tar.gz
Source1:      rc.cherokee
Patch0:       cherokee.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  pcre
PreReq:       pcre
%if "%{with_ssl}" == "yes"
BuildPreReq:  openssl
PreReq:       openssl
%endif
%if "%{with_ldap}" == "yes"
BuildPreReq:  openldap
PreReq:       openldap
%endif
%if "%{with_geoip}" == "yes"
BuildPreReq:  geoip
PreReq:       geoip
%endif
%if "%{with_ffmpeg}" == "yes"
BuildPreReq:  ffmpeg
PreReq:       ffmpeg
%endif

%description
    Cherokee is a very fast, flexible and easy to configure Web Server.
    It supports the widespread technologies nowadays: FastCGI, SCGI,
    PHP, CGI, uWSGI, SSI, TLS and SSL encrypted connections, Virtual
    hosts, Authentication, on the fly encoding, Load Balancing, Apache
    compatible log files, Data Base Balancing, Reverse HTTP Proxy,
    Traffic Shaper, Video Streaming and much more.

%track
    prog cherokee = {
        version   = %{version}
        url       = http://www.cherokee-project.com/download/%{V_major}/
        regex     = (%{V_major}.\d+)/
    }

%prep
    %setup -q
    %patch -p0

%build
    %{l_shtool} subst \
        -e 's;/cherokee-spawner;%{l_prefix}/var/cherokee/run/cherokee-spawner;g' \
        cherokee/main.c cherokee/spawner.c
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    LIBS="-lpcre" \
    ./configure \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --datadir=%{l_prefix}/share/cherokee \
        --docdir=%{l_prefix}/share/cherokee/doc \
        --localstatedir=%{l_prefix}/var/cherokee \
        --with-wwwroot=%{l_prefix}/share/cherokee/htdocs \
        --with-wwwuser=%{l_nusr} \
        --with-wwwgroup=%{l_ngrp} \
%if "%{with_ssl}" == "yes"
        --with-libssl=%{l_prefix} \
%else
        --without-libssl \
%endif
%if "%{with_ldap}" == "yes"
        --with-ldap=%{l_prefix} \
%else
        --without-ldap \
%endif
%if "%{with_geoip}" == "yes"
        --with-geoip=%{l_prefix} \
%else
        --without-geoip \
%endif
%if "%{with_ffmpeg}" == "yes"
        --with-ffmpeg=%{l_prefix} \
%else
        --without-ffmpeg \
%endif
        --without-mysql \
        --disable-pam \
        --disable-nls
    %{l_make} %{l_mflags -O}

%install
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    strip $RPM_BUILD_ROOT%{l_prefix}/sbin/* >/dev/null 2>&1 || true
    rm -f $RPM_BUILD_ROOT%{l_prefix}/etc/cherokee/cherokee.conf.perf_sample
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.cherokee} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/cherokee/*' \
        '%attr(-,%{l_nusr},%{l_ngrp}) %{l_prefix}/var/cherokee/*' \
        '%attr(-,%{l_nusr},%{l_ngrp}) %{l_prefix}/var/cherokee/*/*' \
        '%attr(-,%{l_nusr},%{l_ngrp}) %{l_prefix}/var/cherokee/*/*/*' \
        '%attr(-,%{l_nusr},%{l_ngrp}) %{l_prefix}/var/cherokee/*/*/*/*'

%files -f files

%clean

%post
    if [ $1 -eq 1 ]; then
        ( echo "To configure Cherokee, start the Admin interface via..."
          echo ""
          echo "  \$ $RPM_INSTALL_PREFIX/sbin/cherokee-admin"
          echo ""
          echo "...and then connect to it via..."
          echo ""
          echo "  http://localhost:9090/
          echo ""
          echo "...and use the printed authentication credentials to login."
        ) | %{l_rpmtool} msg -b -t notice
    fi
    exit 0

%preun
    #   before erase, stop service and remove log files
    [ $1 -eq 0 ] || exit 0
    %{l_rc} cherokee stop 2>/dev/null
    rm -f $RPM_INSTALL_PREFIX/var/cherokee/run/* >/dev/null 2>&1 || true
    exit 0

