File suse-online-update.spec of Package suse-online-update
#
# spec file for package suse-online-update
#
# Copyright (c) 2016-2019 SUSE LINUX GmbH, Nuernberg, Germany.
# Author: Lars Vogdt
#
# 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 http://bugs.opensuse.org/
#
%if 0%{?suse_version} >= 1210
%bcond_without systemd
%else
%bcond_with systemd
%endif
Name: suse-online-update
Summary: Simple script to execute online updates automatically
License: BSD-4-Clause
Group: System/Monitoring
Version: 2.4.1
Release: 0
Url: https://github.com/lrupp/suse-online-update
Provides: abuild-online-update = %{version}-%{release}
Obsoletes: abuild-online-update < 1.2
Source0: %{name}-%version.tar.gz
Source4: suse-online-update-rpmlintrc
PreReq: %fillup_prereq
%if 0%{?suse_version} >= 1500
Requires: hostname
%endif
Requires: logrotate
Requires: mailx
Requires: zypper
Recommends: permissions
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%if ! %{defined _fillupdir}
%define _fillupdir /var/adm/fillup-templates
%endif
%if %{with systemd}
BuildRequires: systemd-rpm-macros
Requires(pre): systemd
%{?systemd_requires}
%else
Requires: cron
%endif
%description
This package contains a simple script installing all non-interactive
online updates automatically via daily cronjob.
Please configure this script via /etc/sysconfig/suse-online-update
%prep
%setup -q
%build
%install
install -Dm750 zypper_ps_restart %buildroot/%{_sbindir}/zypper_ps_restart
%if %{with systemd}
install -Dm644 %{name}.service %{buildroot}%{_unitdir}/%{name}.service
install -Dm644 %{name}.timer %{buildroot}%{_unitdir}/%{name}.timer
install -Dm755 suse.de-online-update %buildroot/%{_sbindir}/%{name}
%else
install -Dm755 suse.de-online-update %buildroot/%{_sysconfdir}/cron.daily/suse.de-online-update
%endif
install -Dm644 %{name}.sysconfig %buildroot/%{_fillupdir}/sysconfig.%{name}
install -Dm644 %{name}.logrotate %buildroot/%{_sysconfdir}/logrotate.d/%name
install -Dm644 README.md %buildroot/%{_defaultdocdir}/%{name}/README.SUSE
install -Dm644 %{name}.man8 %{buildroot}%{_mandir}/man8/%{name}.8
%check
%if %{with systemd}
output=$(%buildroot/%{_sbindir}/%{name} -h 2>&1) || :
%else
output=$(%buildroot/%{_sysconfdir}/cron.daily/suse.de-online-update -h 2>&1) || :
%endif
exit_code=$(echo $?)
expected_exit_code=0
if [ "$exit_code" != "$expected_exit_code" ]; then
echo "ERROR: exit code is not as expected: $exit_code"
exit 1
fi
%clean
rm -rf %buildroot
%if %{with systemd}
%pre
%service_add_pre %{name}.service %{name}.timer
%post
%service_add_post %{name}.service %{name}.timer
# enable the timer if the package is installed for the first time
if [ ${1:-0} -eq 1 ]; then
%{_bindir}/systemctl enable %{name}.timer
%{_bindir}/systemctl start %{name}.timer
fi
%{fillup_only %name}
%preun
%service_del_preun %{name}.service %{name}.timer
%postun
%service_del_postun %{name}.service %{name}.timer
%else
%post
%{fillup_only %name}
%endif
%files
%defattr(-, root, root)
%doc %{_defaultdocdir}/%{name}
%if %{with systemd}
%{_unitdir}/%{name}.service
%{_unitdir}/%{name}.timer
%{_sbindir}/%{name}
%else
%config %{_sysconfdir}/cron.daily/suse.de-online-update
%endif
%config(noreplace) %{_sysconfdir}/logrotate.d/%name
%{_sbindir}/zypper_ps_restart
%{_fillupdir}/sysconfig.%{name}
%{_mandir}/man8/%{name}.8*
%changelog