# Tests by default. No tests: rpm -ba --define 'dotests 0' *.spec
%{!?dotests: %define dotests 1}


%define perl_vendorarch %(eval "`%{_bindir}/perl -V:installvendorarch`"; echo $installvendorarch)
%define perl_vendorarch64 %(eval "`%{_bindir}/perl_64bit -V:installvendorarch`"; echo $installvendorarch)

%define nginx_uid 64600
%define nginx_gid 64600

%global  with_perl 0

%global  nginx_user          nginx
%global  nginx_group         %{nginx_user}
%global  nginx_home          /var/lib/%{name}
%global  nginx_home_tmp      %{nginx_home}/tmp
%global  nginx_confdir       /etc/%{name}
%global  nginx_datadir       %{_datadir}/%{name}
%global  nginx_logdir        /var/log/%{name}
%global  nginx_webroot       /var/%{name}/html

Name:              nginx
Version:           1.17.8
Release:           1

Summary:           A high performance web server and reverse proxy server
Group:             System Environment/Daemons
# BSD License (two clause)
# http://www.freebsd.org/copyright/freebsd-license.html
License:           BSD
URL:               http://nginx.org/

Source0:           http://nginx.org/download/%{name}-%{version}.tar.gz
Source1:           http://nginx.org/download/%{name}-%{version}.tar.gz.asc
Source2:           %{name}.logrotate
Source3:           %{name}.conf
Source4:           %{name}-default.conf
Source5:           %{name}-ssl.conf
Source6:           %{name}-virtual.conf
Source7:           %{name}.aix.init
Source100:         %{name}-index.html
Source102:         %{name}-logo.png
Source103:         %{name}-404.html
Source104:         %{name}-50x.html

Patch0:            %{name}-1.16.1-aix51-52.patch

BuildRequires:     GeoIP-devel >= 1.6.12
BuildRequires:     libgd-devel >= 2.2.5

BuildRequires:     libxslt-devel >= 1.1.32
BuildRequires:     libxml2-devel >= 2.9.9
BuildRequires:     pcre-devel >= 8.42

%if %{with_perl}
BuildRequires:     perl >= 5.24.1-1
%endif

BuildRequires:     zlib-devel >= 1.2.11

Requires:          GeoIP >= 1.6.12
Requires:          libgd >= 2.2.5
Requires:          libxslt >= 1.1.32
Requires:          libxml2 >= 2.9.9
Requires:          pcre >= 8.42
Requires:          zlib >= 1.2.11

Provides:          webserver


%description
Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
IMAP protocols, with a strong focus on high concurrency, performance and low
memory usage.


%prep
%setup -q


%build
# we must find our perl first
export PATH=/opt/freeware/bin:$PATH
export CC="gcc -maix64"
export CFLAGS="-DSYSV -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_AIX51 -D_ALL_SOURCE -DFUNCPROTO=15 -O2 -I/opt/freeware/include"
export LDFLAGS="-L/opt/freeware/lib64 -L/opt/freeware/lib  -Wl,-blibpath:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib"

# nginx does not utilize a standard configure script.  It has its own
# and the standard configure options cause the nginx configure script
# to error out.  This is is also the reason for the DESTDIR environment
# variable.
export DESTDIR=${RPM_BUILD_ROOT}
./configure \
    --prefix=%{nginx_datadir} \
    --sbin-path=%{_sbindir}/%{name} \
    --conf-path=%{nginx_confdir}/%{name}.conf \
    --error-log-path=%{nginx_logdir}/error.log \
    --http-log-path=%{nginx_logdir}/access.log \
    --http-client-body-temp-path=%{nginx_home_tmp}/client_body \
    --http-proxy-temp-path=%{nginx_home_tmp}/proxy \
    --http-fastcgi-temp-path=%{nginx_home_tmp}/fastcgi \
    --http-uwsgi-temp-path=%{nginx_home_tmp}/uwsgi \
    --http-scgi-temp-path=%{nginx_home_tmp}/scgi \
    --pid-path=/var/run/%{name}.pid \
    --lock-path=/var/locks/%{name} \
    --user=%{nginx_user} \
    --group=%{nginx_group} \
    --with-ipv6 \
   --with-http_ssl_module \
    --with-http_realip_module \
    --with-http_addition_module \
    --with-http_xslt_module \
    --with-http_image_filter_module \
    --with-http_geoip_module \
    --with-http_sub_module \
    --with-http_dav_module \
    --with-http_flv_module \
    --with-http_mp4_module \
    --with-http_gzip_static_module \
    --with-http_random_index_module \
    --with-http_secure_link_module \
    --with-http_degradation_module \
    --with-http_stub_status_module \
	--with-http_v2_module \
%if %{with_perl}
    --with-http_perl_module \
%endif
    --with-mail \
    --with-mail_ssl_module \
    --with-cc-opt="${CFLAGS} $(pcre-config --cflags)" \
    --with-ld-opt="${LDFLAGS}"

gmake %{?_smp_mflags} 
if [ "%{dotests}" == 1 ]
      then
          (gmake -k check || true)
      fi

%install
make install DESTDIR=${RPM_BUILD_ROOT} INSTALLDIRS=vendor

/usr/bin/strip -X64 ${RPM_BUILD_ROOT}%{_sbindir}/* || :

find ${RPM_BUILD_ROOT} -type f -name .packlist -exec rm -f '{}' \;
find ${RPM_BUILD_ROOT} -type f -name perllocal.pod -exec rm -f '{}' \;
find ${RPM_BUILD_ROOT} -type f -name '*.so' -exec chmod 0755 '{}' \;

# the manpage does not get installed anymore
mkdir -p ${RPM_BUILD_ROOT}%{_mandir}/man8
cp objs/%{name}.8 ${RPM_BUILD_ROOT}%{_mandir}/man8/%{name}.8
chmod 0644 ${RPM_BUILD_ROOT}%{_mandir}/man8/%{name}.8

mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d
cp %{SOURCE2} ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/%{name}
chmod 0644 ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/%{name}

mkdir -p ${RPM_BUILD_ROOT}%{nginx_confdir}/conf.d
cp %{SOURCE3} ${RPM_BUILD_ROOT}%{nginx_confdir}/%{name}.conf
chmod 0644 ${RPM_BUILD_ROOT}%{nginx_confdir}/%{name}.conf

cp %{SOURCE4} ${RPM_BUILD_ROOT}%{nginx_confdir}/conf.d/default.conf
cp %{SOURCE5} ${RPM_BUILD_ROOT}%{nginx_confdir}/conf.d/ssl.conf
cp %{SOURCE6} ${RPM_BUILD_ROOT}%{nginx_confdir}/conf.d/virtual.conf
chmod 0644 ${RPM_BUILD_ROOT}%{nginx_confdir}/conf.d/*.conf

mkdir -p ${RPM_BUILD_ROOT}%{nginx_home_tmp}
mkdir -p ${RPM_BUILD_ROOT}%{nginx_logdir}
mkdir -p ${RPM_BUILD_ROOT}%{nginx_webroot}

cp %{SOURCE100} ${RPM_BUILD_ROOT}%{nginx_webroot}/index.html
cp %{SOURCE102} ${RPM_BUILD_ROOT}%{nginx_webroot}
cp %{SOURCE103} ${RPM_BUILD_ROOT}%{nginx_webroot}/404.html
cp %{SOURCE104} ${RPM_BUILD_ROOT}%{nginx_webroot}/50x.html
chmod 0644 ${RPM_BUILD_ROOT}%{nginx_webroot}/*

mkdir -p ${RPM_BUILD_ROOT}/etc/rc.d/init.d
cp %{SOURCE7} ${RPM_BUILD_ROOT}/etc/rc.d/init.d/%{name}

mkdir -p ${RPM_BUILD_ROOT}/etc/rc.d/rc2.d
mkdir -p ${RPM_BUILD_ROOT}/etc/rc.d/rc3.d
ln -sf '../init.d/nginx' ${RPM_BUILD_ROOT}/etc/rc.d/rc2.d/S%{name}
ln -sf '../init.d/nginx' ${RPM_BUILD_ROOT}/etc/rc.d/rc2.d/K%{name}
ln -sf '../init.d/nginx' ${RPM_BUILD_ROOT}/etc/rc.d/rc3.d/S%{name}
ln -sf '../init.d/nginx' ${RPM_BUILD_ROOT}/etc/rc.d/rc3.d/K%{name}


%preun
if [ $1 = 0 ]; then
    /etc/rc.d/init.d/%{name} stop > /dev/null 2>&1
#fi
# remove "nginx" user and group
/usr/sbin/rmuser -p nginx || :
/usr/sbin/rmgroup nginx || :
fi

%pre
# add the "nginx" group only if it does not yet exist
result=`/usr/sbin/lsgroup nginx | /usr/bin/awk '{ print $1 }' 2>/dev/null`
if [[ "${result}" != "nginx" ]] ; then
    /usr/bin/mkgroup -A id=%{nginx_gid} nginx 2> /dev/null || :
fi
# add the "nginx" user only if it does not yet exist
result=`/usr/sbin/lsuser nginx | /usr/bin/awk '{ print $1 }' 2>/dev/null`
if [[ "${result}" != "nginx" ]] ; then
    /usr/bin/mkuser id=%{nginx_uid} pgrp='nginx' gecos='NGINX User' \
        login='false' rlogin='false' nginx 2> /dev/null || :
fi


%postun
if [ $1 -gt 1 ]; then
    /etc/rc.d/init.d/%{name} conrestart >/dev/null 2>&1 || :
fi


%clean
[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}


%files
%doc LICENSE CHANGES README
%{_sbindir}/nginx
%{_mandir}/man8/nginx.8
%{nginx_datadir}/
%dir %{nginx_confdir}
%dir %{nginx_confdir}/conf.d
%dir %{nginx_logdir}
%config(noreplace) %{nginx_confdir}/fastcgi.conf
%config(noreplace) %{nginx_confdir}/fastcgi.conf.default
%config(noreplace) %{nginx_confdir}/fastcgi_params
%config(noreplace) %{nginx_confdir}/fastcgi_params.default
%config(noreplace) %{nginx_confdir}/koi-utf
%config(noreplace) %{nginx_confdir}/koi-win
%config(noreplace) %{nginx_confdir}/mime.types
%config(noreplace) %{nginx_confdir}/mime.types.default
%config(noreplace) %{nginx_confdir}/nginx.conf
%config(noreplace) %{nginx_confdir}/nginx.conf.default
%config(noreplace) %{nginx_confdir}/scgi_params
%config(noreplace) %{nginx_confdir}/scgi_params.default
%config(noreplace) %{nginx_confdir}/uwsgi_params
%config(noreplace) %{nginx_confdir}/uwsgi_params.default
%config(noreplace) %{nginx_confdir}/win-utf
%config(noreplace) %{nginx_confdir}/conf.d/*.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/nginx
%attr(-,%{nginx_user},%{nginx_group}) %dir %{nginx_home}
%attr(-,%{nginx_user},%{nginx_group}) %dir %{nginx_home_tmp}
/etc/rc.d/init.d/%{name}
/etc/rc.d/rc2.d/S%{name}
/etc/rc.d/rc2.d/K%{name}
/etc/rc.d/rc3.d/S%{name}
/etc/rc.d/rc3.d/K%{name}
 %if %{with_perl}
%dir %{perl_vendorarch}/auto/nginx
%{perl_vendorarch}/nginx.pm
%{perl_vendorarch}/auto/nginx/nginx.so
%endif
%dir %{nginx_webroot}
%{nginx_webroot}/*


%changelog
* Wed Feb 12 2020 Baanu Tumma <btumma15@in.ibm.com> - 1.17.8-1
- Update to fix CVE CVE-2019-20372	 

* Tue Sep 03 2019 Harshita Jain <harjain9@in.ibm.com > -1.16.1-1
- Update to CVE-2019-9516 CVE-2019-9518  CVE-2019-9517 CVE-2019-9512 CVE-2019-9511 CVE-2019-9514 CVE-2019-9513 

* Fri Jun 07 2019 Harshita Jain <harjain9@in.ibm.com>- 1.15.8-2
- Rebuilt with libgd (Without libwebp support) 

* Fri Feb 15 2019 Harshita Jain <harjain9@in.ibm.com>- 1.15.8-1
- Initial port to AIX toolbox
 
* Thu Nov 08 2018 Michael Perzl <michael@perzl.org> - 1.15.6-1
- updated to version 1.15.6

* Fri Oct 05 2018 Michael Perzl <michael@perzl.org> - 1.15.5-1
- updated to version 1.15.5

* Fri Oct 05 2018 Michael Perzl <michael@perzl.org> - 1.15.4-1
- updated to version 1.15.4

* Wed Sep 19 2018 Michael Perzl <michael@perzl.org> - 1.15.3-1
- updated to version 1.15.3

* Mon Aug 06 2018 Michael Perzl <michael@perzl.org> - 1.15.2-1
- updated to version 1.15.2

* Wed Jul 04 2018 Michael Perzl <michael@perzl.org> - 1.15.1-1
- updated to version 1.15.1

* Mon Jun 11 2018 Michael Perzl <michael@perzl.org> - 1.15.0-1
- updated to version 1.15.0

* Mon Apr 30 2018 Michael Perzl <michael@perzl.org> - 1.14.0-1
- updated to version 1.14.0

* Mon Apr 30 2018 Michael Perzl <michael@perzl.org> - 1.13.12-1
- updated to version 1.13.12

* Mon Apr 30 2018 Michael Perzl <michael@perzl.org> - 1.13.11-1
- updated to version 1.13.11

* Mon Apr 30 2018 Michael Perzl <michael@perzl.org> - 1.13.10-1
- updated to version 1.13.10

* Mon Apr 30 2018 Michael Perzl <michael@perzl.org> - 1.13.9-1
- updated to version 1.13.9

* Thu Apr 26 2018 Michael Perzl <michael@perzl.org> - 1.13.8-1
- updated to version 1.13.8

* Fri Dec 01 2017 Michael Perzl <michael@perzl.org> - 1.13.7-1
- updated to version 1.13.7

* Mon Oct 16 2017 Michael Perzl <michael@perzl.org> - 1.13.6-1
- updated to version 1.13.6

* Tue Sep 05 2017 Michael Perzl <michael@perzl.org> - 1.13.5-1
- updated to version 1.13.5

* Fri Aug 11 2017 Michael Perzl <michael@perzl.org> - 1.13.4-1
- updated to version 1.13.4

* Fri Aug 11 2017 Michael Perzl <michael@perzl.org> - 1.13.3-1
- updated to version 1.13.3

* Tue Jul 04 2017 Michael Perzl <michael@perzl.org> - 1.13.2-1
- updated to version 1.13.2

* Thu Jun 01 2017 Michael Perzl <michael@perzl.org> - 1.13.1-1
- updated to version 1.13.1

* Thu Jun 01 2017 Michael Perzl <michael@perzl.org> - 1.13.0-1
- updated to version 1.13.0

* Thu Jun 01 2017 Michael Perzl <michael@perzl.org> - 1.12.0-1
- updated to version 1.12.0

* Thu Jun 01 2017 Michael Perzl <michael@perzl.org> - 1.11.13-1
- updated to version 1.11.13

* Thu Jun 01 2017 Michael Perzl <michael@perzl.org> - 1.11.12-1
- updated to version 1.11.12

* Thu Jun 01 2017 Michael Perzl <michael@perzl.org> - 1.11.11-1
- updated to version 1.11.11

* Wed Mar 08 2017 Michael Perzl <michael@perzl.org> - 1.11.10-1
- updated to version 1.11.10

* Mon Jan 30 2017 Michael Perzl <michael@perzl.org> - 1.11.9-1
- updated to version 1.11.9

* Fri Dec 30 2016 Michael Perzl <michael@perzl.org> - 1.11.8-1
- updated to version 1.11.8

* Tue Dec 13 2016 Michael Perzl <michael@perzl.org> - 1.11.7-1
- updated to version 1.11.7

* Tue Dec 13 2016 Michael Perzl <michael@perzl.org> - 1.11.6-1
- updated to version 1.11.6

* Mon Nov 21 2016 Michael Perzl <michael@perzl.org> - 1.11.5-2
- recompiled against latest versions

* Thu Oct 13 2016 Michael Perzl <michael@perzl.org> - 1.11.5-1
- updated to version 1.11.5

* Mon Sep 19 2016 Michael Perzl <michael@perzl.org> - 1.11.4-1
- updated to version 1.11.4

* Wed Jul 27 2016 Michael Perzl <michael@perzl.org> - 1.11.3-1
- updated to version 1.11.3

* Tue Jul 05 2016 Michael Perzl <michael@perzl.org> - 1.11.2-1
- updated to version 1.11.2

* Sun Jun 05 2016 Michael Perzl <michael@perzl.org> - 1.11.1-1
- updated to version 1.11.1

* Fri May 27 2016 Michael Perzl <michael@perzl.org> - 1.11.0-1
- updated to version 1.11.0

* Wed Apr 27 2016 Michael Perzl <michael@perzl.org> - 1.10.0-1
- updated to version 1.10.0

* Wed Apr 20 2016 Michael Perzl <michael@perzl.org> - 1.9.15-1
- updated to version 1.9.15

* Thu Apr 14 2016 Michael Perzl <michael@perzl.org> - 1.9.14-1
- updated to version 1.9.14

* Mon Apr 04 2016 Michael Perzl <michael@perzl.org> - 1.9.13-1
- updated to version 1.9.13

* Fri Mar 04 2016 Michael Perzl <michael@perzl.org> - 1.9.12-2
- compiled against latest version of openssl

* Wed Feb 24 2016 Michael Perzl <michael@perzl.org> - 1.9.12-1
- updated to version 1.9.12

* Sat Feb 13 2016 Michael Perzl <michael@perzl.org> - 1.9.11-1
- updated to version 1.9.11

* Sat Jan 30 2016 Michael Perzl <michael@perzl.org> - 1.9.10-1
- updated to version 1.9.10

* Tue Dec 22 2015 Michael Perzl <michael@perzl.org> - 1.9.9-1
- updated to version 1.9.9

* Tue Dec 22 2015 Michael Perzl <michael@perzl.org> - 1.9.8-1
- updated to version 1.9.8

* Sun Nov 29 2015 Michael Perzl <michael@perzl.org> - 1.9.7-1
- updated to version 1.9.7

* Sun Nov 29 2015 Michael Perzl <michael@perzl.org> - 1.9.6-1
- updated to version 1.9.6

* Fri Sep 25 2015 Michael Perzl <michael@perzl.org> - 1.9.5-1
- updated to version 1.9.5

* Sun Aug 23 2015 Michael Perzl <michael@perzl.org> - 1.9.4-1
- updated to version 1.9.4

* Thu Jul 16 2015 Michael Perzl <michael@perzl.org> - 1.9.3-1
- updated to version 1.9.3

* Mon Jun 22 2015 Michael Perzl <michael@perzl.org> - 1.9.2-1
- updated to version 1.9.2

* Tue Jun 09 2015 Michael Perzl <michael@perzl.org> - 1.9.1-1
- updated to version 1.9.1

* Wed May 13 2015 Michael Perzl <michael@perzl.org> - 1.9.0-1
- updated to version 1.9.0

* Mon Apr 13 2015 Michael Perzl <michael@perzl.org> - 1.7.12-1
- updated to version 1.7.12

* Thu Apr 02 2015 Michael Perzl <michael@perzl.org> - 1.7.11-1
- updated to version 1.7.11

* Wed Feb 18 2015 Michael Perzl <michael@perzl.org> - 1.7.10-1
- updated to version 1.7.10

* Wed Feb 18 2015 Michael Perzl <michael@perzl.org> - 1.7.9-1
- updated to version 1.7.9

* Mon Dec 08 2014 Michael Perzl <michael@perzl.org> - 1.7.8-1
- updated to version 1.7.8

* Wed Oct 29 2014 Michael Perzl <michael@perzl.org> - 1.7.7-1
- updated to version 1.7.7

* Wed Oct 01 2014 Michael Perzl <michael@perzl.org> - 1.7.6-1
- updated to version 1.7.6

* Thu Sep 18 2014 Michael Perzl <michael@perzl.org> - 1.7.5-1
- updated to version 1.7.5

* Tue Aug 12 2014 Michael Perzl <michael@perzl.org> - 1.7.4-1
- updated to version 1.7.4

* Tue Aug 12 2014 Michael Perzl <michael@perzl.org> - 1.7.3-1
- updated to version 1.7.3

* Mon Jun 23 2014 Michael Perzl <michael@perzl.org> - 1.7.2-1
- updated to version 1.7.2

* Wed May 28 2014 Michael Perzl <michael@perzl.org> - 1.7.1-1
- updated to version 1.7.1

* Sun Apr 27 2014 Michael Perzl <michael@perzl.org> - 1.7.0-1
- updated to version 1.7.0

* Sun Apr 27 2014 Michael Perzl <michael@perzl.org> - 1.5.13-1
- updated to version 1.5.13

* Thu Mar 27 2014 Michael Perzl <michael@perzl.org> - 1.5.12-1
- updated to version 1.5.12

* Fri Mar 14 2014 Michael Perzl <michael@perzl.org> - 1.5.11-1
- updated to version 1.5.11

* Wed Feb 05 2014 Michael Perzl <michael@perzl.org> - 1.5.10-1
- updated to version 1.5.10

* Wed Feb 05 2014 Michael Perzl <michael@perzl.org> - 1.5.9-1
- updated to version 1.5.9

* Mon Jan 20 2014 Michael Perzl <michael@perzl.org> - 1.5.8-1
- updated to version 1.5.8

* Wed Nov 20 2013 Michael Perzl <michael@perzl.org> - 1.5.7-1
- updated to version 1.5.7

* Fri Oct 11 2013 Michael Perzl <michael@perzl.org> - 1.5.6-1
- updated to version 1.5.6

* Fri Oct 11 2013 Michael Perzl <michael@perzl.org> - 1.5.5-1
- updated to version 1.5.5

* Fri Oct 11 2013 Michael Perzl <michael@perzl.org> - 1.5.4-1
- updated to version 1.5.4

* Fri Aug 23 2013 Michael Perzl <michael@perzl.org> - 1.5.3-1
- updated to version 1.5.3

* Mon Jul 08 2013 Michael Perzl <michael@perzl.org> - 1.5.2-1
- updated to version 1.5.2

* Mon Jun 24 2013 Michael Perzl <michael@perzl.org> - 1.5.1-1
- updated to version 1.5.1

* Wed May 08 2013 Michael Perzl <michael@perzl.org> - 1.5.0-1
- updated to version 1.5.0

* Wed May 08 2013 Michael Perzl <michael@perzl.org> - 1.4.1-1
- updated to version 1.4.1

* Fri May 03 2013 Michael Perzl <michael@perzl.org> - 1.4.0-1
- updated to version 1.4.0

* Fri May 03 2013 Michael Perzl <michael@perzl.org> - 1.3.16-1
- updated to version 1.3.16

* Thu Apr 04 2013 Michael Perzl <michael@perzl.org> - 1.3.15-1
- updated to version 1.3.15

* Tue Mar 26 2013 Michael Perzl <michael@perzl.org> - 1.3.14-1
- updated to version 1.3.14

* Wed Feb 20 2013 Michael Perzl <michael@perzl.org> - 1.3.13-1
- updated to version 1.3.13

* Mon Jan 28 2013 Michael Perzl <michael@perzl.org> - 1.3.11-1
- updated to version 1.3.11

* Tue Jan 08 2013 Michael Perzl <michael@perzl.org> - 1.3.10-1
- updated to version 1.3.10

* Wed Oct 31 2012 Michael Perzl <michael@perzl.org> - 1.3.8-1
- updated to version 1.3.8

* Wed Oct 31 2012 Michael Perzl <michael@perzl.org> - 1.3.7-1
- updated to version 1.3.7

* Sun Oct 28 2012 Michael Perzl <michael@perzl.org> - 1.2.4-1
- first version for AIX5L v5.1 and higher
