# Define variables to use in conditionals
%define use_systemd 0

%define use_systemd 0

%global __python %{__python3}

Summary:        An advanced IRC bouncer
Name:           znc
Version:        1.0
Release:        2%{?_dist_release}
License:        GPLv2 with exceptions
Group:          System Environment/Daemons
URL:            http://znc.in
Source0:        http://znc.in/releases/znc-1.0.tar.gz

Packager:       tomop

%if %{use_systemd}
Source1:        znc.service
%endif

%if !%{use_systemd}
Source1:        znc.init
%endif

# git clone https://github.com/znc/znc.git
# cd znc
# git archive --prefix=znc/ HEAD | xz > ../znc-0.097.tar.xz

BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires:  gcc-c++ perl
BuildRequires:  openssl-devel >= 0.9.8
BuildRequires:  cyrus-sasl-devel
#BuildRequires:  c-ares-devel
BuildRequires:  automake
BuildRequires:  tcl perl(ExtUtils::Embed)
Obsoletes:      znc-extra <= %{version}-%{release}

%if %{use_systemd}
BuildRequires: systemd-units
%endif
Requires(pre):  shadow-utils
%if %{use_systemd}
Requires(post): systemd-units
Requires(post): systemd-sysv
Requires(preun): systemd-units
Requires(postun): systemd-units
%endif

%if !%{use_systemd}
Requires(post): chkconfig
Requires(preun): chkconfig
# This is for /sbin/service
Requires(preun): initscripts
%endif

%description
ZNC is an IRC bouncer with many advanced features like detaching,
multiple users, per channel playback buffer, SSL, IPv6, transparent
DCC bouncing, Perl and C++ module support to name a few.

%package devel
Summary:        Development files needed to compile ZNC modules
Group:          Development/Libraries
Requires:       %{name} = %{version}-%{release} pkgconfig
Requires:       openssl-devel glibc-devel
#Requires:       c-ares-devel
BuildRequires: pkgconfig

%description devel
All includes and program files you need to compile your own znc
modules.

%package modtcl
Summary:       TCL module for ZNC
Group:         Development/Libraries
Requires:      %{name} = %{version}-%{release}
Requires:      tcl

%description modtcl
TCL module for ZNC

%prep
%setup -q -n %{name}-%{version}
#%setup -q -n znc-1.0-beta1
#%patch0 -p1
%__perl -pi.add_release -e 's|(?<="ZNC \%1\.3f)|-%{release}|' znc.cpp
chmod -x modules/q.cpp

%build
%configure \
     --with-module-prefix=%{_libdir}/znc \
     --enable-ipv6 --enable-sasl --disable-perl --enable-tcl
%__make %{?_smp_mflags}

%pre
#%if %{use_systemd}
getent group znc >/dev/null || groupadd -r znc
getent passwd znc >/dev/null || \
    useradd -r -g znc -d /var/lib/znc -s /sbin/nologin \
    -c "Account for ZNC to run as" znc
mkdir -p /var/lib/znc
chown znc:znc /var/lib/znc
#exit 0
#%endif

%install
%__rm -Rf "%{buildroot}"
%__make install DESTDIR="%{buildroot}"
%if %{use_systemd}
mkdir -p %buildroot%{_unitdir}
install -m 0644 %{SOURCE1} %buildroot%{_unitdir}/znc.service
%endif
%if !%{use_systemd}
mkdir -p %buildroot%{_initrddir}
install -Dp -m0755 %{SOURCE1} %{buildroot}%{_initrddir}/znc
%endif

%clean
%__rm -Rf "%{buildroot}"

%post

%if %{use_systemd}
if [ $1 -eq 1 ] ; then
    # Initial installation 
    /bin/systemctl daemon-reload >/dev/null 2>&1 || :
fi
%endif

%if !%{use_systemd}
# This adds the proper /etc/rc*.d links for the script
/sbin/chkconfig --add znc
%endif

%postun

%if %{use_systemd}
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
if [ $1 -ge 1 ] ; then
    # Package upgrade, not uninstall
    /bin/systemctl try-restart znc.service >/dev/null 2>&1 || :
fi
%endif

%if !%{use_systemd}
if [ "$1" -ge "1" ] ; then
    /sbin/service znc condrestart >/dev/null 2>&1 || :
fi
%endif

%preun

%if %{use_systemd}
if [ $1 -eq 0 ] ; then
    # Package removal, not upgrade
    /bin/systemctl --no-reload disable znc.service > /dev/null 2>&1 || :
    /bin/systemctl stop znc.service > /dev/null 2>&1 || :
fi
%endif

%if !%{use_systemd}
if [ $1 -eq 0 ] ; then
    /sbin/service znc stop >/dev/null 2>&1 || :
    /sbin/chkconfig --del znc || :
fi
%endif

%files
%defattr(-,root,root)
%doc AUTHORS LICENSE LICENSE.OpenSSL README.md
%{_bindir}/znc
%{_mandir}/man1/*
%{_libdir}/znc/adminlog.so
%{_libdir}/znc/autoattach.so
%{_libdir}/znc/autocycle.so
%{_libdir}/znc/autoop.so
%{_libdir}/znc/autoreply.so
%{_libdir}/znc/autovoice.so
%{_libdir}/znc/awaynick.so
%{_libdir}/znc/awaystore.so
%{_libdir}/znc/block_motd.so
%{_libdir}/znc/blockuser.so
%{_libdir}/znc/bouncedcc.so
%{_libdir}/znc/buffextras.so
%{_libdir}/znc/cert.so
%{_libdir}/znc/certauth.so
%{_libdir}/znc/chansaver.so
%{_libdir}/znc/charset.so
%{_libdir}/znc/clearbufferonmsg.so
%{_libdir}/znc/clientnotify.so
%{_libdir}/znc/controlpanel.so
%{_libdir}/znc/crypt.so
%{_libdir}/znc/ctcpflood.so
#%{_libdir}/znc/cyrusauth.so
%{_libdir}/znc/dcc.so
%{_libdir}/znc/disconkick.so
%{_libdir}/znc/fail2ban.so
%{_libdir}/znc/flooddetach.so
%{_libdir}/znc/identfile.so
%{_libdir}/znc/imapauth.so
%{_libdir}/znc/keepnick.so
%{_libdir}/znc/kickrejoin.so
%{_libdir}/znc/lastseen.so
%{_libdir}/znc/listsockets.so
%{_libdir}/znc/log.so
%{_libdir}/znc/missingmotd.so
%{_libdir}/znc/nickserv.so
%{_libdir}/znc/notes.so
%{_libdir}/znc/notify_connect.so
%{_libdir}/znc/partyline.so
%{_libdir}/znc/perform.so
%{_libdir}/znc/q.so
%{_libdir}/znc/raw.so
%{_libdir}/znc/route_replies.so
%{_libdir}/znc/sample.so
%{_libdir}/znc/sasl.so
%{_libdir}/znc/savebuff.so
%{_libdir}/znc/schat.so
%{_libdir}/znc/send_raw.so
%{_libdir}/znc/shell.so
%{_libdir}/znc/simple_away.so
%{_libdir}/znc/stickychan.so
%{_libdir}/znc/watch.so
%{_libdir}/znc/webadmin.so
%{_datadir}/znc/
%if %{use_systemd}
%{_unitdir}/znc.service
%endif
%if !%{use_systemd}
%{_initrddir}/znc
%endif

%files devel
%defattr(-,root,root)
%{_bindir}/znc-buildmod
#%{_bindir}/znc-config
%{_libdir}/pkgconfig/%{name}.pc
%{_includedir}/znc/

%files modtcl
%defattr(-,root,root)
%{_libdir}/znc/modtcl.so

%changelog
* Tue Mar 12 2013 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.0-2
- initial build for Vine Linux.

* Tue Nov 13 2012 Nick Bebout <nb@fedoraproject.org> - 1.0-1
- Update to 1.0

* Thu Oct 18 2012 Nick Bebout <nb@fedoraproject.org> - 1.0-0.2.beta1
- Update to 1.0-beta1

* Thu Sep 13 2012 Nick Bebout <nb@fedoraproject.org> - 1.0-0.1.alpha1
- Update to 1.0-alpha1

* Sun Jul 22 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.206-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild

* Mon Apr 16 2012 Nick Bebout <nb@fedoraproject.org> - 0.206-1
- Upgrade to 0.206

* Tue Feb 28 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.204-4
- Rebuilt for c++ ABI breakage

* Mon Jan 23 2012 Nick Bebout <nb@fedoraproject.org> - 0.204-2
- Add init script for EPEL

* Mon Jan 23 2012 Nick Bebout <nb@fedoraproject.org> - 0.204-1
- Update to 0.204 to fix security issue CVE-2012-0033

* Mon Jan 09 2012 Nick Bebout <nb@fedoraproject.org> - 0.202-2
- Add glibc-devel, openssl-devel, c-ares-devel to requires for
- znc-devel so znc-buildmod will work

* Sun Sep 25 2011 Nick Bebout <nb@fedoraproject.org> - 0.202-1
- Update to 0.202

* Tue Aug 23 2011 Nick Bebout <nb@fedoraproject.org> - 0.200-1
- Update to 0.200

* Mon Aug 15 2011 Nick Bebout <nb@fedoraproject.org> - 0.200-0.5.rc1
- Don't create the znc user on Fedora 14 and lower and on EPEL

* Mon Aug 15 2011 Nick Bebout <nb@fedoraproject.org> - 0.200-0.4.rc1
- Change znc's homedir to /var/lib/znc

* Sun Aug 14 2011 Nick Bebout <nb@fedoraproject.org> - 0.200-0.3.rc1
- Re-add modpython, it somehow got disabled accidentally
- Also re-add modperl, it works now

* Sun Aug 14 2011 Nick Bebout <nb@fedoraproject.org> - 0.200-0.2.rc1
- Create /home/znc upon install

* Sat Aug 13 2011 Nick Bebout <nb@fedoraproject.org> - 0.200-0.1.rc1
- Update to 0.200-rc1

* Sat Aug 6 2011 Nick Bebout <nb@fedoraproject.org> - 0.2-0.2.beta1
- Update to 0.2-beta1, disable perl for now

* Fri Aug 5 2011 Nick Bebout <nb@fedoraproject.org> - 0.2-0.1.alpha1
- Update to 0.2-alpha1

* Mon Aug 1 2011 Nick Bebout <nb@fedoraproject.org> - 0.099-0.1.20110801git
- Update to latest git

* Sat Apr 2 2011 Nick Bebout <nb@fedoraproject.org> - 0.098-2
- Add provides for ZNC::Module to znc-modperl

* Tue Mar 29 2011 Nick Bebout <nb@fedoraproject.org> - 0.098-1
- Update to znc-0.098

* Sat Mar 12 2011 Nick Bebout <nb@fedoraproject.org> - 0.098-0.3.rc1
- Update to znc-0.098-rc1

* Wed Mar 02 2011 Nick Bebout <nb@fedoraproject.org> - 0.098-0.2.beta
- Update to znc-0.098-beta

* Wed Feb 23 2011 Nick Bebout <nb@fedoraproject.org> - 0.098-0.1.alpha1
- Update to znc 0.098-alpha1

* Tue Feb 15 2011 Nick Bebout <nb@fedoraproject.org> - 0.097-8.20110215git
- Update to latest git

* Wed Feb 09 2011 Nick Bebout <nb@fedoraproject.org> - 0.097-7.svn2277
- Update to svn2277

* Mon Jan 24 2011 Nick Bebout <nb@fedoraproject.org> - 0.097-6.svn2272
- Update to svn2272

* Mon Jan 17 2011 Nick Bebout <nb@fedoraproject.org> - 0.097-5.svn2269
- Update to svn2269

* Fri Jan 7 2011 Nick Bebout <nb@fedoraproject.org> - 0.097-4.svn2255
- Update to svn2255

* Mon Jan  3 2011 David Malcolm <dmalcolm@redhat.com> - 0.097-3.svn2214
- rebuild for newer python3 (see rhbz#666429)

* Fri Dec 24 2010 Nick Bebout <nb@fedoraproject.org> - 0.097-2.svn2214
- Patch has been upstreamed, update to svn2214

* Wed Dec 22 2010 Nick Bebout <nb@fedoraproject.org> - 0.097-1.svn2213
- Update to znc 0.097-svn2213 which also adds modpython

* Sun Nov 7 2010 Nick Bebout <nb@fedoraproject.org> - 0.096-2
- Build TCL module, move modperl and modtcl to separate subpackages

* Sat Nov 6 2010 Nick Bebout <nb@fedoraproject.org> - 0.096-1
- Update to znc 0.096

* Fri Sep 10 2010 Nick Bebout <nb@fedoraproject.org> - 0.094-1
- Update to znc 0.094

* Tue Aug 10 2010 Nick Bebout <nb@fedoraproject.org> - 0.093-2.svn2101
- Update to znc 0.093.svn2101 to fix CVE-2010-2812 and CVE-2010-2934

* Tue Aug 3 2010 Nick Bebout <nb@fedoraproject.org> - 0.093-1.svn2098
- Update to znc 0.093 svn2098

* Wed Jul 14 2010 Nick Bebout <nb@fedoraproject.org> - 0.092-1
- Update to znc 0.092

* Wed Jun 16 2010 Nick Bebout <nb@fedoraproject.org> - 0.090-2
- Backport r2026 of ZNC subversion repo to fix bug 603915
- NULL pointer dereference flaw leads to segfault under certain conditions

* Sun Jun 06 2010 Nick Bebout <nb@fedoraproject.org> - 0.090-1
- Update to znc 0.090

* Thu May 27 2010 Nick Bebout <nb@fedoraproject.org> - 0.090-0.1.rc1
- Update to znc 0.090-rc1

* Thu May 27 2010 Nick Bebout <nb@fedoraproject.org> - 0.089-7.svn2004
- Update to znc 0.089.svn2004

* Tue May 18 2010 Nick Bebout <nb@fedoraproject.org> - 0.089-6.svn2000
- Re-enable saslauth

* Tue May 18 2010 Nick Bebout <nb@fedoraproject.org> - 0.089-5.svn2000
- Re-enable modperl

* Tue May 18 2010 Nick Bebout <nb@fedoraproject.org> - 0.089-4.svn2000
- Update to znc 0.089.svn2000

* Sun Apr 25 2010 Nick Bebout <nb@fedoraproject.org> - 0.089-3.svn1944
- Update to znc 0.089.svn1944

* Wed Apr 7 2010 Nick Bebout <nb@fedoraproject.org> - 0.081-2.svn1897
- Update to znc 0.081.svn1897

* Mon Mar 29 2010 Nick Bebout <nb@fedoraproject.org> - 0.081-1.svn1850
- Update to znc 0.081.svn1850

* Thu Feb 18 2010 Nick Bebout <nb@fedoraproject.org> - 0.080-1
- Update to znc 0.080

* Wed Dec 30 2009 Nick Bebout <nb@fedoraproject.org> - 0.078-1
- Update to znc 0.078

* Sun Dec 13 2009 Nick Bebout <nb@fedoraproject.org> - 0.078-0.1.rc1
- Update to znc 0.078.rc1

* Mon Dec 7 2009 Nick Bebout <nb@fedoraproject.org> - 0.077-1.svn1672
- Add a DCCVHost config option which specifies the VHost (IP only!) for DCC bouncing. (r1647)
- Users cloned via the admin module no longer automatically connect into IRC. (r1653)
- Inform new clients about their /away status. (r1655)
- The "BUG" messages from route_replies can now be turned off via /msg *route_replies silent yes. (r1660)
- Rewrite znc.conf on SIGUSR1. (r1666)
- ISpoofFormat now supports ExpandString. (r1670) 
- Allow specifing port and password for delserver. (r1640)
- Write the config file on restart and shutdown. (r1641)
- Disable c-ares if it is not found unless --enable-c-ares was used. (r1644) (r1645)
- blockuser was missing an admin check. (r1648)
- Sometimes, removing a server caused znc to lose track of which server it is connected to. (r1659)
- Include a more portable header for uint32_t in SHA256.h. (r1665)
- Fixed cases where ZNC didn't properly block PONG replies to its own PINGs. (r1668)
- Fixed a possible crash if a client disconnected before an auth module was able to verify the login. (r1669)
- Away allowed to accidentally execute IRC commands. (r1672) 
- Comment out some weird code in Client.cpp. (r1646)
- Remove connect_throttle since it's obsoleted by fail2ban. (r1649)
- Remove outdated sample znc.conf. (r1654)
- route_replies now got a higher timeout before it generates a "BUG" message. (r1657)
- Documented the signals on which znc reacts better. (r1667) 
- New module hook OnIRCConnecting(). (r1638)
- Remove obsolete CUtils::GetHashPass(). (r1642)
- A module's GetDescription() now returns a C-String. (r1661) (r1662)
- When opening a module, check the version number first and don't do anything on a mismatch. (r1663) 

* Fri Dec  4 2009 Stepan Kasal <skasal@redhat.com> - 0.076-3
- rebuild against perl 5.10.1

* Fri Sep 25 2009 Nick Bebout <nb@fedoraproject.org> - 0.076-2
- Fix missing dist tag

* Fri Sep 25 2009 Nick Bebout <nb@fedoraproject.org> - 0.076-1
- Upgrade to ZNC 0.076
- http://en.znc.in/wiki/ChangeLog/0.076

* Fri Aug 28 2009 Nick Bebout <nb@fedoraproject.org> - 0.075-8.svn1613
- Rebuild with new openssl and svn 1613
- build 0.075-7.svn1610 existed but I had to remove it from the spec because
- the date was earlier than the date tmraz build the new openssl one

* Wed Aug 26 2009 Tomas Mraz <tmraz@redhat.com> - 0.075-6.svn1608
- rebuilt with new openssl

* Thu Aug 20 2009 Nick Bebout <nb@fedoraproject.org> - 0.075-5.svn1608
- Upgrade to svn 1608

* Tue Aug 18 2009 Nick Bebout <nb@fedoraproject.org> - 0.075-4.20090818svn1602
- Upgrade to svn 1602

* Sat Aug 8 2009 Nick Bebout <nb@fedoraproject.org> - 0.075-3.20090807svn1594
- Fix source filename

* Fri Aug 7 2009 Nick Bebout <nb@fedoraproject.org> - 0.075-2.20090807svn1594
- Fix broken source tarball

* Fri Aug 7 2009 Nick Bebout <nb@fedoraproject.org> - 0.075-1.20090807svn1594
- Upgrade to svn 1594

* Mon Jul 27 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.074-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild

* Thu Jul 23 2009 Nick Bebout <nb@fedoraproject.org> - 0.074-1
- Update to 0.074

* Wed Jul 22 2009 Nick Bebout <nb@fedoraproject.org> - 0.072-3
- Fix date in changelog, disable c-ares

* Wed Jul 22 2009 Nick Bebout <nb@fedoraproject.org> - 0.072-2
- Backport patch to fix webadmin skins issue introduced in 0.072

* Wed Jul 22 2009 Nick Bebout <nb@fedoraproject.org> - 0.072-1
- Upgrade to 0.072 of ZNC, fixes security issue in bug # 513152

* Sun Jul 12 2009 Nick Bebout <nb@fedoraproject.org> - 0.070-7
- Fix License: to be GPLv2 with exceptions

* Sat Jul 11 2009 Nick Bebout <nb@fedoraproject.org> - 0.070-6
- Fix permissions error in %%prep, not in source

* Sat Jul 11 2009 Nick Bebout <nb@fedoraproject.org> - 0.070-5
- Fix permissions error on q.cpp and add LICENSE.OpenSSL

* Sat Jul 11 2009 Nick Bebout <nb@fedoraproject.org> - 0.070-4
- Remove switch to enable debug, fix %%files section

* Fri Jul 10 2009 Nick Bebout <nb@fedoraproject.org> - 0.070-3
- Move fixfreenode and log into separate znc-extra package
- Move awayping into separate znc-awayping package

* Thu Jul 9 2009 Nick Bebout <nb@fedoraproject.org> - 0.070-2
- Include modules with main package

* Wed Jul 8 2009 Nick Bebout <nb@fedoraproject.org> - 0.070-1
- Initial Fedora package based on 0.070 of upstream
