Making an RPM for a shell script.

So, you have written an enterprise quality shell script and would like to deploy it on serveral Red Hat based machines? Creating an RPM will make this easy to do. Here are the steps required.

1. Install rpmbuild so you may start to build your own RPMs.
2. Package your shell script into a tar.gz file and move that to /usr/src/redhat/SOURCES/

# tar -cvzf shell-script-0.1.tar.gz shell-script-0.1
# mv shell-script-0.1.tar.gz /usr/src/redhat/SOURCES/

3. Create a .spec file that describes where everything is.
# cat /usr/src/redhat/SPECS/shell-script.spec
Summary: The do it all script. (Enterprise quality)
Name: shell-script
Version: 0.1
Release: 1
URL:     http://meinit.nl
License: GPL
Group: Applications/Internet
BuildRoot: %{_tmppath}/%{name}-root
Requires: bash
Source0: shell-script-%{version}.tar.gz
BuildArch: noarch

%description
A shell script.

%prep
%setup

%build

%install
rm -rf ${RPM_BUILD_ROOT}
mkdir -p ${RPM_BUILD_ROOT}/usr/bin
install -m 755 shell-script.sh ${RPM_BUILD_ROOT}%{_bindir}

%clean
rm -rf ${RPM_BUILD_ROOT}

%files
%defattr(-,root,root)
%attr(755,root,root) %{_bindir}/shell-script.sh

%changelog
* Tue Jan 12 2010 Robert de Bock <[email protected]>
- Uberscript!

3. Build it!
# rpmbuild --bb /usr/src/redhat/SPECS/shell-script.spec

4. Install it!
# rpm -Uvh /usr/src/redhat/RPMS/noarch/shell-script-0.1.1.noarch.rpm

Comments

Hi All, I have to set a

Hi All,

I have to set a dependency in the rpm spec that should be check while installing the rpm on linux server.
let i m writing the spec for rpm X .This rpm can be install on linux server when suppose rpm Y is installed otherwise it will give the failed message. please let me know where i have to set this check in rpm spec .%post or %preun ..if possible pls give me the sample code for this.

Thanks,
Ashutosh

That's the "Requires:"

That's the "Requires:" parameter. It's near the top. In this example spec file "bash" is required.

Regards,

Robert de Bock.

Thanks Robert..

Thanks Robert..

hey can u refer me to site

hey can u refer me to site where i can find in detail for the syntax you are using here

or can u explain me i am a very beginner in this i just know shell scripting and don't want to cram

Thank you very much for this

Thank you very much for this informative article. Helped me get started.

My notes:

The script name should be shell-script and should be first copied into the directory shell-script-0.1.tar.gz; the tar should be run thereafter.

Last line: # rpm -Uvh /usr/src/redhat/RPMS/noarch/shell-script-0.1.1.noarch.rpm

Should be: # rpm -Uvh /usr/src/redhat/RPMS/noarch/shell-script-0.1.noarch.rpm

Sesh

Hi Could you please tell me i

Hi Could you please tell me i am doing the same with different script name but facing error

can you tell me why this errors for

+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd shell-script-0.1
/var/tmp/rpm-tmp.RmeqSp: line 38: cd: shell-script-0.1: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.RmeqSp (%prep)

RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.RmeqSp (%prep)

I guess your .tar.gz does not

I guess your .tar.gz does not unpack into a directory with the name "shell-script-0.1". So; first you have to tar.gz your shell scripts, which RPM will use. Something like this can be used to create that .tar.gz:
mkdir shell-script-0.1
mv myscript.sh sheel-script-0.1
tar -cvzf shell-script-0.1.tar.gz shell-script-0.1

Regards,

Robert de Bock.

Hi robert I execute the steps

Hi robert

I execute the steps mentioned above it create the rpm but my script which i want to run is not getting executed.
---------------------------------------------------------
Source folder name: Fusion-ioAgent-0.1.tar.gz

my spec file is this:
name:Fusion-ioAgent.spec

Summary: The rpm will install the fusion-ioAgent
Name: Fusion-ioAgent
Version: 0.1
Release: 1
License: GPL
Group: Applications/Internet
BuildRoot: %{_tmppath}/%{name}-root
Requires: bash
Source0: Fusion-ioAgent-%{version}.tar.gz
BuildArch: noarch

%description
This rpm will install the agent and uninstall the agent..

%prep
%setup

%build

%install
rm -rf ${RPM_BUILD_ROOT}
mkdir -p ${RPM_BUILD_ROOT}/usr/bin
install -m 755 installer.sh ${RPM_BUILD_ROOT}%{_bindir}

%clean
rm -rf ${RPM_BUILD_ROOT}

%files
%defattr(-,root,root)
%attr(755,root,root) %{_bindir}/installer.sh

In this section iam writing my script name "installer.sh" which is present in the Fusion-ioAgent-0.1.tar.gz

Iam not able to figure out why it is not calling the installer script.
can u please help me out with this.

You refer to the installer.sh

You refer to the installer.sh from %install and %files sections. There
will not execute code, they will just place and package the code.

In order to execute it, you can use %pre, %post, %preun or %postun.
These sections will execute some code, before installation, after
installation, before uninstallation or after uninstallation.

About Consultancy Articles Contact




References Red Hat Certified Architect By Robert de Bock Robert de Bock
Curriculum Vitae By Fred Clausen +31 6 14 39 58 72
By Nelson Manning [email protected]