File mirrorbrain.spec of Package mirrorbrain

#
# spec file for package mirrorbrain
#
# Copyright (c) 2007-2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

%bcond_with    memcached
%bcond_with    geoip

%if %{defined suse_version}
%define apxs /usr/sbin/apxs2
BuildRequires:  apache2-devel
BuildRequires:  apache2-prefork
BuildRequires:  apache2-worker
%endif
#
%if %{defined centos_version} || %{defined rhel} || %{defined fedora_version}
%define apxs /usr/sbin/apxs
BuildRequires:  httpd-devel
%endif
#
%define apache apache2
%define apache_libexecdir %(%{apxs} -q LIBEXECDIR)
%define apache_sysconfdir %(%{apxs} -q SYSCONFDIR)
%define apache_includedir %(%{apxs} -q INCLUDEDIR)
%define apache_serverroot %(%{apxs} -q PREFIX)
%define apache_localstatedir %(%{apxs} -q LOCALSTATEDIR)
%define apache_mmn        %(MMN=$(%{apxs} -q LIBEXECDIR)_MMN; test -x $MMN && $MMN)
#
Name:           mirrorbrain
Version:        2.19.3
Release:        0
License:        Apache-2.0 or GPL-2.0+
Summary:        A download redirector and metalink generator
# to build a man page, we need to have the script functional, and thus we need more stuff
# but python-cmdln is not available
#BuildRequires:  help2man python-cmdln
Url:            https://github.com/openSUSE/mirrorbrain
Group:          Productivity/Networking/Web/Servers
#
# https://github.com/openSUSE/mirrorbrain/releases
Source:         %{name}-%{version}.tar.gz
Source1:        %{name}-rpmlintrc
Source2:        geoiplookup-mb
#
Patch1:         mirrorbrain-2.19.3-summary_attribute_on_the_table_element_is_obsolete.patch
#
BuildRequires:  apache2-mod_form
BuildRequires:  python-devel
%if %{with geoip}
BuildRequires:  GeoIP
BuildRequires:  GeoIP-devel
%endif
#
%if %{defined suse_version}
BuildRequires:  fdupes
PreReq:         %fillup_prereq
PreReq:         %insserv_prereq
PreReq:         pwdutils
%else
PreReq:         glibc-common
PreReq:         shadow-utils
%endif
#
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(True)")}

%description
This apache module redirects clients to mirror servers, using an SQL backend,
and generates metalinks.

See http://mirrorbrain.org/

Author: Peter Poeml <peter@poeml.de>

%package -n apache2-mod_mirrorbrain
License:        Apache-2.0 or GPL-2.0+
Summary:        MirrorBrain redirector Apache module
Group:          Productivity/Networking/Web/Servers
Obsoletes:      apache2-mod_zrkadlo < %{version}
Provides:       apache2-mod_zrkadlo = %{version}-%{release}
# see http://mirrorbrain.org/requirements
%if %{defined suse_version}
Requires:       %{apache_mmn}
Requires:       apache2 >= 2.2.6
%if %{with geoip}
Requires:       apache2-mod_geoip2
%else
Requires:       apache2-mod_maxminddb
%endif
Requires:       libapr-util1 >= 1.3.0
Requires:       libapr-util1-dbd-pgsql
%else
Requires:       apr-util
Requires:       apr-util-pgsql
Requires:       httpd
%if %{with geoip}
Requires:       mod_geoip
%else
Requires:       mod_maxminddb
%endif
%endif
%if %{with geoip}
Requires:       GeoIP
%endif
#
# for mod_form
Requires:       apache2-mod_form
# building with memcache support:
%if %{with memcached}
BuildRequires:  apache2-mod_memcache
Requires:       apache2-mod_memcache
%define memcache_cflags -DWITH_MEMCACHE
%else
%define memcache_cflags %nil
%endif
# this module was was split off in a separate package with 2.10.1. Require it
# so that existing installations will keep having it installed.
# the requires can be removed later (let's say, a few months after October '09)
Requires:       apache2-mod_autoindex_mb

%description -n apache2-mod_mirrorbrain
MirrorBrain is a scalable download redirector.

This package contains mod_mirrorbrain, the Apache module which represents the
core of MirrorBrain.

%package -n apache2-mod_autoindex_mb
License:        Apache-2.0 or GPL-2.0+
Summary:        Apache module generating directory indexes for MirrorBrain
Group:          Productivity/Networking/Web/Servers
%if %{defined suse_version}
Requires:       %{apache_mmn}
%else
Requires:       httpd
%endif
Requires:       apache2-mod_mirrorbrain

%description -n apache2-mod_autoindex_mb

This package contains mod_autoindex_mb, the Apache module which represents the
core of MirrorBrain.

This package contains mod_autoindex_mb, which is a patched mod_autoindex. It
adds a little further capability as index option.

It adds these two options:

        <IfModule mod_autoindex_mb.c>
            IndexOptions Metalink
            IndexOptions Mirrorlist
        </IfModule>
The Metalink option adds a link named "Metalink" to the index, which links to
the same file but with ".metalink" appended.

The MirrorList option adds a link named "Mirrors" to the index, which links to
the same resources but with "?mirrorlist" appended.

%package tools
License:        Apache-2.0 or GPL-2.0+
Summary:        MirrorBrain commandline tools
Group:          Productivity/Networking/Web/Servers
Requires:       logrotate
%if %{with geoip}
Requires:       GeoIP
%endif
Requires:       python-cmdln
Requires:       python-mb
Requires:       python-psycopg2
Requires:       python-sqlobject
Requires:       python3-maxminddb

%description tools
MirrorBrain is a scalable download redirector.

This package contains utilities provided by the MirrorBrain framework to
maintain the database and scan mirrors.

%package -n python-mb
License:        Apache-2.0 or GPL-2.0+
Summary:        A Python module used by the MirrorBrain commandline tools
Group:          Productivity/Networking/Web/Servers
%if %{with geoip}
Requires:       GeoIP
%endif
Requires:       python-psycopg2
Requires:       python-sqlobject
%if %{defined suse_version}
%if 0%{?suse_version} >= 01310
Requires:       python-FormEncode
%endif
%if 0%{?suse_version} < 110
Recommends:     python-processing
%endif
%endif

%description -n python-mb
MirrorBrain is a scalable download redirector.

This package contains a Python module (named "mb") for easily maintaining
MirrorBrain.

%package scanner
License:        Apache-2.0 or GPL-2.0+
Summary:        MirrorBrain scanner
Group:          Productivity/Networking/Web/Servers
Requires:       perl-Config-IniFiles
Requires:       perl-DBD-Pg
Requires:       perl-Digest-MD4
Requires:       perl-TimeDate
Requires:       perl-libwww-perl

%description scanner
MirrorBrain is a scalable download redirector.

This package contains the mirror scanner.

%prep
%setup -q -n mirrorbrain-%{version}
%patch1 -p1

%build
cd mod_mirrorbrain
%{apxs} -c -Wc,"%memcache_cflags -Wall -g" -lm mod_mirrorbrain.c
cd ../mod_autoindex_mb
%{apxs} -c -Wc,"%memcache_cflags -Wall -g" mod_autoindex_mb.c
%if %{with geoip}
cd ../tools
gcc %{optflags} -Wall -o geoiplookup_continent geoiplookup_continent.c -lGeoIP
gcc %{optflags} -Wall -o geoiplookup_city geoiplookup_city.c -lGeoIP
%endif
cd ../mb
CFLAGS="%{optflags}" \
%{__python} setup.py build


%install
mkdir -p %{buildroot}%{apache_libexecdir}
cp -p mod_mirrorbrain/.libs/mod_mirrorbrain.so %{buildroot}%{apache_libexecdir}
cp -p mod_autoindex_mb/.libs/mod_autoindex_mb.so %{buildroot}%{apache_libexecdir}
# tools
%if %{with geoip}
install -D -m 755 tools/geoiplookup_continent %{buildroot}%{_bindir}/geoiplookup_continent
install -D -m 755 tools/geoiplookup_city %{buildroot}%{_bindir}/geoiplookup_city
install -D -m 755 tools/geoip-lite-update %{buildroot}%{_bindir}/geoip-lite-update
%else
install -D -m 755 %{SOURCE2}  %{buildroot}%{_bindir}/geoiplookup-mb
ln -sf   geoiplookup-mb       %{buildroot}%{_bindir}/geoiplookup_city
ln -sf   geoiplookup-mb       %{buildroot}%{_bindir}/geoiplookup_continent
%endif
install -D -m 755 tools/bdecode %{buildroot}%{_bindir}/bdecode
install -D -m 755 tools/rsyncinfo %{buildroot}%{_bindir}/rsyncinfo
install -D -m 755 tools/rsyncusers %{buildroot}%{_bindir}/rsyncusers
install -D -m 755 tools/create_timestamp %{buildroot}%{_bindir}/create_timestamp
install -D -m 755 tools/null-rsync %{buildroot}%{_bindir}/null-rsync
# install -D -m 755 tools/push2mirrors %%{buildroot}%%{_bindir}/push2mirrors
install -D -m 755 tools/scanner.pl %{buildroot}%{_bindir}/scanner
install -D -m 755 mirrorprobe/mirrorprobe.py %{buildroot}%{_bindir}/mirrorprobe
install -D -m 644 tools/mirrorprobe-logrotate %{buildroot}%{_sysconfdir}/logrotate.d/mirrorprobe
cd mb
%{__python} setup.py install --prefix=%{_prefix} --root %{buildroot}
# man page for mb tool
#%%{buildroot}%%{_bindir}/mb --version
#help2man --no-info %%{buildroot}%%{_bindir}/mb > mb.1
# Icons
mkdir -p %{buildroot}%{_datadir}/mirrorbrain
cp -a famfamfam_flag_icons %{buildroot}%{_datadir}/mirrorbrain/
%if %{defined suse_version}
# save some space, use fdupes
%fdupes %{buildroot}%{_datadir}/mirrorbrain/famfamfam_flag_icons/
%endif
# log directory
mkdir -p %{buildroot}%{_var}/log/mirrorbrain

%pre
if ! getent group mirrorbrain &>/dev/null; then
  echo "Creating mirrorbrain group"
  groupadd -r mirrorbrain
fi
if ! getent passwd mirrorbrain &>/dev/null; then
  echo "Creating mirrorbrain user"
  if [ -d /home/mirrorbrain ]; then
      echo "WARNING: /home/mirrorbrain already exists, please check if this is expected" 2>&1
  fi
  useradd -g mirrorbrain -s /bin/bash -r -c "MirrorBrain user" \
                    -d /home/mirrorbrain -m mirrorbrain
fi

%post
# move old mirrorprobe logfile to the new location
# Update ?
if [ ${1:-0} -gt 1 ]; then
  if [ -e /var/log/mirrorprobe.log ] && [ ! -e /var/log/mirrorbrain/mirrorprobe.log ]; then
    echo "moving /var/log/mirrorprobe.log to /var/log/mirrorbrain/"
    mv -v /var/log/mirrorprobe.log /var/log/mirrorbrain/
    echo "creating symlink at the old location (/var/log/mirrorprobe.log). You may remove it."
    ln -sv /var/log/mirrorbrain/mirrorprobe.log /var/log/mirrorprobe.log
    # adjust config, if the defaults were in use
    if grep -q '^logfile = /var/log/mirrorprobe.log' /etc/mirrorbrain.conf &>/dev/null; then
      echo "adjusting /etc/mirrorbrain.conf"
      sed -i 's,^logfile = /var/log/mirrorprobe.log,logfile = /var/log/mirrorbrain/mirrorprobe.log,' /etc/mirrorbrain.conf
      echo "/etc/mirrorbrain.conf was migrated to the new location"
    fi
  fi

  # create missing database tables that are needed with 2.13.0 and later
  if test -e /etc/mirrorbrain.conf && test -x /usr/bin/mb; then
    echo "checking if new tables need to be added after upgrade"
    mb > /dev/null
  fi
fi
exit 0


%files
%defattr(-,root,root)
%doc COPYING FAQ TODO
%doc mod_autoindex_mb/NOTICE
%doc mod_mirrorbrain/*.conf
%doc docs
%doc sql
%doc %attr(644,root,root) tools/push2mirrors
%attr(750,mirrorbrain,mirrorbrain) %dir %{_var}/log/mirrorbrain

%files -n apache2-mod_mirrorbrain
%defattr(-,root,root)
%{apache_libexecdir}/mod_mirrorbrain.so

%files -n apache2-mod_autoindex_mb
%defattr(-,root,root)
%{apache_libexecdir}/mod_autoindex_mb.so

%files tools
%defattr(-,root,root)
%{_bindir}/bdecode
%{_bindir}/create_timestamp
%if %{with geoip}
%{_bindir}/geoip-lite-Update
%else
%{_bindir}/geoiplookup-mb
%endif
%{_bindir}/geoiplookup_city
%{_bindir}/geoiplookup_continent

%{_bindir}/mirrorprobe
%{_bindir}/null-rsync
%{_bindir}/rsyncinfo
%{_bindir}/rsyncusers
%config(noreplace) %{_sysconfdir}/logrotate.d/mirrorprobe
# Icons
%{_datadir}/mirrorbrain

%files -n python-mb
%defattr(-,root,root)
%{_bindir}/mb
%{python_sitearch}/*

%files scanner
%defattr(-,root,root)
%{_bindir}/scanner

%changelog
openSUSE Build Service is sponsored by