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

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