Building an rpm to install script files
On an rpm based system, say CentOS, first make sure that the rpm-build package is installed.
In your user account, not as root (bad form and all) make the following directories:
mkdir -p ~/rpm
mkdir -p ~/rpm/BUILD
mkdir -p ~/rpm/RPMS
mkdir -p ~/rpm/SOURCES
mkdir -p ~/rpm/SPECS
mkdir -p ~/rpm/SRPMS
mkdir -p ~/rpm/tmp
And create an ~/.rpmmacros file with the following in it:
%packager Your Name
%_topdir /home/YOUR HOME DIR/rpm
%_tmppath /home/YOUR HOME DIR/rpm/tmp
And now comes the fun part. Go to the ~/rpm/SOURCES directory and create a working package directory under that with the package name and a dash and the major revision number. For example, ~/rpm/SOURCES/linc-1. Now in that directory you will copy all the scripts/files that you wish to have in your package. For example, I might have a script in that directory called myscript.sh that I want to be installed as part of the linc package.
Once that is done, make a tarball of that directory in the ~/rpm/SOURCES directory named programname-revision.tar.gz. Using my previous example it would be:
tar czvf linc-1.tar.gz linc-1/
Now for the glue that makes this all stick together. Go to your ~/rpm/SPECS directory and create a spec file for your package. We’ll call mine linc.spec and it’ll look like this:
Summary: My first rpm script package
Name: linc
Version: 1
Release: 1
Source0: linc-1.tar.gz
License: GPL
Group: MyJunk
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-buildroot
%description
Make some relevant package description here
%prep
%setup -q
%build
%install
install -m 0755 -d $RPM_BUILD_ROOT/opt/linc
install -m 0755 myscript.sh $RPM_BUILD_ROOT/opt/linc/myscript.sh
%clean
rm -rf $RPM_BUILD_ROOT
%post
echo " "
echo "This will display after rpm installs the package!"
%files
%dir /opt/linc
/opt/linc/myscript.sh
A lot of that file is pretty self explanatory except then install lines and the lines after %file. The install lines tell rpm what to install where and with what permissions. You also have to do any directory creation there as well (the one with the -d in the line). The things after %file are similar in that this tells rpm’s database which files are attached to this package. The %dir signifies a new directory, otherwise the files are listed with their complete paths.
Now that you have all that together. The last thing you need do is create the package. Just go to ~/rpm and do an “rpmbuild -ba SPECS/linc.spec”. You will end up with an ~/rpm/RPMS/noarch/linc-1-1.noarch.rpm if all goes well.
You might want to check out the rpm package rpmdevtools. It includes a tool called rpmdev-setuptree that will build you a proper ~/rpmbuild directory + sub. dirs. It will also make you a ~/.rpmmacros file. It is part of the epel repository.
You can find out more about this repo over here:
fedoraproject.org/wiki/EPEL
Good description of repos and CentOS:
wiki.centos.org/AdditionalResources/Repositories
Also good is this page talking about setting priorities with yum:
wiki.centos.org/PackageManagement/Yum/Priorities
If you’re lazy like me and don’t want to mess with RPM hell I highly recommend switching to smart as your package manager:
labix.org/smart
[…] Lifted from Lic Fessden’s blog here 1 2 3 4 5 6 7 8 9 yum install rpm-build mkdir -p ~/rpm mkdir -p ~/rpm/BUILD mkdir -p […]
[…] building a basic RPM. The main source I used, to save reading my book again or the man pages, was Linc Fessenden’s blog and some of Linc’s blog is repeated here for completeness. Thanks […]