<commit_before># Based on http://pkgs.fedoraproject.org/cgit/rubygem-passenger.git/tree/

%global package_name <%= PASSENGER_RPM_NAME %>
%global package_version <%= PASSENGER_VERSION %>
%global package_release <%= PASSENGER_RPM_RELEASE %>
%global tarball_name <%= PASSENGER_TARBALL_NAME %>
%global tarball_version <%= PASSENGER_VERSION %>
%global apache_module_package_name <%= PASSENGER_APACHE_MODULE_RPM_NAME %>
%global namespace <%= PhusionPassenger::GLOBAL_NAMESPACE_DIRNAME %>
%global nginx_version <%= NGINX_VERSION %>
%global bundled_boost_version 1.54.0
%global is_enterprise <%= PASSENGER_ENTERPRISE ? 1 : 0 %>
%global release_dist .<%= @distribution %>

# Fedora <= 18 and RHEL <= 6 used the rubyabi requirement.
# This is gone in later versions.
%if 0%{?fc18}
%global uses_rubyabi 1
%global rubyabi 1.9.1
%endif
%if 0%{?el6}
%global uses_rubyabi 1
%global rubyabi 1.8
%endif

%if 0%{?fedora} >= 19
%global gem_extdir %{gem_extdir_mri}
%endif
%{!?gem_extdir: %global gem_extdir %{gem_instdir}/extdir}

%{!?_httpd_mmn: %{expand: %%global _httpd_mmn %%(cat %{_includedir}/httpd/.mmn 2>/dev/null || echo 0-0)}}
%{!?_httpd_confdir:     %{expand: %%global _httpd_confdir     %%{_sysconfdir}/httpd/conf.d}}
# /etc/httpd/conf.d with httpd < 2.4 and defined as /etc/httpd/conf.modules.d with httpd >= 2.4
%{!?_httpd_modconfdir:  %{expand: %%global _httpd_modconfdir  %%{_sysconfdir}/httpd/conf.d}}
%{!?_httpd_moddir:      %{expand: %%global _httpd_moddir      %%{_libdir}/httpd/modules}}

%{!?ruby_vendorlibdir: %global ruby_vendorlibdir %(ruby -rrbconfig -e 'puts RbConfig::CONFIG["vendorlibdir"]')}
%{!?ruby_vendorarchdir: %global ruby_vendorarchdir %(ruby -rrbconfig -e 'puts RbConfig::CONFIG["vendorarchdir"]')}
%global passenger_ruby_libdir %{ruby_vendorlibdir}
%global locations_ini %{passenger_ruby_libdir}/phusion_passenger/locations.ini
%global selinux_types %(%{__awk} '/^#[[:space:]]*SELINUXTYPE=/,/^[^#]/ { if ($3 == "-") printf "%s ", $2 }' /etc/selinux/config 2>/dev/null)
%global selinux_variants %([ -z "%{selinux_types}" ] && echo mls targeted || echo %{selinux_types})


Summary: Phusion Passenger application server
Name: %{package_name}
Version: %{package_version}
Release: %{package_release}%{?release_dist}
Group: System Environment/Daemons
# Passenger code uses MIT license.
# Bundled(Boost) uses Boost Software License
# BCrypt and Blowfish files use BSD license.
# Documentation is CC-BY-SA
# See: https://bugzilla.redhat.com/show_bug.cgi?id=470696#c146
License: Boost and BSD and BSD with advertising and MIT and zlib
URL: https://www.phusionpassenger.com

Source: http://s3.amazonaws.com/phusion-passenger/releases/%{tarball_name}-%{tarball_version}.tar.gz
Source1: http://nginx.org/download/nginx-%{nginx_version}.tar.gz
Source2: passenger.fc
Source3: passenger.if
Source4: passenger.te
Source10: passenger.logrotate
Source100: apache-passenger.conf.in
Source101: apache-passenger-module.conf
Source102: passenger.tmpfiles

# https://bugzilla.redhat.com/show_bug.cgi?id=985634
Patch107:       rubygem-passenger-4.0.18-GLIBC_HAVE_LONG_LONG.patch

Requires: rubygems
# XXX: Needed to run passenger standalone
Requires: rubygem(rack)
Requires: rubygem(rake)
%if 0%{?uses_rubyabi}
Requires: ruby(abi) = %{rubyabi}
%else
Requires: ruby(release)
%endif

%{!?_selinux_policy_version: %global _selinux_policy_version %(sed -e 's,.*selinux-policy-\\([^/]*\\)/.*,\\1,' /usr/share/selinux/devel/policyhelp 2>/dev/null)}
%if "%{_selinux_policy_version}" != ""
Requires: selinux-policy >= %{_selinux_policy_version}
%endif
Requires(post):   /usr/sbin/semodule, /sbin/restorecon, /sbin/fixfiles
Requires(postun): /usr/sbin/semodule, /sbin/restorecon, /sbin/fixfiles

%if 0%{?rhel} >= 6 || 0%{?fedora} >= 15
BuildRequires: libcurl-devel
%else
BuildRequires: curl-devel
%endif

BuildRequires: httpd-devel
BuildRequires: ruby
BuildRequires: ruby-devel
BuildRequires: rubygems
BuildRequires: rubygems-devel
BuildRequires: rubygem(rake) >= 0.8.1
BuildRequires: rubygem(rack)
BuildRequires: zlib-devel
BuildRequires: pcre-devel
BuildRequires: openssl-devel
BuildRequires: checkpolicy, selinux-policy-devel, /usr/share/selinux/devel/policyhelp
BuildRequires: libselinux-devel

Provides: %{package_name} = %{version}-%{release}
Provides: bundled(boost)  = %{bundled_boost_version}

Obsoletes: rubygem-passenger < %{version}-%{release}
Obsoletes: rubygem-passenger%{?_isa} < %{version}-%{release}
Obsoletes: rubygem-passenger-native < %{version}-%{release}
Obsoletes: rubygem-passenger-native%{?_isa} < %{version}-%{release}
Obsoletes: rubygem-passenger-native-libs < %{version}-%{release}
Obsoletes: rubygem-passenger-native-libs%{?_isa} < %{version}-%{release}

%if %{is_enterprise}
Obsoletes: passenger
Conflicts: passenger-devel
Conflicts: passenger-doc
Conflicts: mod_passenger
%endif

%description
Phusion Passenger® is a web server and application server, designed to be fast,
robust and lightweight. It takes a lot of complexity out of deploying web apps,
adds powerful enterprise-grade features that are useful in production,
and makes administration much easier and less complex. It supports Ruby,
Python, Node.js and Meteor.

%package -n %{apache_module_package_name}
Summary: Apache Module for Phusion Passenger
Group: System Environment/Daemons
BuildRequires:  httpd-devel
Requires: httpd-mmn = %{_httpd_mmn}
Requires: %{package_name}%{?_isa} = %{version}-%{release}
%if %{is_enterprise}
Obsoletes: mod_passenger
%endif
License: Boost and BSD and BSD with advertising and MIT and zlib

%description -n %{apache_module_package_name}
This package contains the pluggable Apache server module for Phusion Passenger®.

%package devel
Summary: Phusion Passenger development files
Group: System Environment/Daemons
Requires: %{package_name}%{?_isa} = %{version}-%{release}
Provides: bundled(boost-devel) = %{bundled_boost_version}
Obsoletes: rubygem-passenger-devel < 4.0.33
Obsoletes: rubygem-passenger-devel%{?_isa} < 4.0.33
%if %{is_enterprise}
Obsoletes: passenger-devel
%endif
License: Boost and BSD and BSD with advertising and GPL+ and MIT and zlib

%description devel
This package contains development files for Phusion Passenger®. Installing this
package allows it to compile native extensions for non-standard Ruby interpreters,
and allows Passenger Standalone to use a different Nginx core version.

%package doc
Summary: Phusion Passenger documentation
Group: System Environment/Daemons
Requires: %{package_name} = %{version}-%{release}
Obsoletes: rubygem-passenger-doc < %{version}-%{release}
Provides:  rubygem-passenger-doc = %{version}-%{release}
%if %{is_enterprise}
Obsoletes: passenger-doc
%endif
BuildArch: noarch
License: CC-BY-SA and MIT and (MIT or GPL+)

%description doc
This package contains documentation files for Phusion Passenger®.


%prep
%setup -q -n %{tarball_name}-%{tarball_version}
tar xzf %{SOURCE1}

# fix passenger boost for glibc >= 2.18
%if 0%{?fedora} >= 20
    %patch107 -p1 -b .glibc-long
%endif

%build
export EXTRA_CFLAGS="${CFLAGS:-%optflags} -Wno-deprecated"
export EXTRA_CXXFLAGS="${CXXFLAGS:-%optflags} -Wno-deprecated"

# Remove default optimization flags and use Phusion Passenger's recommended optimization flags.
export EXTRA_CFLAGS=`echo "$EXTRA_CFLAGS" | sed 's|-O2||g'`
export EXTRA_CXXFLAGS=`echo "$EXTRA_CXXFLAGS" | sed 's|-O2||g'`
export OPTIMIZE=yes
export USE_SELINUX=yes

export CACHING=false

# Speed up ccache (reduce I/O) by lightly compressing things.
# Always set these variables because pbuilder uses ccache transparently.
export CCACHE_COMPRESS=1
export CCACHE_COMPRESS_LEVEL=3

export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

# Build Passenger.
rake fakeroot \
    NATIVE_PACKAGING_METHOD=rpm \
    FS_PREFIX=%{_prefix} \
    FS_BINDIR=%{_bindir} \
    FS_SBINDIR=%{_sbindir} \
    FS_DATADIR=%{_datadir} \
    FS_LIBDIR=%{_libdir} \
    FS_DOCDIR=%{_docdir} \
    RUBYLIBDIR=%{ruby_vendorlibdir} \
    RUBYARCHDIR=%{ruby_vendorarchdir} \
    APACHE2_MODULE_PATH=%{_httpd_moddir}/mod_passenger.so

# Build Nginx core for Passenger Standalone.
nginx_config_opts=`ruby -Isrc/ruby_supportlib -rphusion_passenger -e 'PhusionPassenger.locate_directories; PhusionPassenger.require_passenger_lib "config/nginx_engine_compiler"; puts PhusionPassenger::Config::NginxEngineCompiler.configure_script_options'`
pushd nginx-%{nginx_version}
./configure --prefix=/tmp $nginx_config_opts --add-module=`pwd`/../src/nginx_module
make
popd

# Build SELinux policy modules.
%{__cp} %{SOURCE3} %{SOURCE4} .
%{__cp} %{SOURCE2} passenger.fc.tmp
%{__sed} -i "s|SUPPORT_BINARIES_DIR_MAIN|%{_libdir}/%{namespace}/support-binaries|g" passenger.fc.tmp
%{__sed} -i "s|SUPPORT_BINARIES_DIR_ALT|%{_prefix}/lib/%{namespace}/support-binaries|g" passenger.fc.tmp
uniq passenger.fc.tmp > passenger.fc
for selinuxvariant in %{selinux_variants}; do
    %{__make} -f %{_datadir}/selinux/devel/Makefile NAME=passenger
    %{__mv} passenger.pp passenger.pp.${selinuxvariant}
    %{__make} -f %{_datadir}/selinux/devel/Makefile NAME=passenger clean
done


%install
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

%{__rm} -rf %{buildroot}
%{__mkdir} %{buildroot}
%{__cp} -a pkg/fakeroot/* %{buildroot}/
%{__cp} nginx-%{nginx_version}/objs/nginx %{buildroot}%{_libdir}/%{namespace}/support-binaries/nginx-%{nginx_version}

# Install bootstrapping code into the executables and the Nginx config script.
./dev/install_scripts_bootstrap_code.rb --ruby %{passenger_ruby_libdir} \
    %{buildroot}%{_bindir}/* \
    %{buildroot}%{_sbindir}/* \
    `find %{buildroot} -name rack_handler.rb`
./dev/install_scripts_bootstrap_code.rb --nginx-module-config %{_bindir} %{buildroot}%{_datadir}/%{namespace}/ngx_http_passenger_module/config

# Install Apache config.
%{__mkdir_p} %{buildroot}%{_httpd_confdir} %{buildroot}%{_httpd_modconfdir}
%{__sed} -e 's|@PASSENGERROOT@|%{passenger_ruby_libdir}/phusion_passenger/locations.ini|g' %{SOURCE100} > passenger.conf
%if !(0%{?rhel} >= 7 || 0%{?fedora} >= 16)
    %{__sed} -i -e '/^# *Require all granted/d' passenger.conf
%endif

%if "%{_httpd_modconfdir}" == "%{_httpd_confdir}"
    %{__cat} %{SOURCE101} passenger.conf > passenger-combined.conf
    touch -r %{SOURCE100} passenger-combined.conf
    %{__install} -pm 0644 passenger-combined.conf %{buildroot}%{_httpd_confdir}/passenger.conf
%else
    touch -r %{SOURCE100} passenger.conf
    %{__install} -pm 0644 passenger.conf %{buildroot}%{_httpd_confdir}/passenger.conf
    %{__install} -pm 0644 %{SOURCE101} %{buildroot}%{_httpd_modconfdir}/10-passenger.conf
    touch -r %{SOURCE101} %{buildroot}%{_httpd_modconfdir}/10-passenger.conf
%endif

# Make our ghost log and run directories...
%{__mkdir_p} %{buildroot}%{_localstatedir}/log/passenger-analytics
%{__mkdir_p} %{buildroot}%{_localstatedir}/run/passenger-instreg
%{__mkdir_p} %{buildroot}%{_prefix}/lib/tmpfiles.d 
%if 0%{?rhel} >= 7 || 0%{?fedora} >= 16
    %{__install} -m 644 -p %{SOURCE102} \
        %{buildroot}%{_prefix}/lib/tmpfiles.d/passenger.conf
%endif

# logrotate
%{__mkdir_p} %{buildroot}%{_sysconfdir}/logrotate.d
%{__install} -pm 0644 %{SOURCE10} %{buildroot}%{_sysconfdir}/logrotate.d/passenger

# Install man pages into the proper location.
%{__mkdir_p} %{buildroot}%{_mandir}/man1
%{__mkdir_p} %{buildroot}%{_mandir}/man8
%{__cp} man/*.1 %{buildroot}%{_mandir}/man1
%{__cp} man/*.8 %{buildroot}%{_mandir}/man8

# Fix Python scripts with shebang which are not executable
%{__chmod} +x %{buildroot}%{_datadir}/%{namespace}/helper-scripts/wsgi-loader.py

# Install SELinux policy module.
for selinuxvariant in %{selinux_variants}; do
    %{__install} -d %{buildroot}%{_datadir}/selinux/${selinuxvariant}
    %{__install} -p -m 644 passenger.pp.${selinuxvariant} \
        %{buildroot}%{_datadir}/selinux/${selinuxvariant}/passenger.pp
done


%pre
policy_version=`/usr/sbin/sestatus | %{__grep} 'Policy version' | %{__sed} 's/.*: *//'`
if test "$policy_version" != "" && test "$policy_version" -lt 25; then
    kernel_version=`/bin/uname -r`
    echo >&2
    echo "   !!!! PASSENGER CANNOT BE INSTALLED: KERNEL TOO OLD !!!!" >&2
    echo >&2
    echo "   You are currently running kernel $kernel_version, with SELinux policy" >&2
    echo "   version $policy_version. However, Passenger's SELinux policy requires kernel >= 2.6.39," >&2
    echo "   with support for policy version >= 25." >&2
    echo >&2
    echo "   There are two ways to solve this problem:" >&2
    echo >&2
    echo "   Alternative 1: upgrade your kernel to at least 2.6.39, then reinstall" >&2
    echo "   Passenger." >&2
    echo >&2
    echo "   -OR-" >&2
    echo >&2
    echo "   Alternative 2: disable SELinux." >&2
    echo "   Edit /etc/selinux/config, set SELINUX=disabled, reboot, then" >&2
    echo "   reinstall Passenger." >&2
    echo >&2
    exit 1
fi

%post
for selinuxvariant in %{selinux_variants}; do
    /usr/sbin/semodule -s ${selinuxvariant} -i \
        %{_datadir}/selinux/${selinuxvariant}/passenger.pp &> /dev/null || :
done
/sbin/fixfiles -R %{package_name} restore || :
/sbin/restorecon -R %{_libdir}/%{namespace}/support-binaries || :

%postun
if [ $1 -eq 0 ] ; then
    for selinuxvariant in %{selinux_variants}; do
        /usr/sbin/semodule -s ${selinuxvariant} -r passenger &> /dev/null || :
    done
    /sbin/fixfiles -R %{package_name} restore || :
    [ -d %{_libdir}/%{namespace}/support-binaries ] && \
        /sbin/restorecon -R %{_libdir}/%{namespace}/support-binaries &> /dev/null || :
fi


%files
%{_bindir}/*
%{_sbindir}/*<commit_msg>Reinstall Passenger SELinux policy upon upgrading the system SELinux policy<commit_after># Based on http://pkgs.fedoraproject.org/cgit/rubygem-passenger.git/tree/

%global package_name <%= PASSENGER_RPM_NAME %>
%global package_version <%= PASSENGER_VERSION %>
%global package_release <%= PASSENGER_RPM_RELEASE %>
%global tarball_name <%= PASSENGER_TARBALL_NAME %>
%global tarball_version <%= PASSENGER_VERSION %>
%global apache_module_package_name <%= PASSENGER_APACHE_MODULE_RPM_NAME %>
%global namespace <%= PhusionPassenger::GLOBAL_NAMESPACE_DIRNAME %>
%global nginx_version <%= NGINX_VERSION %>
%global bundled_boost_version 1.54.0
%global is_enterprise <%= PASSENGER_ENTERPRISE ? 1 : 0 %>
%global release_dist .<%= @distribution %>

# Fedora <= 18 and RHEL <= 6 used the rubyabi requirement.
# This is gone in later versions.
%if 0%{?fc18}
%global uses_rubyabi 1
%global rubyabi 1.9.1
%endif
%if 0%{?el6}
%global uses_rubyabi 1
%global rubyabi 1.8
%endif

%if 0%{?fedora} >= 19
%global gem_extdir %{gem_extdir_mri}
%endif
%{!?gem_extdir: %global gem_extdir %{gem_instdir}/extdir}

%{!?_httpd_mmn: %{expand: %%global _httpd_mmn %%(cat %{_includedir}/httpd/.mmn 2>/dev/null || echo 0-0)}}
%{!?_httpd_confdir:     %{expand: %%global _httpd_confdir     %%{_sysconfdir}/httpd/conf.d}}
# /etc/httpd/conf.d with httpd < 2.4 and defined as /etc/httpd/conf.modules.d with httpd >= 2.4
%{!?_httpd_modconfdir:  %{expand: %%global _httpd_modconfdir  %%{_sysconfdir}/httpd/conf.d}}
%{!?_httpd_moddir:      %{expand: %%global _httpd_moddir      %%{_libdir}/httpd/modules}}

%{!?ruby_vendorlibdir: %global ruby_vendorlibdir %(ruby -rrbconfig -e 'puts RbConfig::CONFIG["vendorlibdir"]')}
%{!?ruby_vendorarchdir: %global ruby_vendorarchdir %(ruby -rrbconfig -e 'puts RbConfig::CONFIG["vendorarchdir"]')}
%global passenger_ruby_libdir %{ruby_vendorlibdir}
%global locations_ini %{passenger_ruby_libdir}/phusion_passenger/locations.ini
%global selinux_types %(%{__awk} '/^#[[:space:]]*SELINUXTYPE=/,/^[^#]/ { if ($3 == "-") printf "%s ", $2 }' /etc/selinux/config 2>/dev/null)
%global selinux_variants %([ -z "%{selinux_types}" ] && echo mls targeted || echo %{selinux_types})


Summary: Phusion Passenger application server
Name: %{package_name}
Version: %{package_version}
Release: %{package_release}%{?release_dist}
Group: System Environment/Daemons
# Passenger code uses MIT license.
# Bundled(Boost) uses Boost Software License
# BCrypt and Blowfish files use BSD license.
# Documentation is CC-BY-SA
# See: https://bugzilla.redhat.com/show_bug.cgi?id=470696#c146
License: Boost and BSD and BSD with advertising and MIT and zlib
URL: https://www.phusionpassenger.com

Source: http://s3.amazonaws.com/phusion-passenger/releases/%{tarball_name}-%{tarball_version}.tar.gz
Source1: http://nginx.org/download/nginx-%{nginx_version}.tar.gz
Source2: passenger.fc
Source3: passenger.if
Source4: passenger.te
Source10: passenger.logrotate
Source100: apache-passenger.conf.in
Source101: apache-passenger-module.conf
Source102: passenger.tmpfiles

# https://bugzilla.redhat.com/show_bug.cgi?id=985634
Patch107:       rubygem-passenger-4.0.18-GLIBC_HAVE_LONG_LONG.patch

Requires: rubygems
# XXX: Needed to run passenger standalone
Requires: rubygem(rack)
Requires: rubygem(rake)
%if 0%{?uses_rubyabi}
Requires: ruby(abi) = %{rubyabi}
%else
Requires: ruby(release)
%endif

%{!?_selinux_policy_version: %global _selinux_policy_version %(sed -e 's,.*selinux-policy-\\([^/]*\\)/.*,\\1,' /usr/share/selinux/devel/policyhelp 2>/dev/null)}
%if "%{_selinux_policy_version}" != ""
Requires: selinux-policy >= %{_selinux_policy_version}
%endif
Requires(post):   /usr/sbin/semodule, /sbin/restorecon, /sbin/fixfiles
Requires(postun): /usr/sbin/semodule, /sbin/restorecon, /sbin/fixfiles

%if 0%{?rhel} >= 6 || 0%{?fedora} >= 15
BuildRequires: libcurl-devel
%else
BuildRequires: curl-devel
%endif

BuildRequires: httpd-devel
BuildRequires: ruby
BuildRequires: ruby-devel
BuildRequires: rubygems
BuildRequires: rubygems-devel
BuildRequires: rubygem(rake) >= 0.8.1
BuildRequires: rubygem(rack)
BuildRequires: zlib-devel
BuildRequires: pcre-devel
BuildRequires: openssl-devel
BuildRequires: checkpolicy, selinux-policy-devel, /usr/share/selinux/devel/policyhelp
BuildRequires: libselinux-devel

Provides: %{package_name} = %{version}-%{release}
Provides: bundled(boost)  = %{bundled_boost_version}

Obsoletes: rubygem-passenger < %{version}-%{release}
Obsoletes: rubygem-passenger%{?_isa} < %{version}-%{release}
Obsoletes: rubygem-passenger-native < %{version}-%{release}
Obsoletes: rubygem-passenger-native%{?_isa} < %{version}-%{release}
Obsoletes: rubygem-passenger-native-libs < %{version}-%{release}
Obsoletes: rubygem-passenger-native-libs%{?_isa} < %{version}-%{release}

%if %{is_enterprise}
Obsoletes: passenger
Conflicts: passenger-devel
Conflicts: passenger-doc
Conflicts: mod_passenger
%endif

%description
Phusion Passenger® is a web server and application server, designed to be fast,
robust and lightweight. It takes a lot of complexity out of deploying web apps,
adds powerful enterprise-grade features that are useful in production,
and makes administration much easier and less complex. It supports Ruby,
Python, Node.js and Meteor.

%package -n %{apache_module_package_name}
Summary: Apache Module for Phusion Passenger
Group: System Environment/Daemons
BuildRequires:  httpd-devel
Requires: httpd-mmn = %{_httpd_mmn}
Requires: %{package_name}%{?_isa} = %{version}-%{release}
%if %{is_enterprise}
Obsoletes: mod_passenger
%endif
License: Boost and BSD and BSD with advertising and MIT and zlib

%description -n %{apache_module_package_name}
This package contains the pluggable Apache server module for Phusion Passenger®.

%package devel
Summary: Phusion Passenger development files
Group: System Environment/Daemons
Requires: %{package_name}%{?_isa} = %{version}-%{release}
Provides: bundled(boost-devel) = %{bundled_boost_version}
Obsoletes: rubygem-passenger-devel < 4.0.33
Obsoletes: rubygem-passenger-devel%{?_isa} < 4.0.33
%if %{is_enterprise}
Obsoletes: passenger-devel
%endif
License: Boost and BSD and BSD with advertising and GPL+ and MIT and zlib

%description devel
This package contains development files for Phusion Passenger®. Installing this
package allows it to compile native extensions for non-standard Ruby interpreters,
and allows Passenger Standalone to use a different Nginx core version.

%package doc
Summary: Phusion Passenger documentation
Group: System Environment/Daemons
Requires: %{package_name} = %{version}-%{release}
Obsoletes: rubygem-passenger-doc < %{version}-%{release}
Provides:  rubygem-passenger-doc = %{version}-%{release}
%if %{is_enterprise}
Obsoletes: passenger-doc
%endif
BuildArch: noarch
License: CC-BY-SA and MIT and (MIT or GPL+)

%description doc
This package contains documentation files for Phusion Passenger®.


%prep
%setup -q -n %{tarball_name}-%{tarball_version}
tar xzf %{SOURCE1}

# fix passenger boost for glibc >= 2.18
%if 0%{?fedora} >= 20
    %patch107 -p1 -b .glibc-long
%endif

%build
export EXTRA_CFLAGS="${CFLAGS:-%optflags} -Wno-deprecated"
export EXTRA_CXXFLAGS="${CXXFLAGS:-%optflags} -Wno-deprecated"

# Remove default optimization flags and use Phusion Passenger's recommended optimization flags.
export EXTRA_CFLAGS=`echo "$EXTRA_CFLAGS" | sed 's|-O2||g'`
export EXTRA_CXXFLAGS=`echo "$EXTRA_CXXFLAGS" | sed 's|-O2||g'`
export OPTIMIZE=yes
export USE_SELINUX=yes

export CACHING=false

# Speed up ccache (reduce I/O) by lightly compressing things.
# Always set these variables because pbuilder uses ccache transparently.
export CCACHE_COMPRESS=1
export CCACHE_COMPRESS_LEVEL=3

export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

# Build Passenger.
rake fakeroot \
    NATIVE_PACKAGING_METHOD=rpm \
    FS_PREFIX=%{_prefix} \
    FS_BINDIR=%{_bindir} \
    FS_SBINDIR=%{_sbindir} \
    FS_DATADIR=%{_datadir} \
    FS_LIBDIR=%{_libdir} \
    FS_DOCDIR=%{_docdir} \
    RUBYLIBDIR=%{ruby_vendorlibdir} \
    RUBYARCHDIR=%{ruby_vendorarchdir} \
    APACHE2_MODULE_PATH=%{_httpd_moddir}/mod_passenger.so

# Build Nginx core for Passenger Standalone.
nginx_config_opts=`ruby -Isrc/ruby_supportlib -rphusion_passenger -e 'PhusionPassenger.locate_directories; PhusionPassenger.require_passenger_lib "config/nginx_engine_compiler"; puts PhusionPassenger::Config::NginxEngineCompiler.configure_script_options'`
pushd nginx-%{nginx_version}
./configure --prefix=/tmp $nginx_config_opts --add-module=`pwd`/../src/nginx_module
make
popd

# Build SELinux policy modules.
%{__cp} %{SOURCE3} %{SOURCE4} .
%{__cp} %{SOURCE2} passenger.fc.tmp
%{__sed} -i "s|SUPPORT_BINARIES_DIR_MAIN|%{_libdir}/%{namespace}/support-binaries|g" passenger.fc.tmp
%{__sed} -i "s|SUPPORT_BINARIES_DIR_ALT|%{_prefix}/lib/%{namespace}/support-binaries|g" passenger.fc.tmp
uniq passenger.fc.tmp > passenger.fc
for selinuxvariant in %{selinux_variants}; do
    %{__make} -f %{_datadir}/selinux/devel/Makefile NAME=passenger
    %{__mv} passenger.pp passenger.pp.${selinuxvariant}
    %{__make} -f %{_datadir}/selinux/devel/Makefile NAME=passenger clean
done


%install
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

%{__rm} -rf %{buildroot}
%{__mkdir} %{buildroot}
%{__cp} -a pkg/fakeroot/* %{buildroot}/
%{__cp} nginx-%{nginx_version}/objs/nginx %{buildroot}%{_libdir}/%{namespace}/support-binaries/nginx-%{nginx_version}

# Install bootstrapping code into the executables and the Nginx config script.
./dev/install_scripts_bootstrap_code.rb --ruby %{passenger_ruby_libdir} \
    %{buildroot}%{_bindir}/* \
    %{buildroot}%{_sbindir}/* \
    `find %{buildroot} -name rack_handler.rb`
./dev/install_scripts_bootstrap_code.rb --nginx-module-config %{_bindir} %{buildroot}%{_datadir}/%{namespace}/ngx_http_passenger_module/config

# Install Apache config.
%{__mkdir_p} %{buildroot}%{_httpd_confdir} %{buildroot}%{_httpd_modconfdir}
%{__sed} -e 's|@PASSENGERROOT@|%{passenger_ruby_libdir}/phusion_passenger/locations.ini|g' %{SOURCE100} > passenger.conf
%if !(0%{?rhel} >= 7 || 0%{?fedora} >= 16)
    %{__sed} -i -e '/^# *Require all granted/d' passenger.conf
%endif

%if "%{_httpd_modconfdir}" == "%{_httpd_confdir}"
    %{__cat} %{SOURCE101} passenger.conf > passenger-combined.conf
    touch -r %{SOURCE100} passenger-combined.conf
    %{__install} -pm 0644 passenger-combined.conf %{buildroot}%{_httpd_confdir}/passenger.conf
%else
    touch -r %{SOURCE100} passenger.conf
    %{__install} -pm 0644 passenger.conf %{buildroot}%{_httpd_confdir}/passenger.conf
    %{__install} -pm 0644 %{SOURCE101} %{buildroot}%{_httpd_modconfdir}/10-passenger.conf
    touch -r %{SOURCE101} %{buildroot}%{_httpd_modconfdir}/10-passenger.conf
%endif

# Make our ghost log and run directories...
%{__mkdir_p} %{buildroot}%{_localstatedir}/log/passenger-analytics
%{__mkdir_p} %{buildroot}%{_localstatedir}/run/passenger-instreg
%{__mkdir_p} %{buildroot}%{_prefix}/lib/tmpfiles.d 
%if 0%{?rhel} >= 7 || 0%{?fedora} >= 16
    %{__install} -m 644 -p %{SOURCE102} \
        %{buildroot}%{_prefix}/lib/tmpfiles.d/passenger.conf
%endif

# logrotate
%{__mkdir_p} %{buildroot}%{_sysconfdir}/logrotate.d
%{__install} -pm 0644 %{SOURCE10} %{buildroot}%{_sysconfdir}/logrotate.d/passenger

# Install man pages into the proper location.
%{__mkdir_p} %{buildroot}%{_mandir}/man1
%{__mkdir_p} %{buildroot}%{_mandir}/man8
%{__cp} man/*.1 %{buildroot}%{_mandir}/man1
%{__cp} man/*.8 %{buildroot}%{_mandir}/man8

# Fix Python scripts with shebang which are not executable
%{__chmod} +x %{buildroot}%{_datadir}/%{namespace}/helper-scripts/wsgi-loader.py

# Install SELinux policy module.
for selinuxvariant in %{selinux_variants}; do
    %{__install} -d %{buildroot}%{_datadir}/selinux/${selinuxvariant}
    %{__install} -p -m 644 passenger.pp.${selinuxvariant} \
        %{buildroot}%{_datadir}/selinux/${selinuxvariant}/passenger.pp
done


%pre
policy_version=`/usr/sbin/sestatus | %{__grep} 'Policy version' | %{__sed} 's/.*: *//'`
if test "$policy_version" != "" && test "$policy_version" -lt 25; then
    kernel_version=`/bin/uname -r`
    echo >&2
    echo "   !!!! PASSENGER CANNOT BE INSTALLED: KERNEL TOO OLD !!!!" >&2
    echo >&2
    echo "   You are currently running kernel $kernel_version, with SELinux policy" >&2
    echo "   version $policy_version. However, Passenger's SELinux policy requires kernel >= 2.6.39," >&2
    echo "   with support for policy version >= 25." >&2
    echo >&2
    echo "   There are two ways to solve this problem:" >&2
    echo >&2
    echo "   Alternative 1: upgrade your kernel to at least 2.6.39, then reinstall" >&2
    echo "   Passenger." >&2
    echo >&2
    echo "   -OR-" >&2
    echo >&2
    echo "   Alternative 2: disable SELinux." >&2
    echo "   Edit /etc/selinux/config, set SELINUX=disabled, reboot, then" >&2
    echo "   reinstall Passenger." >&2
    echo >&2
    exit 1
fi

%post
for selinuxvariant in %{selinux_variants}; do
    /usr/sbin/semodule -s ${selinuxvariant} -i \
        %{_datadir}/selinux/${selinuxvariant}/passenger.pp &> /dev/null || :
done
/sbin/fixfiles -R %{package_name} restore || :
/sbin/restorecon -R %{_libdir}/%{namespace}/support-binaries || :

%postun
if [ $1 -eq 0 ] ; then
    for selinuxvariant in %{selinux_variants}; do
        /usr/sbin/semodule -s ${selinuxvariant} -r passenger &> /dev/null || :
    done
    /sbin/fixfiles -R %{package_name} restore || :
    [ -d %{_libdir}/%{namespace}/support-binaries ] && \
        /sbin/restorecon -R %{_libdir}/%{namespace}/support-binaries &> /dev/null || :
fi

%define fixupSelinuxPolicy() \
    /usr/sbin/semodule -s %1 -i %{_datadir}/selinux/%1/passenger.pp &> /dev/null || : \
    /sbin/fixfiles -R %{package_name} restore || : \
    /sbin/restorecon -R %{_libdir}/%{namespace}/support-binaries || :

%triggerin -- selinux-policy-minimum
%fixupSelinuxPolicy minimum

%triggerin -- selinux-policy-mls
%fixupSelinuxPolicy mls

%triggerin -- selinux-policy-targeted
%fixupSelinuxPolicy targeted


%files
%{_bindir}/*
%{_sbindir}/*
{'fraction_non_alphanumeric': 0.1475469368486037, 'fraction_numerical': 0.015760612993427025, 'mean_word_length': 5.308820160366552, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 106, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3499348', 'n_tokens_mistral': 10794, 'n_tokens_neox': 9870, 'n_words': 2205}