Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create spec file ( RPM) [closed]

Tags:

linux

shell

rpm

I've 2 files which include shell command to be execute ,, and I've one iptables-save which include chain need to installed

How can I write the spec file to:

  1. copy my 2 shell files to /etc/
  2. execute iptables-restore < /home/iptables-save

P.S: I went through this how-to. Unfortunately I'm newbie in this, I couldn't find the solution.

like image 933
LeoSam Avatar asked Dec 03 '25 02:12

LeoSam


1 Answers

Had to do this just yesterday.

Create your build directory in your home as a normal user don't use root, just smart that way.

mkdir -p ~/rpmbuild/BUILD
mkdir -p ~/rpmbuild/BUILDROOT
mkdir -p ~/rpmbuild/RPMS
mkdir -p ~/rpmbuild/SOURCES
mkdir -p ~/rpmbuild/SPECS
mkdir -p ~/rpmbuild/SRPMCS
mkdir -p ~/rpmbuild/tmp

Next create rpmmacros so that rpmbuild knows where to build, contents of ~/.rpmmacros should contains the following

%packager Chris Hinshaw
%_topdir /home/chinshaw/rpmbuild
%_tmppath /home/chinshaw/rpmbuild/tmp

Next create the rpm spec found in ~/rpmbuild/SPECS/ . This example spec file will handle a script called demo script, it's configuration file that goes in etc and a third cron script that will schedule the script to run hourly.

~/rpmbuild/SPECS/demoproject.spec

Name:   demoproject     
Version:    0.1 
Release:    1%{?dist}
Summary:    Demo script for doing something cool

Group:  DemoGroup
License:    GPL
Source0:    demoproject-0.1.tar.gz
BuildRoot:  %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)


%description
Demo project that does something interesting

%prep
%setup -q


%build


%install
install --directory $RPM_BUILD_ROOT/usr/sbin
install --directory $RPM_BUILD_ROOT/etc
install --directory $RPM_BUILD_ROOT/etc/cron.d/

install -m 0755 demoscript $RPM_BUILD_ROOT/usr/sbin
install -m 0744 demoscript.conf $RPM_BUILD_ROOT/etc
install -m 0744 cron/democronscript $RPM_BUILD_ROOT/etc/cron.d/

%clean
rm -rf $RPM_BUILD_ROOT


%files
/usr/sbin/demoscript
/etc/demoscript.conf
/etc/cron.d/democronscript


%changelog

The only quirk I found was that I really needed to tar up my 3 source files in a tarball which seemed like a good idea anyway.

The contents or the rpmbuild/SOURCES directory should look like this.

$ cd ~/rpmbuild/SOURCES
$ ls 
demoproject-0.1.tar.gz
$ tar -tvzf demoproject-0.1.tar.gz
demoproject-0.1/
demoproject-0.1/demoscript.conf
demoproject-0.1/demoscript
demoproject-0.1/cron/
demoproject-0.1/cron/democronscript

then all you have to do is build it rpmbuild -ba ~/rpmbuild/SPECS/demoproject.spec

This will create arch rpms and srpms and land them in the ~/rpmbuild/RPMS and ~/rpmbuild/SRPMS directories.

like image 142
Chris Hinshaw Avatar answered Dec 04 '25 19:12

Chris Hinshaw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!