Issue
I have a subdir my_sw that has an image of what I want to install:
my_sw/
usr/
bin/
foo
man/
man1/
foo.1
and so on. I imagine there must be a simple way to create a spec file and use rpmbuild to package this up as an RPM so other users can install it. I don't care about any of the fancy build stuff rpm can do, I just want it to install that dir tree. (I suppose I'm misusing rpm a bit, but this way my users will have my files tracked in their rpm database, which they'd like.)
I've tried various things, but rpm wants to do way more than I want it to, and most projects want rpm to do lots more as well (pre-building, building, testing things, stripping, etc.) Is there a howto somewhere showing how to just put together a trivial rpm that just installs files?
I'm doing this on CentOS 5 or 6 (or similar RedHat).
Solution
Yes, you can create RPMs from a filesystem image such as you describe. It is one of the easier cases for RPM building, but you still have to use the tools.
The steps are roughly:
1) Create an RPM building environment, if you have not already done so. At its barest, that would be a subdirectory tree under your home directory, like so:
rpm/
BUILD/
RPMS/
x86_64/ (or whatever is the applicable arch)
SOURCES/
SPECS/
SRPMS/
2) Create a tarball of the image, and drop it in the SOURCES/ directory.
3) Create a spec file in the SPEC/ subdirectory. There are tools that can help you create a spec file skeleton. For example, if the "rpmdevtools" package is available to you (which it is for CentOS 5 and 6) then you can use "rpmdev-newspec". You will need to fill in some fields and provide some (minor, in your case) shell commands. The result might be something like this:
Name: my_sw
Summary: Cool software
Version: 1.0
Release: 1
Group: Applications
License: <license>
Source0: my_sw.tar.gz
%description
my_sw does awesome things that you'll really like. If you have any need for
awesomeness, this is for you!
%prep
# different from the default:
%setup -q -c -T
%build
# nothing to do
%install
# Start clean
rm -rf %{buildroot}
mkdir -p %{buildroot}
# Put the files in the correct location relative to %{buildroot}
ln -s %{buildroot} ./my_sw
tar xzf %{S:0}
%files
%defattr(-,root,root,-)
%{_bindir}/foo
%{_mandir}/man1/foo.1
%changelog
* Wed Aug 27 2014 Gary O <[email protected]> 1.0-1
- Initial spec
Some of that goes into the ultimate RPM; the rest tells rpmbuild details of what it needs to do.
4) Build it with rpmbuild:
rpmbuild -ba SPECS/my_sw.spec
5) The binary RPM will be in RPMS/. The source RPM will be in SRPMS/.
One of the best RPM building references I have ever found is the Fedora Project's RPM guide: http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/index.html. See especially chapter 9.
Answered By - John Bollinger Answer Checked By - Marilyn (WPSolving Volunteer)