File hddtemp.spec of Package hddtemp

# norootforbuild

%global beta    beta15
%global migfile %{_var}/run/systemd-migr_%{name}-%{version}-%{release}.%{_arch}

Name:           hddtemp
Version:        0.3
Release:        24.1
Summary:        Hard disk temperature tool

License:        GPLv2+
URL:            http://savannah.nongnu.org/projects/hddtemp/
Source0:        %{name}-%{version}-%{beta}.tar.bz2
Source1:        hddtemp.db
Source2:        %{name}.service
Source3:        %{name}.init
Source4:        %{name}.sysconfig
Source5:        %{name}.pam
Source6:        %{name}.consoleapp

Patch0:         %{name}-db.patch
Patch1:         hddtemp_0.3-beta15-48.diff.gz
# https://bugzilla.redhat.com/show_bug.cgi?id=717479
# https://bugzilla.redhat.com/show_bug.cgi?id=710055
Patch2:         %{name}-0.3-beta15-autodetect-717479.patch
# Debian patchset -48 forgets to add de to po/LINGUAS (maintainer notified)
Patch3:         %{name}-0.3-beta15-linguas-de.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-buildroot

BuildRequires:  gettext, perl, gawk, gcc

%if 0%{?suse_version}
Group:          System/Monitoring
BuildRequires:  net-tools
BuildRequires:  systemd
%endif

%if 0%{?fedora} || 0%{?rhel_version} || 0%{?centos_version}
Group:          Applications/System
BuildRequires:  systemd-units, systemd-sysv
Requires:       %{_bindir}/consolehelper
Requires(pre):  chkconfig
Requires(post): systemd-units
Requires(preun): systemd-units
Requires(postun): systemd-units
%endif


%description
hddtemp is a tool that gives you the temperature of your hard drive by
reading S.M.A.R.T. information.

%description -l de
htddtemp ist ein Tool zum auslesen der Festplattentemperatur aus den
S.M.A.R.T Informationenen.

%prep
%setup -q -n %{name}-%{version}-%{beta}

cp -p %{SOURCE1} ./hddtemp.db
%patch0 -p0
%patch1 -p1
%patch2 -p1
%patch3 -p1
sed -i -e s/Celius/Celsius/g po/*.po*
sed -i -e 's|/etc/hddtemp.db|/usr/share/misc/hddtemp.db|' doc/hddtemp.8

chmod -x contribs/analyze/*
rm COPYING ; cp -p GPL-2 COPYING
cp -p debian/changelog changelog.debian


%build
%configure --disable-dependency-tracking
make %{?_smp_mflags}


%install
%makeinstall

install -dm 755 %{buildroot}%{_bindir}
install -Dpm 644 hddtemp.db %{buildroot}%{_datadir}/misc/hddtemp.db
install -Dpm 644 %{SOURCE2} %{buildroot}%{_unitdir}/hddtemp.service

%if 0%{?suse_version}
%{__mkdir_p} %{buildroot}%{_sysconfdir}/init.d
%{__mkdir_p} %{buildroot}%{_sysconfdir}/default
%{__mkdir_p} %{buildroot}%{_datadir}/misc/
%{__mkdir_p} %{buildroot}/var/adm/fillup-templates
%{__mkdir_p} %{buildroot}/etc/
cd %{buildroot}/etc/
%{__ln_s} ..%{_datadir}/misc/hddtemp.db ./hddtemp.db
cd -
%{__install} -m 0755 %{SOURCE3} %{buildroot}%{_sysconfdir}/init.d/%{name}
%{__install} -m 0644 %{SOURCE4} %{buildroot}/var/adm/fillup-templates/sysconfig.%{name}
%endif

%if 0%{?fedora} || 0%{?rhel_version} || 0%{?centos_version}
install -Dpm 644 %{SOURCE4} %{buildroot}%{_sysconfdir}/sysconfig/hddtemp
ln -s consolehelper %{buildroot}%{_bindir}/hddtemp
install -Dpm 644 %{SOURCE5} %{buildroot}%{_sysconfdir}/pam.d/hddtemp
install -Dpm 644 %{SOURCE6} %{buildroot}%{_sysconfdir}/security/console.apps/hddtemp
%endif
%find_lang %{name}

%pre
rm -f %{migfile} &>/dev/null
if [ $1 -gt 1 ] && [ ! -e %{_unitdir}/hddtemp.service ] && \
   [ -e %{_initddir}/hddtemp ] ; then
    systemd-sysv-convert --save hddtemp &>/dev/null
    chkconfig --del hddtemp &>/dev/null
    touch %{migfile} &>/dev/null || :
fi

%post
[ $1 -eq 1 ] && systemctl daemon-reload &>/dev/null || :
%if 0%{?suse_version}
#%{fillup_only -n hddtemp}
%{fillup_and_insserv -Y hddtemp}
%endif

%preun
if [ $1 -eq 0 ] ; then
    systemctl --no-reload disable hddtemp.service &>/dev/null
    systemctl stop hddtemp.service &>/dev/null || :
fi
%if 0%{?suse_version}
if [ "$1" = "0" ]; then # remove
	chkconfig --del %{name}
fi
%{stop_on_removal hddtemp}
%endif


%postun

%if 0%{?fedora} || 0%{?rhel_version} || 0%{?centos_version}
systemctl daemon-reload &>/dev/null
[ $1 -gt 0 ] && systemctl try-restart hddtemp.service &>/dev/null || :
%endif

%if 0%{?suse_version}
%{restart_on_update hddtemp}
rm %{_sysconfdir}/sysconfig/hddtemp
%{insserv_cleanup}
%endif

%triggerpostun -- %{name}
if [ $1 -gt 0 ] && [ -e %{migfile} ] ; then
    systemctl status hddtemp.service
    systemctl daemon-reload &>/dev/null
    systemctl status hddtemp.service
    systemctl try-restart hddtemp.service &>/dev/null
    systemctl status hddtemp.service
fi
rm -f %{migfile} &>/dev/null || :


%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}


%files -f %{name}.lang
%defattr(-,root,root,-)
%doc ChangeLog changelog.debian COPYING README TODO contribs/
%{_unitdir}/hddtemp.service
%{_sbindir}/hddtemp
%config(noreplace) /usr/share/misc/hddtemp.db
%{_mandir}/man8/hddtemp.8*
%if 0%{?fedora} || 0%{?rhel_version} || 0%{?centos_version}
%config(noreplace) %{_sysconfdir}/sysconfig/hddtemp
%config(noreplace) %{_sysconfdir}/pam.d/hddtemp
%config(noreplace) %{_sysconfdir}/security/console.apps/hddtemp
%endif
%if 0%{?suse_version}
%config(noreplace) %{_sysconfdir}/init.d/%{name}
/var/adm/fillup-templates/sysconfig.%{name}
/etc/hddtemp.db
%endif

%changelog
* Mon Nov 28 2011 Agnelo de la Crotche <agnelo@unixversal.com>
- systemd compatible version ported from Fedora

* Thu Aug 18 2011 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.22.beta15
- Migrate to systemd, patch to glob usual device names w/o arguments (#717479).
- Update Debian patch set to 0.3-beta15-48, ship its changelog in docs.

* Wed Feb 09 2011 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.3-0.21.beta15
- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild

* Sun Feb 14 2010 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.20.beta15
- Patch to fix ix86 build if sys/ucontext.h is pulled in by signal.h (#564857).

* Thu Aug 20 2009 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.19.beta15
- Try to start daemon for all disks if none are specified in sysconfig.
- Update URLs.

* Fri Jul 24 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.3-0.18.beta15
- Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild

* Tue Feb 24 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.3-0.17.beta15
- Rebuilt for https://fedoraproject.org/wiki/Fedora_11_Mass_Rebuild

* Wed Oct  1 2008 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.16.beta15
- Sync with Debian's 0.3-beta15-45 for a fix for undesired spin-ups with
  most current drives (#464912).

* Sat Feb  9 2008 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.15.beta15
- Sync with Debian's 0.3-beta15-38.
- Update drive database to 2007-09-14.
- Trim pre-2006 changelog entries.

* Wed Sep  5 2007 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.14.beta15
- Adjust server chkconfig start/stop priorities to start before gkrellmd,
  other cosmetic init script tweaks.
- Mark hddtemp.db as %%config(noreplace).

* Mon Aug  6 2007 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.13.beta15
- License: GPLv2+

* Tue Jul 10 2007 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.12.beta15
- Improve init script LSB compliance.

* Tue Jan  9 2007 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.11.beta15
- SATA sense fix (#221100, Jens Axboe).

* Sun Dec 31 2006 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.10.beta15
- Apply patches from Debian containing bunch of hddtemp.db updates and
  guess mode improvements for drives not in the database.

* Wed Aug 30 2006 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.9.beta15
- Rebuild.

* Wed May  3 2006 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.8.beta15
- 0.3-beta15, drive database 2006-04-26.
- Specfile cleanups.

* Wed Feb  8 2006 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.8.beta14
- Update drive database to 2006-02-07.

* Wed Jan 18 2006 Ville Skytt <ville.skytta@iki.fi> - 0.3-0.7.beta14
- Update drive database to 2006-01-18.
- Init script is not a config file.
- Mark console.perms snippet as noreplace.