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

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