%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}

Name:           felix
Summary:        Project Calico virtual networking for cloud data centers
Version:        -- filled in by 'make rpm' when building packages --
Release:        -- filled in by 'make rpm' when building packages --
# All code is Apache 2.0 except files in bpf-gpl which are GPL-2.
License:        ASL 2.0 and GPLv2
URL:            http://projectcalico.org
Source0:        felix-%{version}.tar.gz
Source1:        calico-felix.logrotate
Source35:       calico-felix.init
Source45:       calico-felix.service


%define _unpackaged_files_terminate_build 0


%description
Project Calico is an open source solution for virtual networking in
cloud data centers. Its IP-centric architecture offers numerous
advantages over other cloud networking approaches such as VLANs and
overlays, including scalability, efficiency, and simplicity. It is
designed for a wide range of environments including OpenStack,
lightweight Linux containers (LXCs), bare metal, and Network Functions
Virtualization (NFV).


%package -n calico-common
Group:          Applications/Engineering
Summary:        Project Calico virtual networking for cloud data centers

%description -n calico-common
This package provides common files.


%package -n calico-felix
Group:          Applications/Engineering
Summary:        Project Calico virtual networking for cloud data centers
%if 0%{?el7}
Requires:       calico-common, conntrack-tools, ipset, iptables, iptables-utils, net-tools, iproute, which
%else
Requires:       calico-common, conntrack-tools, ipset, iptables, net-tools, iproute, which
%endif


%description -n calico-felix
This package provides the Felix component.

%post -n calico-felix
if [ $1 -eq 1 ] ; then
    # Initial installation
%if 0%{?el7}
    /usr/bin/systemctl daemon-reload
    /usr/bin/systemctl enable calico-felix
    /usr/bin/systemctl start calico-felix
%else
    /sbin/chkconfig -add calico-felix >/dev/null 2>&1 || :
    /etc/init.d/calico-felix start >/dev/null 2>&1 || :
%endif
fi

%preun -n calico-felix
if [ $1 -eq 0 ] ; then
    # Package removal, not upgrade
%if 0%{?el7}
    /usr/bin/systemctl disable calico-felix
    /usr/bin/systemctl stop calico-felix
%else
    /etc/init.d/calico-felix stop >/dev/null 2>&1 || :
    /sbin/chkconfig -del calico-felix >/dev/null 2>&1 || :
%endif
fi

%postun -n calico-felix
if [ $1 -ge 1 ] ; then
    # Package upgrade, not uninstall
%if 0%{?el7}
    /usr/bin/systemctl condrestart calico-felix >/dev/null 2>&1 || :
%else
    /etc/init.d/calico-felix condrestart >/dev/null 2>&1 || :
%endif
fi

%prep
%setup -q

%build

%install
rm -rf $RPM_BUILD_ROOT
install -d $RPM_BUILD_ROOT/usr/bin/
install -m 755 bin/calico-felix $RPM_BUILD_ROOT/usr/bin/
install -d $RPM_BUILD_ROOT/usr/lib/calico/bpf/
install -m 644 bpf-gpl/bin/* $RPM_BUILD_ROOT/usr/lib/calico/bpf/
install -m 644 bpf-apache/bin/* $RPM_BUILD_ROOT/usr/lib/calico/bpf/


# Setup directories
install -d -m 755 %{buildroot}%{_datadir}/calico
install -d -m 755 %{buildroot}%{_sysconfdir}
%if 0%{?el7}
    install -d -m 755 %{buildroot}%{_unitdir}
%else
    install -d -m 755 %{buildroot}%{_sysconfdir}/init.d
%endif

# For EL6, install init script
%if 0%{?el6}
    install -p -m 755 %{SOURCE35} %{buildroot}%{_sysconfdir}/init.d/calico-felix
%endif

# For EL7, install systemd service files
%if 0%{?el7}
    install -p -D -m 755 %{SOURCE45} %{buildroot}%{_unitdir}/calico-felix.service
%endif

# Install config and other non-Python files
install -d %{buildroot}%{_sysconfdir}/calico
install etc/*.cfg.example %{buildroot}%{_sysconfdir}/calico
install -d %{buildroot}%{_datadir}/calico/bird
install etc/bird/*.template %{buildroot}%{_datadir}/calico/bird
install -d %{buildroot}%{_bindir}
install -m 755 etc/calico-diags etc/*.sh %{buildroot}%{_bindir}

install -d -m 755 %{buildroot}/%{_sysconfdir}/logrotate.d
install    -m 644 %_sourcedir/calico-felix.logrotate    %{buildroot}/%{_sysconfdir}/logrotate.d/calico-felix


%clean
rm -rf $RPM_BUILD_ROOT


%files -n calico-common
%defattr(-,root,root,-)
/usr/bin/calico-diags
/usr/bin/calico-gen-bird-conf.sh
/usr/bin/calico-gen-bird6-conf.sh
/usr/bin/calico-gen-bird-mesh-conf.sh
/usr/bin/calico-gen-bird6-mesh-conf.sh
/usr/share/calico/bird/*
%doc

%files -n calico-felix
%defattr(-,root,root,-)
/usr/bin/calico-felix
/usr/lib/calico/bpf/*
/etc/calico/felix.cfg.example
%if 0%{?el7}
    %{_unitdir}/calico-felix.service
%else
    %{_sysconfdir}/init.d/calico-felix
%endif
%{_sysconfdir}/logrotate.d/calico-felix
%doc



%changelog
