File mock-core-configs.spec of Package mock-core-configs

#
# spec file for package mock-core-configs
#
# Copyright (c) 2023 SUSE LLC
#
# 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 https://bugs.opensuse.org/
#
%define mockversion 6.4


%if 0%{?el8}
%global python3 %{_libexecdir}/platform-python
%endif
Name:           mock-core-configs
Version:        43.2
Release:        1%{?dist}
Summary:        Mock core config files basic chroots
License:        GPL-2.0-or-later
URL:            https://github.com/rpm-software-management/mock/
Source:         https://github.com/rpm-software-management/mock/releases/download/mock-%{mockversion}-1/%{name}-%{version}.tar.gz
# distribution-gpg-keys contains GPG keys used by mock configs
Requires:       distribution-gpg-keys >= 1.85
# specify minimal compatible version of mock
Requires:       mock >= 5.0
Requires:       mock-filesystem
Requires(post): coreutils
Requires(post): python3
# to detect correct default.cfg
Requires(post): python3-dnf
Requires(post): python3-hawkey
Requires(post): sed
# The mock.rpm requires this.  Other packages may provide this if they tend to
# replace the mock-core-configs.rpm functionality.
Provides:       mock-configs
BuildArch:      noarch
%if 0%{?suse_version}
Requires(post): openSUSE-release
%else
Requires(post): system-release
%endif

%description
Mock configuration files which allow you to create chroots for Alma Linux,
Amazon Linux, CentOS, CentOS Stream, EuroLinux, Fedora, Fedora EPEL, Mageia,
Navy Linux, OpenMandriva Lx, openSUSE, Oracle Linux, Red Hat Enterprise Linux,
Rocky Linux and various other specific or combined chroots.

%prep
%setup -q


%build


%install
mkdir -p %{buildroot}%{_sysusersdir}

mkdir -p %{buildroot}%{_sysconfdir}/mock/eol/templates
mkdir -p %{buildroot}%{_sysconfdir}/mock/templates
cp -a etc/mock/*.cfg %{buildroot}%{_sysconfdir}/mock
cp -a etc/mock/templates/*.tpl %{buildroot}%{_sysconfdir}/mock/templates
cp -a etc/mock/eol/*cfg %{buildroot}%{_sysconfdir}/mock/eol
cp -a etc/mock/eol/templates/*.tpl %{buildroot}%{_sysconfdir}/mock/eol/templates

# generate files section with config - there is many of them
echo "%defattr(0644, root, mock)" > %{name}.cfgs
find %{buildroot}%{_sysconfdir}/mock -name "*.cfg" -o -name '*.tpl' \
    | grep -v chroot-aliases \
    | sed -e "s|^%{buildroot}|%%config(noreplace) |" >> %{name}.cfgs
echo "%%config %{_sysconfdir}/mock/chroot-aliases.cfg" >> %{name}.cfgs

# just for %%ghosting purposes
ln -s fedora-rawhide-x86_64.cfg %{buildroot}%{_sysconfdir}/mock/default.cfg
# bash-completion
if [ -d %{buildroot}%{_datadir}/bash-completion ]; then
    echo %{_datadir}/bash-completion/completions/mock >> %{name}.cfgs
    echo %{_datadir}/bash-completion/completions/mockchain >> %{name}.cfgs
elif [ -d %{buildroot}%{_sysconfdir}/bash_completion.d ]; then
    echo %{_sysconfdir}/bash_completion.d/mock >> %{name}.cfgs
fi

# reference valid mock.rpm's docdir with example site-defaults.cfg
mock_docs=%{_pkgdocdir}
mock_docs=${mock_docs//mock-core-configs/mock}
mock_docs=${mock_docs//-%{version}/-*}
sed -i "s~@MOCK_DOCS@~$mock_docs~" %{buildroot}%{_sysconfdir}/mock/site-defaults.cfg

%post
if [ -s %{_sysconfdir}/os-release ]; then
    # fedora and rhel7+
    if grep -Fiq Rawhide %{_sysconfdir}/os-release; then
        ver=rawhide
    # mageia
    elif [ -s %{_sysconfdir}/mageia-release ]; then
        if grep -Fiq Cauldron %{_sysconfdir}/mageia-release; then
           ver=cauldron
        fi
    else
        ver=$(source %{_sysconfdir}/os-release && echo $VERSION_ID | cut -d. -f1 | grep -o '[0-9]\+')
    fi
else
    # something obsure, use buildtime version
    ver=%{?rhel}%{?fedora}%{?mageia}
fi
%if 0%{?suse_version}
mock_arch=$(uname -m)
%else
if [ -s %{_sysconfdir}/mageia-release ]; then
    mock_arch=$(sed -n '/^$/!{$ s/.* \(\w*\)$/\1/p}' %{_sysconfdir}/mageia-release)
else
    mock_arch=$(%{python3} -c "import dnf.rpm; import hawkey; print(dnf.rpm.basearch(hawkey.detect_arch()))")
fi
%endif

cfg=unknown-distro
%if 0%{?fedora}
cfg=fedora-$ver-$mock_arch.cfg
%endif
%if 0%{?rhel}
# Being installed on RHEL, or a RHEL fork.  Detect it.
distro_id=$(. %{_sysconfdir}/os-release; echo $ID)
case $distro_id in
centos)
  # This package is EL8+, and there's only CentOS Stream now.
  distro_id=centos-stream
  ;;
almalinux)
  # AlmaLinux configs look like 'alma+epel'
  distro_id=alma
  ;;
esac
cfg=$distro_id+epel-$ver-$mock_arch.cfg
%endif
%if 0%{?mageia}
cfg=mageia-$ver-$mock_arch.cfg
%endif
%if 0%{?suse_version}
distro_id=$(. %{_sysconfdir}/os-release; echo $ID)
cfg=$distro_id-$mock_arch.cfg
%endif

if [ -e %{_sysconfdir}/mock/$cfg ]; then
    if [ "$(readlink %{_sysconfdir}/mock/default.cfg)" != "$cfg" ]; then
        ln -s $cfg %{_sysconfdir}/mock/default.cfg 2>/dev/null || ln -s -f $cfg %{_sysconfdir}/mock/default.cfg.rpmnew
    fi
else
    echo "Warning: file %{_sysconfdir}/mock/$cfg does not exist."
    echo "         unable to update %{_sysconfdir}/mock/default.cfg"
fi
:

%files -f %{name}.cfgs
%defattr(0644, root, root)
%dir %{_sysconfdir}/mock/
%dir %{_sysconfdir}/mock/eol/
%dir %{_sysconfdir}/mock/eol/templates
%dir %{_sysconfdir}/mock/templates

%license COPYING
%ghost %config(noreplace,missingok) %{_sysconfdir}/mock/default.cfg

%changelog
openSUSE Build Service is sponsored by