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

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