File kolab-release.spec of Package kolab-release

%global repository_name kolab
%global repository_version 16

# Fedora or Enterprise Linux?
%if 0%{?fedora} > 0
%global dist_full_name Fedora
%global dist_version %{fedora}
%else
%global dist_full_name Enterprise Linux
%if 0%{?centos_stream} >= 8
%global dist_version %{rhel}_Stream
%else
%global dist_version %{rhel}
%endif
%endif

# Runtime settings
%global desc %{dist_full_name} %{dist_version} Kolab %{repository_version}
%global repository_full_name %{repository_name}-%{repository_version}

Summary:    Apheleia IT release files
Name:       %{repository_name}-release
Version:    %{repository_version}.%{dist_version}
Release:    17%{?dist}
License:    GPLv2
Group:      System Environment/Base
URL:        https://www.apheleia-it.ch
Source0:    kolab-repository-template.repo.tpl
BuildRoot:  %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch:  noarch
Requires:   %{repository_name}(release) = %{repository_version}

%description
Apheleia IT repository configuration files, such as YUM repository configuration files

%package -n %{repository_full_name}-release
Summary:    Kolab Enterprise release files by Apheleia IT
Group:      System Environment/Base

Obsoletes:  %{repository_full_name}-release < %{version}
Provides:   %{repository_full_name}-release = %{version}
Provides:   %{repository_name}(release) = %{repository_version}
%if 0%{?rhel}
Requires:   epel-release = %{rhel}
%if 0%{?rhel} < 8
Requires:   pyliblzma
%endif
%endif

Obsoletes:  %{repository_full_name}-community-release < %{version}
Obsoletes:  %{repository_name}-community-release < %{version}
Provides:   %{repository_full_name}-community-release = %{version}
Provides:   %{repository_name}-community-release = %{version}

%description -n %{repository_full_name}-release
This package provides the repository configuration for Apheleia IT' Enterprise version of Kolab

%prep

%build

%install
rm -rf %{buildroot}
install -d %{buildroot}/%{_sysconfdir}

install -d -m 755 %{buildroot}/%{_sysconfdir}/pki/rpm-gpg

##install -m 644 RPM-GPG-KEY-ergo-%{repository}-* %{_sysconfdir}/etc/pki/rpm-gpg/

install -d -m 755 %{buildroot}/%{_sysconfdir}/yum.repos.d

for repo in base testing testing-candidate; do
    if [ "$repo" == "base" ]; then
        enabled="1"
        suffix=""
        reponame=""
    else
        enabled="0"
        suffix="-$repo"
    fi

%if 0%{?plesk}
    plesk_suffix="_Plesk_17"
%else
    plesk_suffix=""
%endif

    repository_name="%{repository_full_name}"

    if [ "$repo" == "testing" ]; then
        reposuffix=":/Testing"
        repository_name="%{repository_full_name}-testing"
    fi

    if [ "$repo" == "testing-candidate" ]; then
        reposuffix=":/Testing:/Candidate"
        repository_name="%{repository_full_name}-testing-candidate"
    fi

%if 0%{?fedora} > 0
    repository_url="https://mirror.apheleia-it.ch/repos/Kolab:/16$reposuffix/Fedora_%{dist_version}$plesk_suffix"
%else
    repository_url="https://mirror.apheleia-it.ch/repos/Kolab:/16$reposuffix/CentOS_%{dist_version}$plesk_suffix"
%endif
    repository_url_src="$repository_url/src"

    cat %{SOURCE0} | \
        sed \
                -e 's/@@desc@@/%{desc}/g' \
                -e "s/@@enabled@@/$enabled/g" \
                -e "s|@@repository_url@@|$repository_url|g" \
                -e "s|@@repository_url_src@@|$repository_url_src|g" \
                -e "s/@@repository_name@@/$repository_name/g" \
        > %{buildroot}/%{_sysconfdir}/yum.repos.d/%{repository_full_name}$suffix.repo
done

sed -i \
    -e 's|@@gpgcheck@@|1|g' \
        %{buildroot}/%{_sysconfdir}/yum.repos.d/*.repo

%clean
rm -rf %{buildroot}


%files -n %{repository_full_name}-release
%defattr(-,root,root,-)
%dir %{_sysconfdir}/yum.repos.d
%config(noreplace) %{_sysconfdir}/yum.repos.d/kolab-16.repo
%config(noreplace) %{_sysconfdir}/yum.repos.d/kolab-16-testing.repo
%config(noreplace) %{_sysconfdir}/yum.repos.d/kolab-16-testing-candidate.repo
%dir %{_sysconfdir}/pki/rpm-gpg

%changelog
* Fri Jun 3 2022 Christian Mollekopf <mollekopf@apheleia-it.ch> - 16.8-17
- New simplified repository layout

* Mon May 14 2018 Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> - 16.7-10
- Add extras-collab for Plesk 17

* Wed Nov  1 2017 Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> - 16.7-2
- Add extras-collab

* Tue Nov 15 2016 Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> - 16.7-1
- Add extras-fasttrack for RHEL 7 too

* Sat Jan 16 2016 Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> - 16.0-1
- Update for Kolab 16
- Also require pyliblzma
- Add fasttrack repository configuration for kolab-14/el6
- Add repository configuration for extras-audit and extras-puppet

* Thu Oct  2 2014 Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> - 14-1
- Kolab Enterprise 14 repository configuration

* Sun Dec  8 2013 Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> - 6-7
- Drop requirement on yum-plugin-priorities, not available in RHEL

* Mon Oct 14 2013 Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> - 6-5
- Make sure yum-plugin-priorities is a required package, documentation
  clearly is insufficient.
- Make sure the default priority is set.

* Thu Apr 11 2013 Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> - 6-4.1
- Correct yum/curl now using the ca and client certificates configured
  in the kolab repository configuration.

* Sat Dec  1 2012 Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> - 6-4
- Correct base_url for private repository stages

* Fri Nov 30 2012 Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> - 6-3
- Correct requires/provides for sub-package