%define webroot /var/www/lighttpd

%if %{?_dist_release} == "vl6"
%define owneruser lighttpd
%define ownergroup lighttpd
%else
%define owneruser www-data
%define ownergroup www-data
%endif

Summary: Lightning fast webserver with light system requirements
Summary(ja): 少ないシステムリソースで動く超高速なウェブサーバ
Name: lighttpd
Version: 1.4.53
Release: 1%{?_dist_release}
License: BSD
Group: System Environment/Daemons
URL: http://www.lighttpd.net/
Source0: http://www.lighttpd.net/download/lighttpd-%{version}.tar.xz
Source1: lighttpd.logrotate
Source2: php.d-lighttpd.ini
Source3: lighttpd.init
Source4: sysconfig.lighttpd
Source10: index.html
Source11: http://www.lighttpd.net/favicon.ico
Source13: http://www.lighttpd.net/light_button.png
Source14: http://www.lighttpd.net/light_logo.png
# config file patches
## for vl7 and later
Patch0: lighttpd-1.4.31-vine.patch
## for vl6
Patch1: lighttpd-1.4.31-vine6.patch
# security patch(es)
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Requires(pre): shadow-utils
%if %{?_dist_release} != "vl6"
Requires(pre): www-common
%endif
Requires(post): chkconfig
Requires(preun): chkconfig
Requires(postun): chkconfig
BuildRequires: openssl-devel, pcre-devel, bzip2-devel, zlib-devel, gcc-c++
%{?_with_ldap:BuildRequires: openldap-devel}
BuildRequires: libxcrypt-devel
BuildRequires: gamin-devel
BuildRequires: gdbm-devel
BuildRequires: lua-devel

%description
Secure, fast, compliant and very flexible web-server which has been optimized
for high-performance environments. It has a very low memory footprint compared
to other webservers and takes care of cpu-load. Its advanced feature-set
(FastCGI, CGI, Auth, Output-Compression, URL-Rewriting and many more) make
it the perfect webserver-software for every server that is suffering load
problems.

Available rpmbuild rebuild options :
--with : memcache webdavprops ldap
--without: lua

%package mod_mysql_vhost
Summary: Virtual host module for lighttpd that uses a MySQL database
Group: System Environment/Daemons
Requires: %{name} = %{version}
BuildRequires: libmariadb-devel

%description mod_mysql_vhost
Virtual host module for lighttpd that uses a MySQL database.


%package fastcgi
Summary: FastCGI module and spawning helper for lighttpd and PHP configuration
Group: System Environment/Daemons
Requires: %{name} = %{version}
Requires: spawn-fcgi

%description fastcgi
This package contains the spawn-fcgi helper for lighttpd's automatic spawning
of local FastCGI programs. Included is also a PHP .ini file to change a few
defaults needed for correct FastCGI behavior.
Note that for FastCGI to work with PHP, you will most likely need to find a
tweaked PHP package (--enable-fastcgi and --enable-discard-path added) or
recompile PHP yourself.


%prep
%setup -q
%if %{?_dist_release} == "vl6"
%patch1 -p1 -b .vine6
%else
%patch0 -p1 -b .vine
%endif

%build
%configure \
    --libdir="%{_libdir}/lighttpd" \
    --with-mysql \
    %{?_with_ldap:--with-ldap} \
    --with-openssl \
    --with-fam \
    --with-gdbm \
    --with-pcre \
    %{?_with_memcache:--with-memcache} \
    %{?_with_webdavprops:--with-webdav-props} \
    %{?_with_webdavlocks:--with-webdav-locks} \
    %{?!_without_lua:--with-lua}
%{__make}


%install
%{__rm} -rf %{buildroot}
%{__make} install DESTDIR=%{buildroot}

# Install included init script and sysconfig entry
%{__install} -D -p -m 0755 %{SOURCE3} \
    %{buildroot}%{_sysconfdir}/rc.d/init.d/lighttpd
%{__install} -D -p -m 0644 %{SOURCE4} \
    %{buildroot}%{_sysconfdir}/sysconfig/lighttpd

# Install (*patched above*) sample config file
%{__install} -D -p -m 0640 doc/config/lighttpd.conf \
    %{buildroot}%{_sysconfdir}/lighttpd/lighttpd.conf
%{__install} -D -p -m 0640 doc/config/modules.conf \
    %{buildroot}%{_sysconfdir}/lighttpd/modules.conf

mkdir -p %{buildroot}%{_sysconfdir}/lighttpd/conf.d/
%{__install} -D -p -m 0640 doc/config/conf.d/*.conf \
    %{buildroot}%{_sysconfdir}/lighttpd/conf.d/
mkdir -p %{buildroot}%{_sysconfdir}/lighttpd/vhosts.d/
%{__install} -D -p -m 0640 doc/config/vhosts.d/vhosts.template \
    %{buildroot}%{_sysconfdir}/lighttpd/vhosts.d/

# Install our own logrotate entry
%{__install} -D -p -m 0644 %{SOURCE1} \
    %{buildroot}%{_sysconfdir}/logrotate.d/lighttpd

# Install our own php.d ini file
%{__install} -D -p -m 0644 %{SOURCE2} \
    %{buildroot}%{_sysconfdir}/php.d/lighttpd.ini

# Install our own init script
%{__install} -D -p -m 0755 %{SOURCE3} \
    %{buildroot}%{_sysconfdir}/rc.d/init.d/lighttpd

# Install our own default web page and images
%{__mkdir_p} %{buildroot}%{webroot}
%{__install} -p -m 0644 %{SOURCE10} %{SOURCE11} %{SOURCE13} \
    %{SOURCE14} \
    %{buildroot}%{webroot}/

# Install empty log directory to include
%{__mkdir_p} %{buildroot}%{_var}/log/lighttpd

# Install empty run directory to include (for the example fastcgi socket)
%{__mkdir_p} %{buildroot}%{_var}/run/lighttpd


%clean
%{__rm} -rf %{buildroot}

%if %{?_dist_release} == "vl6"
%pre
/usr/sbin/useradd -s /sbin/nologin -M -r -d %{webroot} \
    -c "lighttpd web server" lighttpd &>/dev/null || :
%endif

%post
/sbin/chkconfig --add lighttpd

%preun
if [ $1 -eq 0 ]; then
  /sbin/service lighttpd stop &>/dev/null || :
  /sbin/chkconfig --del lighttpd
fi

%postun
if [ $1 -ge 1 ]; then
    /sbin/service lighttpd condrestart &>/dev/null || :
fi


%files
%defattr(-, root, root, 0755)
%doc AUTHORS NEWS COPYING README
%doc doc/config/lighttpd.conf
%dir %{_sysconfdir}/lighttpd/
%config(noreplace) %{_sysconfdir}/lighttpd/lighttpd.conf
%config(noreplace) %{_sysconfdir}/lighttpd/modules.conf
%config(noreplace) %{_sysconfdir}/lighttpd/conf.d/*
%config(noreplace) %{_sysconfdir}/lighttpd/vhosts.d/*
%config(noreplace) %{_sysconfdir}/logrotate.d/lighttpd
%config(noreplace) %{_sysconfdir}/sysconfig/lighttpd
%{_sysconfdir}/rc.d/init.d/lighttpd
%{_sbindir}/lighttpd
%{_sbindir}/lighttpd-angel
%{_libdir}/lighttpd/
%exclude %{_libdir}/lighttpd/*.la
%exclude %{_libdir}/lighttpd/mod_fastcgi.so
%exclude %{_libdir}/lighttpd/mod_mysql_vhost.so
%exclude %{_sysconfdir}/lighttpd/conf.d/fastcgi.conf
%exclude %{_sysconfdir}/lighttpd/conf.d/mysql_vhost.conf
%{_mandir}/man8/lighttpd.8*
%{_mandir}/man8/lighttpd-angel.8*
%attr(0750, %{owneruser}, %{ownergroup}) %{_var}/log/lighttpd/
%{webroot}/

%files mod_mysql_vhost
%defattr(-, root, root, 0755)
%dir %{_libdir}/lighttpd/
%{_sysconfdir}/lighttpd/conf.d/mysql_vhost.conf
%{_libdir}/lighttpd/mod_mysql_vhost.so

%files fastcgi
%defattr(-, root, root, 0755)
%config(noreplace) %{_sysconfdir}/php.d/lighttpd.ini
%dir %{_libdir}/lighttpd/
%{_libdir}/lighttpd/mod_fastcgi.so
%{_sysconfdir}/lighttpd/conf.d/fastcgi.conf


%changelog
* Mon May 13 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.4.53-1
- new upstream release.
- added BR:libxcrypt-devel.
- dropped Patch1001.

* Sun May 15 2016 Yoji TOYODA <bsyamato@sea.plala.or.jp> 1.4.33-2
- rebuild with openssl-1.0.2

* Sun Jan  5 2014 IWAI, Masaharu <iwaim.sub@gmail.com> 1.4.33-1
- update to 1.4.33
- add CVE-2013-4508 patch (Patch1001)
- require www-common without vl6
- drop outdated mod_mysql_vhost document
 - see upstream #2248: http://redmine.lighttpd.net/issues/2248
- come back useradd pre script for Vine Linux 6

* Thu Nov 29 2012 Daisuke SUZUKI <daisuke@linux.or.jp> 1.4.32-1
- new upstream release

* Wed Oct 24 2012 Daisuke SUZUKI <daisuke@linux.or.jp> 1.4.31-1
- update to 1.4.31
- build with pcre-8.31
- require www-common, change docroot owner to www-data

* Sun Feb 06 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 1.4.22-2
- rebuild with openssl-1.0.0c

* Fri Jun 05 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 1.4.22-1
- new upstream release
- build with lua, add BR: lua-devel
- update init script

* Fri May 22 2009 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.4.20-2
- rebuilt with MySQL-5.1.34.

* Wed Oct 08 2008 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 1.4.20-1
- updated to 1.4.20 release with many bug/security fixes, including:
  - CVE-2008-4298: fix memory leak in request header handling
  - CVE-2008-4360: fix mod_userdir information disclosure
  - CVE-2008-4359: fix bypassing rewrite/redirect rules with encoded urls
  - CVE-2008-1531: fix DoS of ssl connections
- modified Patch0 for version 1.4.20
- add %{_sbindir}/lighttpd-angel to the filelist

* Fri Oct 03 2008 Shu KONNO <owa@bg.wakwak.com> 1.4.16-1vl5
- applied new versioning policy, spec in utf-8

* Tue Jul 31 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 1.4.16-0vl1
- new upstream release

* Fri Nov 03 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 1.4.13-0vl1
- initial build for Vine Linux

* Wed Oct 11 2006 Matthias Saou <http://freshrpms.net/> 1.4.13-1
- Update to 1.4.13, which contains the previous fix.

* Tue Oct  3 2006 Matthias Saou <http://freshrpms.net/> 1.4.12-3
- Include fix for segfaults (lighttpd bug #876, changeset 1352).

* Mon Sep 25 2006 Matthias Saou <http://freshrpms.net/> 1.4.12-1
- Update to 1.4.12 final.

* Fri Sep 22 2006 Matthias Saou <http://freshrpms.net/> 1.4.12-0.1.r1332
- Update to latest 1.4.12 pre-release, fixes SSL issues and other bugs.
- Update powered_by_fedora.png to the new logo.

* Mon Aug 28 2006 Matthias Saou <http://freshrpms.net/> 1.4.11-2
- FC6 rebuild.

* Thu Mar  9 2006 Matthias Saou <http://freshrpms.net/> 1.4.11-1
- Update to 1.4.11.

* Mon Mar  6 2006 Matthias Saou <http://freshrpms.net/> 1.4.10-2
- FC5 rebuild.

* Wed Feb  8 2006 Matthias Saou <http://freshrpms.net/> 1.4.10-1
- Update to 1.4.10.
- Remove now included fix.

* Wed Jan 25 2006 Matthias Saou <http://freshrpms.net/> 1.4.9-2
- Add mod_fastcgi-fix patch to fix crash on backend overload.

* Mon Jan 16 2006 Matthias Saou <http://freshrpms.net/> 1.4.9-1
- Update to 1.4.9.

* Wed Nov 23 2005 Matthias Saou <http://freshrpms.net/> 1.4.8-1
- Update to 1.4.8.

* Fri Nov  4 2005 Matthias Saou <http://freshrpms.net/> 1.4.7-1
- Update to 1.4.7.

* Wed Oct 12 2005 Matthias Saou <http://freshrpms.net/> 1.4.6-1
- Update to 1.4.6.

* Mon Oct  3 2005 Matthias Saou <http://freshrpms.net/> 1.4.5-1
- Update to 1.4.5.
- Disable gamin/fam support for now, it does not work.

* Tue Sep 27 2005 Matthias Saou <http://freshrpms.net/> 1.4.4-3
- Update to current SVN to check if it fixes the remaining load problems.

* Wed Sep 21 2005 Matthias Saou <http://freshrpms.net/> 1.4.4-2
- Patch to SVN 722 revision : Fixes a crash in mod_mysql_vhost and a problem
  with keepalive and certain browsers.

* Mon Sep 19 2005 Matthias Saou <http://freshrpms.net/> 1.4.4-1
- Update to 1.4.4 final.
- Enable ldap auth, gdbm and gamin/fam support by default.

* Thu Sep 15 2005 Matthias Saou <http://freshrpms.net/> 1.4.4-0
- Update to 1.4.4 pre-release (fixes another fastcgi memleak).
- Enable lua (cml module) by default.
- Add --with-webdav-props conditional option.

* Tue Sep 13 2005 Matthias Saou <http://freshrpms.net/> 1.4.3-2
- Include lighttpd-1.4.3-stat_cache.patch to fix memleak.

* Fri Sep  2 2005 Matthias Saou <http://freshrpms.net/> 1.4.3-1.1
- Rearrange the included index.html to include the new logo, button and
  favicon from lighttpd.net.

* Fri Sep  2 2005 Matthias Saou <http://freshrpms.net/> 1.4.3-1
- Update to 1.4.3.
- No longer override libdir at make install stage, use DESTDIR instead, as
  the resulting binary would now have referenced to %%{buildroot} :-(

* Tue Aug 30 2005 Matthias Saou <http://freshrpms.net/> 1.4.2-1
- Update to 1.4.2.

* Mon Aug 22 2005 Matthias Saou <http://freshrpms.net/> 1.4.1-1
- Update to 1.4.1.

* Sun Aug 21 2005 Matthias Saou <http://freshrpms.net/> 1.4.0-1
- Update to 1.4.0.
- Add conditional of gamin, gdbm, memcache and lua options.

* Mon Aug  1 2005 Matthias Saou <http://freshrpms.net/> 1.3.16-2
- Update to 1.3.16, rebuild.

* Mon Jul 18 2005 Matthias Saou <http://freshrpms.net/> 1.3.15-1
- Update to 1.3.15.

* Mon Jun 20 2005 Matthias Saou <http://freshrpms.net/> 1.3.14-1
- Update to 1.3.14.

* Sun May 22 2005 Jeremy Katz <katzj@redhat.com> - 1.3.13-5
- rebuild on all arches

* Mon Apr  4 2005 Matthias Saou <http://freshrpms.net/> 1.3.13-4
- Change signal sent from the logrotate script from USR1 to HUP, as that's the
  correct one.

* Fri Apr  1 2005 Michael Schwendt <mschwendt[AT]users.sf.net> 1.3.13-2
- Include /etc/lighttpd directory.

* Sun Mar  6 2005 Matthias Saou <http://freshrpms.net/> 1.3.13-1
- Update to 1.3.13.

* Wed Mar  2 2005 Matthias Saou <http://freshrpms.net/> 1.3.12-1
- Update to 1.3.12.
- Remove obsolete empty_cgi_handler patch.

* Tue Mar  1 2005 Matthias Saou <http://freshrpms.net/> 1.3.11-2
- Add missing defattr to sub-packages (#150018).

* Mon Feb 21 2005 Matthias Saou <http://freshrpms.net/> 1.3.11-0
- Update to 1.3.11.
- Remove cleanconf and init.d patches (merged upstream).
- Add empty_cgi_handler patch.

* Fri Feb 18 2005 Matthias Saou <http://freshrpms.net/> 1.3.10-0
- Split off -fastcgi sub-package.
- Include php.d entry to set sane FastCGI defaults.

* Wed Feb 16 2005 Matthias Saou <http://freshrpms.net/> 1.3.10-0
- Spec file cleanup for freshrpms.net/Extras.
- Compile OpenSSL support unconditionally.
- Put modules in a subdirectory of libdir.
- Don't include all of libdir's content to avoid debuginfo content.
- Add optional LDAP support.
- Add patch to change the default configuration.
- Add dedicated lighttpd user/group creation.
- Add logrotate entry.
- Include a nice little default page for the default setup.
- Split off mod_mysql_vhost sub-package, get dep only there.
- Use webroot in /srv by default.
- Exclude .la files, I doubt anyone will need them.

* Thu Sep 30 2004 <jan@kneschke.de> 1.3.1
- upgraded to 1.3.1

* Tue Jun 29 2004 <jan@kneschke.de> 1.2.3
- rpmlint'ed the package
- added URL
- added (noreplace) to start-script
- change group to Networking/Daemon (like apache)

* Sun Feb 23 2003 <jan@kneschke.de>
- initial version