%global debug_package %{nil}
%{!?_licensedir:%global license %%doc}


Name:           disks-keepalive
Version:        1.0
Release:        1%{?dist}
Group:          Applications/System
License:        MIT
URL:            https://copr.fedorainfracloud.org/coprs/scx/disks-keepalive/
Summary:        An utility that can disable extensive head parking

Source0:        %{name}.tar.gz


BuildRequires:  bash
BuildRequires:  coreutils
BuildRequires:  sed
# for %%{_unitdir} macro
BuildRequires:  systemd


Requires:       bash
Requires:       coreutils
Requires:       grep
# smartctl
Requires:       smartmontools
Requires:       systemd
# blkid
Requires:       util-linux


%description
An utility that can disable extensive head parking for specified disk drives.
It is based on smartctl and can be considered as an equivalent of idle3-tools.


%prep
%setup -q -n "%{name}"


%build
%{__cp} -p "%{name}.sample" "%{name}.conf"
%{__sed} -i -re 's/^([[:blank:]]*[^#])/#\1/' "%{name}.conf"
touch -r "%{name}.sample" "%{name}.conf"


%install
%{__install} -d "%{buildroot}%{_bindir}/"
%{__install} -d "%{buildroot}%{_sysconfdir}/"
%{__install} -d "%{buildroot}%{_datadir}/%{name}/"
%{__install} -d "%{buildroot}%{_unitdir}/"
%{__install} -Dpm 0755 "%{name}" -t "%{buildroot}%{_bindir}/"
%{__install} -Dpm 0644 "%{name}.conf" -t "%{buildroot}%{_sysconfdir}/"
%{__install} -Dpm 0644 "%{name}.sample" -t "%{buildroot}%{_datadir}/%{name}/"
%{__install} -Dpm 0644 "%{name}.service" -t "%{buildroot}%{_unitdir}/"


%post
%systemd_post %{name}.service


%preun
%systemd_preun %{name}.service


%postun
%systemd_postun_with_restart %{name}.service


%files
%doc README
%license COPYING
%{_bindir}/%{name}
%config(noreplace) %{_sysconfdir}/%{name}.conf
%{_datadir}/%{name}/%{name}.sample
%{_unitdir}/%{name}.service


%changelog
* Mon Jan 24 2022 Tomasz Tomasik <scx.mail@gmail.com> - 1.0-1
- Initial build for EL7