Mindtwist.de

...let your mind twist!

How to convert tar.gz archive to RPM

Sometimes you want to deploy a configuration file on a Red Hat or CentOS system via RPM but you don't know how to create the spec file for the rpmbuild command. The tgz2rpm shell script in this article helps you in the process to write your own RPM spec files. The directory structure in the tar.gz file should resemble the locations where you want to place your files beneath the filesystem root.

The Script

The tgz2rpm.sh script creates a RPM spec file from an tgz tarball. Although the spec file is ready to use to create a simple RPM, it may be used to create a spec file as starting point for a more sophisticated setup.

http://www.mindtwist.de/main/downloads.html?task=summary&cid=3&catid=3

Help

This is the help when executing the script without a tarball as commandline option:

$ ./tgz2rpm.sh 

This script has been released under BSD license.
Copyright (C) 2010 Reiner Rottmann <rei..rATrottmann.it>

./tgz2rpm.sh creates a simple RPM spec file from the contents of a tarball.
The output may be used as starting point to create more complex RPM spec files.
The contents of the tarball should reflect the final directory structure where
you want your files to be deployed. As the name and version get parsed
from the tarball filename, it has to follow the naming convention
"<name>-<ver.si.on>.tar.gz". The name may only contain characters from the
range [A-Z] and [a-z]. The version string may only include numbers seperated by dots.

Usage: ./tgz2rpm.sh  [TARBALL]

Example:
$ ./tgz2rpm.sh sample-1.0.0.tar.gz

$ /usr/bin/rpmbuild -ba /tmp/sample-1.0.0.spec

The Script in Action

[rottmrei@vcentos01 ~]$ mkdir -p usr/local/bin
[rottmrei@vcentos01 ~]$ touch usr/local/bin/samplescript.sh
[rottmrei@vcentos01 ~]$ tar -czf samplescript-1.0.0.tar.gz usr/
[rottmrei@vcentos01 ~]$ tar -tzf samplescript-1.0.0.tar.gz
usr/
usr/local/
usr/local/bin/
usr/local/bin/samplescript.sh
[rottmrei@vcentos01 ~]$ ./tgz2rpm.sh samplescript-1.0.0.tar.gz
INFO: Valid input file 'samplescript-1.0.0.tar.gz' detected.
INFO: Spec file has been saved as '/tmp/samplescript-1.0.0.spec':
--------------------------------------------------------------------------------
Name: samplescript
Version: 1.0.0
Release: 0
Vendor: Reiner Rottmann
Summary: Summary
License: GPL
Group: System
Source0: %{name}-%{version}.tar.gz
BuildRoot: /var/tmp/%{name}-buildroot
BuildArch: noarch

%description

Longer
...
Description


%prep

%setup -c -n %{name}-%{version}

%build

%install
[ -d ${RPM_BUILD_ROOT} ] && rm -rf ${RPM_BUILD_ROOT}
/bin/mkdir -p ${RPM_BUILD_ROOT}
/bin/cp -axv ${RPM_BUILD_DIR}/%{name}-%{version}/* ${RPM_BUILD_ROOT}/


%post

%postun

%clean

%files
%defattr(-,root,root)
/usr/local/bin/samplescript.sh

%define date    %(echo `LC_ALL="C" date +"%a %b %d %Y"`)

%changelog

* %{date} User <rei..rATrottmann.it>
- first Version

--------------------------------------------------------------------------------
[rottmrei@vcentos01 ~]$ mv /tmp/samplescript-1.0.0.spec rpm/SPECS/
[rottmrei@vcentos01 ~]$ mv samplescript-1.0.0.tar.gz rpm/SOURCES/
[rottmrei@vcentos01 ~]$ rpmbuild -ba rpm/SPECS/samplescript-1.0.0.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.81263
+ umask 022
+ cd /home/rottmrei/rpm/BUILD
+ cd /home/rottmrei/rpm/BUILD
+ rm -rf samplescript-1.0.0
+ /bin/mkdir -p samplescript-1.0.0
+ cd samplescript-1.0.0
+ /bin/gzip -dc /home/rottmrei/rpm/SOURCES/samplescript-1.0.0.tar.gz
+ tar -xvvf -
drwxrwxr-x rottmrei/rottmrei 0 2010-02-12 01:46:06 usr/
drwxrwxr-x rottmrei/rottmrei 0 2010-02-12 01:46:06 usr/local/
drwxrwxr-x rottmrei/rottmrei 0 2010-02-12 01:46:20 usr/local/bin/
-rw-rw-r-- rottmrei/rottmrei 0 2010-02-12 01:46:20 usr/local/bin/samplescript.sh
+ STATUS=0
+ '[' 0 -ne 0 ']'
++ /usr/bin/id -u
+ '[' 3002 = 0 ']'
++ /usr/bin/id -u
+ '[' 3002 = 0 ']'
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.81263
+ umask 022
+ cd /home/rottmrei/rpm/BUILD
+ cd samplescript-1.0.0
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.81263
+ umask 022
+ cd /home/rottmrei/rpm/BUILD
+ cd samplescript-1.0.0
+ '[' -d /var/tmp/samplescript-buildroot ']'
+ /bin/mkdir -p /var/tmp/samplescript-buildroot
+ /bin/cp -axv /home/rottmrei/rpm/BUILD/samplescript-1.0.0/usr /var/tmp/samplescript-buildroot/
`/home/rottmrei/rpm/BUILD/samplescript-1.0.0/usr' -> `/var/tmp/samplescript-buildroot/usr'
`/home/rottmrei/rpm/BUILD/samplescript-1.0.0/usr/local' -> `/var/tmp/samplescript-buildroot/usr/local'
`/home/rottmrei/rpm/BUILD/samplescript-1.0.0/usr/local/bin' -> `/var/tmp/samplescript-buildroot/usr/local/bin'
`/home/rottmrei/rpm/BUILD/samplescript-1.0.0/usr/local/bin/samplescript.sh' -> `/var/tmp/samplescript-buildroot/usr/local/bin/samplescript.sh'
+ /usr/lib/rpm/brp-compress
+ /usr/lib/rpm/brp-strip
+ /usr/lib/rpm/brp-strip-static-archive
+ /usr/lib/rpm/brp-strip-comment-note
Processing files: samplescript-1.0.0-0
Requires(interp): /bin/sh /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires(post): /bin/sh
Requires(postun): /bin/sh
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/samplescript-buildroot
Wrote: /home/rottmrei/rpm/SRPMS/samplescript-1.0.0-0.src.rpm
Wrote: /home/rottmrei/rpm/RPMS/noarch/samplescript-1.0.0-0.noarch.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.47386
+ umask 022
+ cd /home/rottmrei/rpm/BUILD
+ cd samplescript-1.0.0
+ exit 0
[rottmrei@vcentos01 ~]$ rpm -qpi rpm/RPMS/noarch/samplescript-1.0.0-0.noarch.rpm
Name        : samplescript                 Relocations: (not relocatable)
Version     : 1.0.0                             Vendor: Reiner Rottmann
Release     : 0                             Build Date: Fri 12 Feb 2010 01:48:45 AM CET
Install Date: (not installed)               Build Host: vcentos01.rottmann.local
Group       : System                        Source RPM: samplescript-1.0.0-0.src.rpm
Size        : 0                                License: GPL
Signature   : (none)
Packager    : Reiner Rottmann <rei..rATrottmann.it>
Summary     : Summary
Description :

Longer
...
Description
[rottmrei@vcentos01 ~]$ rpm -qpl rpm/RPMS/noarch/samplescript-1.0.0-0.noarch.rpm
/usr/local/bin/samplescript.sh

 

 

Linux Magazine

Linux Magazine News (path: lmi_news)