Blame SPECS/redhat-cloud-client-configuration.spec

523e72
Name:           redhat-cloud-client-configuration
523e72
Version:        1
523e72
Release:        10%{?dist}
523e72
Summary:        Red Hat cloud client configuration
523e72
License:        GPLv2+
523e72
URL:            https://github.com/RedHatInsights/redhat-cloud-client-configuration
523e72
523e72
Source0: insights-register.path.in
523e72
Source1: insights-register.service.in
523e72
Source2: insights-unregister.path.in
523e72
Source3: insights-unregister.service.in
523e72
Source4: 80-insights-register.preset
523e72
Source5: insights-unregistered.path.in
523e72
Source6: insights-unregistered.service.in
523e72
Source7: rhcd.path.in
523e72
Source8: rhcd-stop.path.in
523e72
Source9: rhcd-stop.service.in
523e72
Source10: 80-rhcd-register.preset
523e72
Source11: LICENSE
523e72
523e72
BuildArch:      noarch
523e72
523e72
Requires:      insights-client
523e72
Requires:      subscription-manager
523e72
523e72
%if 0%{?rhel} >= 8
523e72
Requires:      rhc
523e72
%endif
523e72
523e72
BuildRequires: systemd
523e72
523e72
%description
523e72
Configure client autoregistration for cloud environments
523e72
523e72
%prep
523e72
# we have no source
523e72
523e72
523e72
%build
523e72
# insights-client
523e72
sed -e 's|@sysconfdir@|%{_sysconfdir}|g' %{SOURCE0} > insights-register.path
523e72
sed -e 's|@bindir@|%{_bindir}|g' %{SOURCE1} > insights-register.service
523e72
sed -e 's|@sysconfdir@|%{_sysconfdir}|g' %{SOURCE2} > insights-unregister.path
523e72
sed -e 's|@sysconfdir@|%{_sysconfdir}|g' -e 's|@bindir@|%{_bindir}|g' %{SOURCE3} > insights-unregister.service
523e72
sed -e 's|@sysconfdir@|%{_sysconfdir}|g' %{SOURCE5} > insights-unregistered.path
523e72
sed -e 's|@sysconfdir@|%{_sysconfdir}|g' %{SOURCE6} > insights-unregistered.service
523e72
523e72
%if 0%{?rhel} >= 8
523e72
# rhcd
523e72
sed -e 's|@sysconfdir@|%{_sysconfdir}|g' %{SOURCE7} > rhcd.path
523e72
sed -e 's|@sysconfdir@|%{_sysconfdir}|g' %{SOURCE8} > rhcd-stop.path
523e72
sed -e 's|@sysconfdir@|%{_sysconfdir}|g' %{SOURCE9} > rhcd-stop.service
523e72
%endif
523e72
523e72
%install
523e72
# insights-client
523e72
install -d %{buildroot}%{_unitdir}
523e72
install -m644 insights-register.path    %{buildroot}%{_unitdir}/
523e72
install -m644 insights-register.service %{buildroot}%{_unitdir}/
523e72
install -m644 insights-unregister.path    %{buildroot}%{_unitdir}/
523e72
install -m644 insights-unregister.service %{buildroot}%{_unitdir}/
523e72
install -m644 insights-unregistered.path %{buildroot}%{_unitdir}/
523e72
install -m644 insights-unregistered.service %{buildroot}%{_unitdir}/
523e72
install -d %{buildroot}%{_presetdir}
523e72
install -m644 %{SOURCE4} -t %{buildroot}%{_presetdir}/
523e72
523e72
%if 0%{?rhel} >= 8
523e72
# rhcd
523e72
install -D -m644 rhcd.path %{buildroot}%{_unitdir}/
523e72
install -D -m644 rhcd-stop.path %{buildroot}%{_unitdir}/
523e72
install -D -m644 rhcd-stop.service %{buildroot}%{_unitdir}/
523e72
install -m644 %{SOURCE10} -t %{buildroot}%{_presetdir}/
523e72
%endif
523e72
523e72
%post
523e72
# insights-client
523e72
%systemd_post insights-register.path
523e72
%systemd_post insights-unregister.path
523e72
%systemd_post insights-unregistered.path
523e72
#rhcd
523e72
%if 0%{?rhel} >= 8
523e72
%systemd_post rhcd.path
523e72
%systemd_post rhcd-stop.path
523e72
%endif
523e72
523e72
# Make sure that rhsmcertd.service is enabled and running
523e72
%systemd_post rhsmcertd.service
523e72
# Run following block only during installation (not during update)
523e72
if [ $1 -eq 1 ]; then
523e72
    # Try to get current value of auto-registration in rhsm.conf
523e72
    subscription-manager config --list | grep -q '^[ \t]*auto_registration[ \t]*=[ \t]*1'
523e72
    if [ $? -eq 0 ]; then
523e72
        auto_reg_enabled=1
523e72
    else
523e72
        auto_reg_enabled=0
523e72
    fi
523e72
523e72
    # Try to get current value of manage_repos
523e72
    subscription-manager config --list | grep -q '^[ \t]*manage_repos[ \t]*=[ \t]*0'
523e72
    if [ $? -eq 0 ]; then
523e72
        manage_repos_enabled=0
523e72
    else
523e72
        manage_repos_enabled=1
523e72
    fi
523e72
523e72
    # When we are going to change any configuration value, then save original rhsm.conf
523e72
    if [ $auto_reg_enabled -eq 0 -o $manage_repos_enabled -eq 1 ]; then
523e72
        echo -e "#\n# Automatic backup of rhsm.conf created by %{name} installation script\n#\n" \
523e72
            > /etc/rhsm/rhsm.conf.cloud_save
523e72
        cat /etc/rhsm/rhsm.conf >> /etc/rhsm/rhsm.conf.cloud_save
523e72
    fi
523e72
523e72
    # Enable auto-registration in rhsm.conf
523e72
    if [ $auto_reg_enabled -eq 0 ]; then
523e72
        subscription-manager config --rhsmcertd.auto_registration=1
523e72
    fi
523e72
523e72
    # Disable management of redhat.repo on systems running in
523e72
    # public cloud, because content is provided by RHUI
523e72
    if [ $manage_repos_enabled -eq 1 ]; then
523e72
        subscription-manager config --rhsm.manage_repos=0
523e72
    fi
523e72
523e72
    # Restart rhsmcertd to reload configuration file, when it is necessary
523e72
    if [ $auto_reg_enabled -eq 0 -o $manage_repos_enabled -eq 1 ]; then
523e72
        /bin/systemctl restart rhsmcertd.service
523e72
    fi
523e72
fi
523e72
523e72
%preun
523e72
if [ $1 -eq 0 ]; then
523e72
    # Packager removal, unmask register if exists
523e72
    /bin/systemctl unmask --now insights-register.path > /dev/null 2>&1 || :
523e72
%if 0%{?rhel} >= 8
523e72
    /bin/systemctl unmask --now rhcd.path > /dev/null 2>&1 || :
523e72
%endif
523e72
fi
523e72
%systemd_preun insights-register.path
523e72
%systemd_preun insights-unregister.path
523e72
%systemd_preun insights-unregistered.path
523e72
523e72
%if 0%{?rhel} >= 8
523e72
%systemd_preun rhcd.path
523e72
%systemd_preun rhcd-stop.path
523e72
%endif
523e72
523e72
%postun
523e72
%systemd_postun insights-register.path
523e72
%systemd_postun insights-unregister.path
523e72
%systemd_postun insights-unregistered.path
523e72
523e72
%if 0%{?rhel} >= 8
523e72
%systemd_postun rhcd.path
523e72
%systemd_postun rhcd-stop.path
523e72
%endif
523e72
523e72
523e72
if [ $1 -eq 0 ]; then
523e72
    if [ -f /etc/rhsm/rhsm.conf.cloud_save ]; then
523e72
        rhsmcertd_restart_required=0
523e72
523e72
        # When auto-registration was originally disabled and we had
523e72
        # to enable it during installation of this RPM, then disable it
523e72
        # again during removal of RPM package to restore original state.
523e72
        grep -q '^[ \t]*auto_registration[ \t]*=[ \t]*0' /etc/rhsm/rhsm.conf.cloud_save
523e72
        if [ $? -eq 0 ]; then
523e72
            subscription-manager config --rhsmcertd.auto_registration=0
523e72
            rhsmcertd_restart_required=1
523e72
        fi
523e72
523e72
        # When managing was originally enabled, then enable it again
523e72
        grep -q '^[ \t]*manage_repos[ \t]*=[ \t]*1' /etc/rhsm/rhsm.conf.cloud_save
523e72
        if [ $? -eq 0 ]; then
523e72
            subscription-manager config --rhsm.manage_repos=1
523e72
            rhsmcertd_restart_required=1
523e72
        fi
523e72
523e72
        # Restart rhsmcertd to propagate change in rhsm.conf
523e72
        if [ $rhsmcertd_restart_required -eq 1 ]; then
523e72
            %systemd_postun_with_restart rhsmcertd.service
523e72
        fi
523e72
523e72
        # Script should clean up after itself
523e72
        rm -f /etc/rhsm/rhsm.conf.cloud_save
523e72
    fi
523e72
fi
523e72
523e72
523e72
%files
523e72
%{_unitdir}/*
523e72
%{_presetdir}/*
523e72
523e72
523e72
%changelog
523e72
* Fri Sep 16 2022 Gael Chamoulaud <gchamoul@redhat.com> - 1-10
523e72
- Remove preset files from %post directive
523e72
523e72
* Wed Jul 06 2022 Gaël Chamoulaud <gchamoul@redhat.com> - 1-9
523e72
- Add LICENSE file
523e72
523e72
* Mon Jul 04 2022 Gaël Chamoulaud <gchamoul@redhat.com> - 1-8
523e72
- Fix bad date format in Changelog
523e72
523e72
* Mon Jul 04 2022 Gaël Chamoulaud <gchamoul@redhat.com> - 1-7
523e72
- Remove conditional for rhcd sources
523e72
- Fix: systemctl absolute path for rhel7
523e72
523e72
* Thu Jun 30 2022 Gaël Chamoulaud <gchamoul@redhat.com> - 1-6
523e72
- Split preset insights-client and rhcd. RHEL7 compatibility.
523e72
- Add autoregistration when insights-client manually unregister
523e72
523e72
* Thu Jun 30 2022 Gaël Chamoulaud <gchamoul@redhat.com> - 1-5
523e72
- Disable RHSM config option manage_repos during installation
523e72
- Enable rhcd auto-enablement only for RHEL>=8
523e72
523e72
* Thu Jun 23 2022 Gaël Chamoulaud <gchamoul@redhat.com> - 1-4
523e72
- Add gating.yaml file
523e72
523e72
* Thu Jun 23 2022 Gaël Chamoulaud <gchamoul@redhat.com> - 1-3
523e72
- Fix - Executable path is not absolute, ignoring: systemctl
523e72
523e72
* Thu Jun 16 2022 Gaël Chamoulaud <gchamoul@redhat.com> - 1-2
523e72
- fix - remove .in suffix from rhcd unit files
523e72
- remove rhcd-override.conf
523e72
- add rhcd path files to monitor existence of cert file + add rhcd stop service file which can stop rhcd when system is unsubscribed
523e72
523e72
* Tue May 31 2022 Link Dupont <link@redhat.com> - 1-1
523e72
- fix up some spec file descriptions
523e72
- add override to automatically activate rhcd
523e72
523e72
* Tue May 17 2022 Alba Hita Catala <ahitacat@redhat.com> - 1-1
523e72
- insights-client autoregistration