File cobbler.spec of Package cobbler

#
# spec file for package cobbler
#
# Copyright (c) 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/
#


%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
%{!?pyver: %define pyver %(%{__python} -c "import sys ; print sys.version[:3]" || echo 0)}

%if 0%{?suse_version}
%define www_path /srv/
%define apache_user wwwrun
%define apache_group www
%define apachedir apache2
%else
%define www_path %{_var}
%define apache_user apache
%define apache_group apache
%define apachedir httpd
%endif

%define _binaries_in_noarch_packages_terminate_build 0
%global debug_package %{nil}
Summary:        Boot server configurator
License:        GPL-2.0+
Group:          Applications/System
Name:           cobbler
AutoReq:        no
Version:        2.4.2
Release:        1%{?dist}
Source0:        cobbler-%{version}.tar.gz
Source1:        vendor-files.tar.bz2
Source2:        fence_ipmitool.sh
Patch1:         suse_config.diff
Patch2:         cobbler_web_config.diff
Patch3:         setup_py.diff
%if 0%{?suse_version}
Patch4:         grubby-compat.diff
%endif
Patch5:         koan_old_cobbler_compat.diff
Patch6:         looking_for_cobbler_order_changed.diff
Patch7:         catch_cheetah_exception.patch
Patch9:         fix-restart-paravirt-xen.dif
Patch10:        disable_not_relevant_checks_bnc_828453.patch
Patch11:        fix-powermanagement-status.dif
Patch12:        bnc_877009.patch
Patch13:        fix_sle_detection.patch
Patch14:        do_not_use_grubby_compat_when_grub2_is_in_use.diff

BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch
Url:            http://www.cobblerd.org/

BuildRequires:  fdupes
BuildRequires:  git
BuildRequires:  python-cheetah
%if 0%{?suse_version}
BuildRequires:  apache2
BuildRequires:  atftp
BuildRequires:  distribution-release
BuildRequires:  python-PyYAML
Requires:       apache2-mod_wsgi
Requires:       ipmitool
%else
BuildRequires:  PyYAML
BuildRequires:  redhat-rpm-config
Requires:       httpd
Requires:       mod_wsgi
%endif

Requires:       createrepo
Requires:       python >= 2.3
Requires:       python-cheetah
Requires:       python-netaddr
Requires:       python-simplejson
Requires:       python-urlgrabber
Requires:       rsync
%ifarch %ix86 x86_64
Requires:       syslinux
%endif
%ifarch s390x
Requires:       syslinux-x86_64
%endif
Requires:       tftp(server)

%if 0%{?fedora} >= 11 || 0%{?rhel} >= 6 || 0%{?suse_version}
Requires:       genisoimage
%else
Requires:       mkisofs
%endif

%if 0%{?fedora} >= 11 || 0%{?rhel} >= 6
Requires:       python(abi) >= %{pyver}
%endif

%if 0%{?fedora} >= 8
BuildRequires:  python-setuptools-devel
%else
BuildRequires:  python-setuptools
%endif

%if 0%{?fedora} >= 6 || 0%{?rhel} >= 5 || 0%{?suse_version}
Requires:       yum-utils
%endif

%if 0%{?fedora} >= 16
BuildRequires:  systemd-units
Requires(post): systemd-sysv
Requires(post): systemd-units
Requires(preun): systemd-units
Requires(postun): systemd-units
%else
%if 0%{?suse_version}
BuildRequires:  pkgconfig(systemd)
%{?systemd_requires}
%else
Requires(post):  /sbin/chkconfig
Requires(preun): /sbin/chkconfig
Requires(preun): /sbin/service
%endif
%endif

%description

Cobbler is a network install server.  Cobbler supports PXE,
virtualized installs, and re-installing existing Linux machines.  The
last two modes use a helper tool, 'koan', that integrates with
cobbler.  There is also a web interface 'cobbler-web'.  Cobbler's
advanced features include importing distributions from DVDs and rsync
mirrors, kickstart templating, integrated yum mirroring, and built-in
DHCP/DNS Management.  Cobbler has a XMLRPC API for integration with
other applications.

%prep
%setup -q
%setup -a1
%if 0%{?suse_version}
%patch1
%patch2
%endif
%patch3
%if 0%{?suse_version}
%patch4
%endif
%patch5
%patch6
%patch7 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1

mv vendor-files/cobbler.1.gz docs

%build
%{__python} setup.py build

%install
test "x$RPM_BUILD_ROOT" != "x" && rm -rf $RPM_BUILD_ROOT
%{__python} setup.py install --optimize=1 --root=$RPM_BUILD_ROOT $PREFIX
mkdir -p $RPM_BUILD_ROOT/etc/%{apachedir}/conf.d
mv config/cobbler.conf $RPM_BUILD_ROOT/etc/%{apachedir}/conf.d/
mv config/cobbler_web.conf $RPM_BUILD_ROOT/etc/%{apachedir}/conf.d/

mkdir -p $RPM_BUILD_ROOT/var/spool/koan

%if 0%{?fedora} >= 9 || 0%{?rhel} > 5
mkdir -p $RPM_BUILD_ROOT/var/lib/tftpboot/images
%else
%if 0%{?suse_version}
mkdir -p $RPM_BUILD_ROOT/srv/tftpboot/images
%else
mkdir -p $RPM_BUILD_ROOT/tftpboot/images
%endif
%endif

rm -f $RPM_BUILD_ROOT/etc/cobbler/cobblerd

%if 0%{?suse_version}
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/SuSEfirewall2.d
mv vendor-files/cobbler_firewall_settings $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/SuSEfirewall2.d/cobbler
install -m 755 %{S:2} $RPM_BUILD_ROOT/usr/sbin/fence_ipmitool
ln -sf service $RPM_BUILD_ROOT/usr/sbin/rccobblerd
chmod 755 $RPM_BUILD_ROOT/usr/sbin/grubby-compat
%endif

%if 0%{?fedora} >= 16 || 0%{?suse_version}
rm -rf $RPM_BUILD_ROOT/etc/init.d
mkdir -p $RPM_BUILD_ROOT%{_unitdir}
install -m0644 config/cobblerd.service $RPM_BUILD_ROOT%{_unitdir}

%fdupes %{buildroot}/usr

%if 0%{?suse_version}
%pre
%service_add_pre cobblerd.service
%endif

%post
if [ $1 -eq 1 ] ; then 
    # Initial installation 
    %if 0%{?suse_version}
        %{fillup_and_insserv cobblerd}
        sysconf_addword /etc/sysconfig/apache2 APACHE_MODULES proxy
        sysconf_addword /etc/sysconfig/apache2 APACHE_MODULES proxy_http
        sysconf_addword /etc/sysconfig/apache2 APACHE_MODULES proxy_connect
        sysconf_addword /etc/sysconfig/apache2 APACHE_MODULES wsgi
    %else
        /bin/systemctl daemon-reload >/dev/null 2>&1 || :
    %endif
elif [ "$1" -ge "2" ]; then
    # backup config
    if [ -e /var/lib/cobbler/distros ]; then
        cp /var/lib/cobbler/distros*  /var/lib/cobbler/backup 2>/dev/null
        cp /var/lib/cobbler/profiles* /var/lib/cobbler/backup 2>/dev/null
        cp /var/lib/cobbler/systems*  /var/lib/cobbler/backup 2>/dev/null
        cp /var/lib/cobbler/repos*    /var/lib/cobbler/backup 2>/dev/null
        cp /var/lib/cobbler/networks* /var/lib/cobbler/backup 2>/dev/null
    fi
    if [ -e /var/lib/cobbler/config ]; then
        cp -a /var/lib/cobbler/config    /var/lib/cobbler/backup 2>/dev/null
    fi
    # upgrade older installs
    # move power and pxe-templates from /etc/cobbler, backup new templates to *.rpmnew
    for n in power pxe; do
      rm -f /etc/cobbler/$n*.rpmnew
      find /etc/cobbler -maxdepth 1 -name "$n*" -type f | while read f; do
        newf=/etc/cobbler/$n/`basename $f`
        [ -e $newf ] &&  mv $newf $newf.rpmnew
        mv $f $newf
      done
    done
    # upgrade older installs
    # copy kickstarts from /etc/cobbler to /var/lib/cobbler/kickstarts
    rm -f /etc/cobbler/*.ks.rpmnew
    find /etc/cobbler -maxdepth 1 -name "*.ks" -type f | while read f; do
      newf=/var/lib/cobbler/kickstarts/`basename $f`
      [ -e $newf ] &&  mv $newf $newf.rpmnew
      cp $f $newf
    done
    # remove mod_python from apache
    sysconf_addword -r /etc/sysconfig/apache2 APACHE_MODULES python >/dev/null 2>&1
%if ! 0%{?suse_version}
    /bin/systemctl try-restart cobblerd.service >/dev/null 2>&1 || :
%endif
fi
%if 0%{?suse_version}
%service_add_post cobblerd.service
%endif

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

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

%if ! 0%{?suse_version}
%triggerun -- cobbler < 2.0.11-3
# Save the current service runlevel info
# User must manually run systemd-sysv-convert --apply cobblerd
# to migrate them to systemd targets
/usr/bin/systemd-sysv-convert --save cobblerd >/dev/null 2>&1 ||:

# Run these because the SysV package being removed won't do them
/sbin/chkconfig --del cobblerd >/dev/null 2>&1 || :
/bin/systemctl try-restart cobblerd.service >/dev/null 2>&1 || :
%endif

%else

%post
if [ "$1" = "1" ];
then
    # This happens upon initial install. Upgrades will follow the next else
    /sbin/chkconfig --add cobblerd
elif [ "$1" -ge "2" ];
then
    # backup config
    if [ -e /var/lib/cobbler/distros ]; then
        cp /var/lib/cobbler/distros*  /var/lib/cobbler/backup 2>/dev/null
        cp /var/lib/cobbler/profiles* /var/lib/cobbler/backup 2>/dev/null
        cp /var/lib/cobbler/systems*  /var/lib/cobbler/backup 2>/dev/null
        cp /var/lib/cobbler/repos*    /var/lib/cobbler/backup 2>/dev/null
        cp /var/lib/cobbler/networks* /var/lib/cobbler/backup 2>/dev/null
    fi
    if [ -e /var/lib/cobbler/config ]; then
        cp -a /var/lib/cobbler/config    /var/lib/cobbler/backup 2>/dev/null
    fi
    # upgrade older installs
    # move power and pxe-templates from /etc/cobbler, backup new templates to *.rpmnew
    for n in power pxe; do
      rm -f /etc/cobbler/$n*.rpmnew
      find /etc/cobbler -maxdepth 1 -name "$n*" -type f | while read f; do
        newf=/etc/cobbler/$n/`basename $f`
        [ -e $newf ] &&  mv $newf $newf.rpmnew
        mv $f $newf
      done
    done
    # upgrade older installs
    # copy kickstarts from /etc/cobbler to /var/lib/cobbler/kickstarts
    rm -f /etc/cobbler/*.ks.rpmnew
    find /etc/cobbler -maxdepth 1 -name "*.ks" -type f | while read f; do
      newf=/var/lib/cobbler/kickstarts/`basename $f`
      [ -e $newf ] &&  mv $newf $newf.rpmnew
      cp $f $newf
    done
    # reserialize and restart
    # FIXIT: ?????
    #/usr/bin/cobbler reserialize
    /sbin/service cobblerd condrestart
fi

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

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

%endif

%clean
test "x$RPM_BUILD_ROOT" != "x" && rm -rf $RPM_BUILD_ROOT

%files

%defattr(-,root,root,-)

%{_bindir}/cobbler
%{_bindir}/cobbler-ext-nodes
%{_bindir}/cobblerd
%{_sbindir}/tftpd.py*

%config(noreplace) %{_sysconfdir}/cobbler
%if 0%{?fedora} >= 16 || 0%{?suse_version} > 1230
%{_unitdir}/cobblerd.service
%else
/etc/init.d/cobblerd
%endif

%{python_sitelib}/cobbler

%config(noreplace) /var/lib/cobbler
%exclude /var/lib/cobbler/webui_sessions

/var/log/cobbler
/%{www_path}/www/cobbler

%{_mandir}/man1/cobbler.1.gz

%config(noreplace) /etc/%{apachedir}/conf.d/cobbler.conf

%if 0%{?fedora} >= 9 || 0%{?rhel} >= 5 || 0%{?suse_version}
%exclude %{python_sitelib}/cobbler/sub_process.py*
%endif
%if 0%{?fedora} >= 9 || 0%{?rhel} > 5 || 0%{?suse_version}
%{python_sitelib}/cobbler*.egg-info
%if 0%{?suse_version}
/srv/tftpboot/images
%else
/var/lib/tftpboot/images
%endif
%else
/tftpboot/images
%endif

%doc AUTHORS CHANGELOG README COPYING
%if 0%{?suse_version}
%config /etc/apache2/vhosts.d/cobbler_web.conf
%config /etc/sysconfig/SuSEfirewall2.d/cobbler
/usr/sbin/fence_ipmitool
/usr/sbin/rccobblerd
%endif

%package -n koan

Summary:        Helper tool that performs cobbler orders on remote machines
Group:          Applications/System
Requires:       python >= 2.0
Requires:       python-simplejson
Requires:       virt-install
%if 0%{?fedora} >= 11 || 0%{?rhel} >= 6
Requires:       python(abi) >= %{pyver}
%endif

%description -n koan

Koan stands for kickstart-over-a-network and allows for both
network installation of new virtualized guests and reinstallation
of an existing system.  For use with a boot-server configured with Cobbler

%files -n koan
%defattr(-,root,root,-)
%dir /var/spool/koan
%dir /var/lib/koan
%dir /var/lib/koan/config
%{_bindir}/koan
%{_bindir}/ovz-install
%{_bindir}/cobbler-register
%{python_sitelib}/koan
%if 0%{?suse_version}
%attr(0755,root,root) /usr/sbin/grubby-compat
%endif

%if 0%{?fedora} >= 9 || 0%{?rhel} >= 5 || 0%{?suse_version}
%exclude %{python_sitelib}/koan/sub_process.py*
%exclude %{python_sitelib}/koan/opt_parse.py*
%exclude %{python_sitelib}/koan/text_wrap.py*
%endif

%{_mandir}/man1/koan.1.gz
%{_mandir}/man1/cobbler-register.1.gz
%dir /var/log/koan
%doc AUTHORS COPYING CHANGELOG README

%package -n cobbler-web

Summary:        Web interface for Cobbler
Group:          Applications/System
Requires:       cobbler
%if 0%{?fedora} >= 11 || 0%{?rhel} >= 6
Requires:       Django >= 1.1.2
Requires:       mod_ssl
Requires:       mod_wsgi
Requires:       python(abi) >= %{pyver}
%endif
%if 0%{?suse_version}
Requires:       apache2-mod_wsgi
Requires:       python-django
%endif

%description -n cobbler-web

Web interface for Cobbler that allows visiting
http://server/cobbler_web to configure the install server.

%post -n cobbler-web
# Change the SECRET_KEY option in the Django settings.py file
# required for security reasons, should be unique on all systems
RAND_SECRET=$(openssl rand -base64 40 | sed 's/\//\\\//g')
sed -i -e "s/SECRET_KEY = ''/SECRET_KEY = \'$RAND_SECRET\'/" /usr/share/cobbler/web/settings.py

%files -n cobbler-web
%defattr(-,root,root,-)
%doc AUTHORS COPYING CHANGELOG README
%config(noreplace) /etc/%{apachedir}/conf.d/cobbler_web.conf
%defattr(-,%{apache_user},%{apache_group},-)
/usr/share/cobbler/web
%dir %attr(700,%{apache_user},root) /var/lib/cobbler/webui_sessions
/%{www_path}/www/cobbler_webui_content/
%if 0%{?suse_version}
%dir /usr/share/cobbler
%endif

%changelog
openSUSE Build Service is sponsored by