File bootcycle.spec of Package bootcycle

#
# spec file for package bootcycle
#
# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
#
# 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/
#


Name:           bootcycle
Version:        0.3
Release:        0
Summary:        Boot Cycle Detection
License:        GPL-2.0+
Group:          System/Boot
%if 0%{?suse_version} >= 1315
BuildRequires:  grub2
BuildRequires:  systemd-rpm-macros
PreReq:         %fillup_prereq
PreReq:         grub2
%{?systemd_requires}
%else
PreReq:         %fillup_prereq %insserv_prereq
%ifarch %ix86 x86_64
Requires:       grub
%endif
%ifarch %ia64
Requires:       efibootmgr
%endif
%endif
Source0:        sysconfig.bootloader-bootcycle
Source1:        boot.cycle.IA32
Source3:        boot.cycle.IA64
Source2:        README.IA32
Source4:        README.IA64
Source5:        boot.cycle.grub2
Source6:        bootcycle.service
Source7:        grub_menuentry_halt
Source8:        README.grub2
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if 0%{?suse_version} >= 1315
BuildArch:      noarch
%else
ExclusiveArch:  %ix86 ia64 x86_64
%endif

%description
This package provides a boot script that is used for boot cycle
detection to avoid unconditional reboot cycles on an unsupervised
system.  For example, on INTEL IA32 the GNU GRUB multiboot loader is
used for this.

%prep
%setup -n %{name}-%{version} -c -T
%if 0%{?suse_version} >= 1315
    cp %{SOURCE8} README
%else
%ifarch %ix86 x86_64
    cp %{SOURCE1} boot.cycle
    cp %{SOURCE2} README
%endif
%ifarch ia64
    cp %{SOURCE3} boot.cycle
    cp %{SOURCE4} README
%endif
%endif

%install
    install -d -m 0755 $RPM_BUILD_ROOT/var/adm/fillup-templates
    install -c -m 0644 %{SOURCE0} $RPM_BUILD_ROOT/var/adm/fillup-templates/
%if 0%{?suse_version} >= 1315
    install -D -m 0755 %{SOURCE5} $RPM_BUILD_ROOT/%{_sbindir}/bootcycle
    install -D -m 444 %{SOURCE6} $RPM_BUILD_ROOT/%{_unitdir}/bootcycle.service
    install -D -m 0755 %{SOURCE7} $RPM_BUILD_ROOT/%{_sysconfdir}/grub.d/50_bootcycle
%else
    install -d -m 0755 $RPM_BUILD_ROOT/etc/init.d/boot.d
    install -c -m 0755 boot.cycle $RPM_BUILD_ROOT/etc/init.d/
%endif

%pre
%if 0%{?suse_version} >= 1315
%service_add_pre bootcycle.service
%endif

%post
%{fillup_only -an bootloader}
%if 0%{?suse_version} >= 1315
%service_add_post bootcycle.service
/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg || :
%else
%{fillup_and_insserv -fY boot.cycle}
%endif

%preun
%if 0%{?suse_version} >= 1315
%service_del_preun bootcycle.service
%endif

%postun
%if 0%{?suse_version} >= 1315
%service_del_postun bootcycle.service
%else
%{insserv_cleanup}
%endif

%files
%defattr(-,root,root)
/var/adm/fillup-templates/*
%doc README
%if 0%{?suse_version} >= 1315
%{_sbindir}/bootcycle
%{_unitdir}/bootcycle.service
%config %{_sysconfdir}/grub.d/50_bootcycle
%else
%config /etc/init.d/boot.cycle
%endif

%changelog
openSUSE Build Service is sponsored by