[lug] tweaking RPM spec files

D. Stimits stimits at idcomm.com
Wed Aug 7 23:49:21 MDT 2002


I'm tweaking an out-of-date spec file for some UPS software (the "nut" 
package). The old version was 0.45.4, then there were a couple of 
upgrades, and a test version which is a "pre-final" type release is 
0.99.0. I am trying to use the old spec file (which is in the tarball 
but not current) to create rpm's. I am almost successful, it builds 
everything but the binary programs that act as drivers. So I was looking 
at the 0.45 spec file, and now I am scratching my noggin a bit more than 
usual: Neither the "driver" subdirectory (where the driver binary 
programs are compiled to), nor any driver files, are listed anywhere in 
the spec files, directly or indirectly through macros. [note: the 
drivers are full programs being called by wrapper scripts, they are not 
libraries or modules]

So...how is it that a source rpm rebuild from 0.45 will create binary 
rpm's that also have the binary programs, yet the "nearly same" file in 
0.99 in no way references these binaries for install? This is long, but 
pasted below (beware line wrap) is the spec file I am using. The 
original 0.45 and friends are available at
  http://www.exploits.org/nut/

Is there some magic incantation or human sacrifice ritual that must be 
performed to get the binaries without mentioning them or the directory 
in the spec file? In the spec file, if you look at the section 8 man 
pages (sounds like Klinger on M.A.S.H.), these man pages are for the 
binaries, which end up installed in /sbin/ (if it is a working rpm).

D. Stimits, stimits at idcomm.com

%define version 0.99.0
%define relver 1

# what version of RH are we building for?
%define redhat7 1
%define redhat6 0

# Options for Redhat version 6.x:
# rpm -ba|--rebuild --define "rh6 1"
%{?rh6:%define redhat7 0}
%{?rh6:%define redhat6 1}

# some systems dont have initrddir defined
%{?_initrddir:%define _initrddir /etc/rc.d/init.d}

Name: nut
Group: Applications/System
Summary: Multi-vendor UPS Monitoring Project Client Utilities
Version: %{version}
Release: %{relver}
Source: http://www.exploits.org/nut/release/%{name}-%{version}.tar.gz
Copyright: GPL
BuildRoot: /var/tmp/%{name}-%{version}-root
Prereq: chkconfig fileutils
Obsoletes: nut-client
#
# configure file locations
# confdir etc are not really negotiable, so are not configurable here
%define STATEPATH  	/var/state/ups
%define CGIPATH   	/var/www/nut-cgi-bin
%define MODELPATH	/usr/sbin
%define CONFPATH	/etc/ups


%description
These programs are part of a developing project to monitor the assortment
of UPSes that are found out there in the field. Many models have serial
ports of some kind that allow some form of state checking. This
capability has been harnessed where possible to allow for safe shutdowns,
live status tracking on web pages, and more.

This package includes the client utilities that are required to monitor a
UPS that the client host is powered from - either connected directly via
a serial port (in which case the main nut package needs to be installed on
this machine) or across the network (where another host on the network
monitors the UPS via serial cable and runs the main nut package to allow
clients to see the information).

%package server
Requires: nut
Summary: Multi-vendor UPS Monitoring Project server
Group: Applications/System
Requires: nut = %{version}

%description server
These programs are part of a developing project to monitor the assortment
of UPSes that are found out there in the field. Many models have serial
serial ports of some kind that allow some form of state checking. This
capability has been harnessed where possible to allow for safe shutdowns,
live status tracking on web pages, and more.

This package is the main NUT upsd daemon and the associated per-UPS-model
drivers which talk to the UPSes.  You also need to install the base NUT
package.

%package cgi
Group: Applications/System
Summary: CGI utils for Multi-vendor UPS Monitoring Project
Requires: gd >= 1.6
BuildRequires: gd-devel >= 1.6, libpng-devel

%description cgi
These programs are part of a developing project to monitor the assortment
of UPSes that are found out there in the field. Many models have serial
serial ports of some kind that allow some form of state checking. This
capability has been harnessed where possible to allow for safe shutdowns,
live status tracking on web pages, and more.

This package adds the web CGI programs.   These can be installed on a
separate machine to the rest of the NUT package.

%prep
%setup -q
autoconf

%build
autoconf
CFLAGS="$RPM_OPT_FLAGS" ./configure \
	--prefix=/usr \
	--exec-prefix=/usr \
	--sysconfdir=%{CONFPATH} \
	--with-statepath=%{STATEPATH} \
	--with-modelpath=%{MODELPATH} \
	--with-cgipath=%{CGIPATH} \
	--with-user=ups \
	--with-group=ups \
	--mandir=%{_mandir} \
	--enable-shared \
	--with-linux-hiddev=/usr/src/linux-2.4/include/linux \
	--with-cgi
make

%install
rm -rf %{buildroot}
#
# Build basic directories here - if they exist already then the
# installer doesn't try to create and chown them (the chown is
# a killer if we are building as non-root
mkdir -p %{buildroot}%{CONFPATH}
mkdir -p %{buildroot}%{MODELPATH}
mkdir -p %{buildroot}%{CGIPATH}
mkdir -p %{buildroot}%{STATEPATH}
mkdir -p %{buildroot}%{_mandir}
mkdir -p %{buildroot}/usr/bin
mkdir -p %{buildroot}/usr/sbin
make INSTALLROOT=%{buildroot} install
make INSTALLROOT=%{buildroot} install-cgi

# move the *.sample config files to their real locations
# we don't need to worry about overwriting anything since
# they are marked as %config files within the package
for file in %{buildroot}%{CONFPATH}/*.sample
do
     mv $file %{buildroot}%{CONFPATH}/`basename $file .sample`
done

# install SYSV init stuff
mkdir -p %{buildroot}%{_initrddir}
install scripts/RedHat-6.0/upsd %{buildroot}%{_initrddir}
install scripts/RedHat-6.0/upsmon %{buildroot}%{_initrddir}
%if %{redhat7}
install scripts/RedHat-6.0/upspowerdown.rh7 
%{buildroot}%{_initrddir}/upspowerdown
%else
install scripts/RedHat-6.0/upspowerdown %{buildroot}%{_initrddir}
%endif

%preun
# only do this if it is not an upgrade
if [ $1 -eq 0 ]
then
    /sbin/chkconfig --del upsmon
    [ -f %{_initrddir}/upsmon ] && \
    	%{_initrddir}/upsmon stop
fi

%post
/sbin/chkconfig --add upsmon
# restart server if this is an upgrade
if [ $1 -gt 1 ]
then
    [ -f %{_initrddir}/upsmon ] && \
    	%{_initrddir}/upsmon restart
fi


%preun server
# only do this if it is not an upgrade
if [ $1 -eq 0 ]
then
    /sbin/chkconfig --del upspowerdown
    /sbin/chkconfig --del upsd
    [ -f %{_initrddir}/upsd ] && \
    	%{_initrddir}/upsd stop
fi

%post server
/sbin/chkconfig --add upspowerdown
/sbin/chkconfig --add upsd
# restart server if this is an upgrade
if [ $1 -gt 1 ]
then
    [ -f %{_initrddir}/upsd ] && \
    	%{_initrddir}/upsd restart
fi

%clean
rm -rf %{buildroot}

%files server
%defattr(-,root,root)
%{MODELPATH}
/usr/sbin/upsd
%attr(755,root,root) %{_initrddir}/upspowerdown
%attr(755,root,root) %{_initrddir}/upsd
%dir %attr(755,root,root) %{CONFPATH}
%config(noreplace) %attr(444,root,root) %{CONFPATH}/ups.conf
%config(noreplace) %attr(444,root,root) %{CONFPATH}/upsd.conf
%config(noreplace) %attr(600,root,root) %{CONFPATH}/upsd.users
%{_mandir}/man8/apcsmart.8.gz
%{_mandir}/man8/belkin.8.gz
%{_mandir}/man8/bestups.8.gz
%{_mandir}/man8/fentonups.8.gz
%{_mandir}/man8/newapc.8.gz
%{_mandir}/man8/nutupsdrv.8.gz
%{_mandir}/man8/powercom.8.gz
%{_mandir}/man8/upsd.8.gz
%{_mandir}/man8/upsdrvctl.8.gz
%{_mandir}/man5/ups.conf.5.gz
%{_mandir}/man5/upsd.conf.5.gz
%{_mandir}/man5/upsd.users.5.gz


%files
%defattr(-,root,root)
%doc CHANGES COPYING CREDITS INSTALL README docs/
%dir %attr(755,root,root) %{CONFPATH}
%config(noreplace) %attr(644,root,root) %{CONFPATH}/hosts.conf
%config(noreplace) %attr(600,root,root) %{CONFPATH}/upsmon.conf
%config(noreplace) %attr(600,root,root) %{CONFPATH}/upssched.conf
##%config(noreplace) %attr(644,root,root) /etc/sysconfig/ups
%dir %attr(755,ups,ups) %{STATEPATH}
%attr(755,root,root) %{_initrddir}/upsmon
/usr/bin/upsc
/usr/bin/upscmd
/usr/bin/upsct
/usr/bin/upsct2
/usr/bin/upslog
/usr/sbin/upsmon
/usr/sbin/upssched
%{_mandir}/man5/upsmon.conf.5.gz
%{_mandir}/man5/upssched.conf.5.gz
%{_mandir}/man8/nutupsdrv.8.gz
%{_mandir}/man8/upsc.8.gz
%{_mandir}/man8/upsct.8.gz
%{_mandir}/man8/upsct2.8.gz
%{_mandir}/man8/upslog.8.gz
%{_mandir}/man8/upscmd.8.gz
%{_mandir}/man8/upsmon.8.gz
%{_mandir}/man8/upssched.8.gz

%files cgi
%defattr(-,root,root)
%dir %attr(755,root,root) %{CONFPATH}
%config(noreplace) %attr(644,root,root) %{CONFPATH}/multimon.conf
%config(noreplace) %attr(600,ups,root) %{CONFPATH}/upsset.conf
%config(noreplace) %attr(644,root,root) %{CONFPATH}/hosts.conf
%dir %{CGIPATH}
%{CGIPATH}/multimon.cgi
%{CGIPATH}/upsimage.cgi
%{CGIPATH}/upsset.cgi
%{CGIPATH}/upsstats.cgi

%changelog
* Thu Feb  7 2002 Nigel Metheringham <Nigel.Metheringham at InTechnology.co.uk>
- Rearranged config files again
- Updated startup files (for RH 7x - rpm builds for eith 6x or 7x)
- More man pages
- Macrofied even more of the spec file
- stripped SNMP support for main line, will fully integrate soon

* Fri Feb  1 2002 Nigel Metheringham <Nigel.Metheringham at InTechnology.co.uk>
- Integrated SNMP support back in (from my branch)
- moved the config files around a little - default into samples subdir

* Wed Oct 24 2001 Peter Bieringer <pb at bieringer.de> (0.45.3pre1)
- Take man path given by rpm instead of hardwired
- Add some missing man pages to %files

* Wed Feb 07 2001 Karl O. Pinc <kop at meme.com> (0.44.3-pre2)
- Cgi package buildrequires gd >= 1.6
- Added man pages for apcsmart and powercom models

* Tue Dec 05 2000 <Nigel.Metheringham at InTechnology.co.uk> (0.44.2)
- Made cgi package standalone (needs no other parts of NUT)
- Moved some configs into cgi
- Shared hosts.conf between cgi & main

* Fri Nov 24 2000 <Nigel.Metheringham at InTechnology.co.uk> (0.44.2)
- Moved models to be more FHS compliant and make sure they are there
   if everything but root is unmounted
- Moved a few things around

* Mon Aug 21 2000 <Nigel.Metheringham at Vdata.co.uk> (0.44.1)
- Added new model drivers into rpm list
- Made it wildcard more stuff so this doesn't need to be
   maintained for every little change.
   ** NOTE this breaks things if modelpath isn't distinct **

* Mon Jul 17 2000 <Nigel.Metheringham at Vdata.co.uk> (0.44.0)
- Fixed some problems in the spec file
- Dropped the older changelog entries since there is some
   intermediate history thats been missed.
- Added new model drivers into rpm list
- Updated descriptions somewhat





More information about the LUG mailing list