Showing posts with label rpm. Show all posts
Showing posts with label rpm. Show all posts

Friday, 20 April 2012

Find installed location of RPM Package

I've been trying to run HPL on a homemade HPC (in the loosest sense of the word) cluster and I was struggling with some of the dependencies.

Rather than compile from source, I had decided to use the available binaries for various packages, so I needed to find out where the libraries where actually held, with the added problem of not being fully aware of the names of what I was looking for. Enter the rpm tool and its myriad options:
Usage: rpm [-aKfgpWHqVcdilsKiv?] [-a|--all] [-f|--file] [-g|--group] [-p|--package] [-W|--ftswalk] [--pkgid] [--hdrid] [--fileid] [--specfile]   [--triggeredby] [--whatrequires] [--whatprovides] [--nomanifest] [-c|--configfiles] [-d|--docfiles] [--dump] [-l|--list] [--queryformat=QUERYFORMAT] [-s|--state] [--nofiledigest] [--nomd5] [--nofiles] [--nodeps] [--noscript] [--comfollow] [--logical] [--nochdir] [--nostat] [--physical] [--seedot] [--xdev] [--whiteout] [--addsign] [-K|--checksig] [--delsign] [--import] [--resign] [--nodigest] [--nosignature] [--initdb] [--rebuilddb] [--aid] [--allfiles] [--allmatches] [--badreloc] [-e|--erase <package>+] [--excludedocs] [--excludepath=<path>] [--fileconflicts] [--force] [-F|--freshen <packagefile>+] [-h|--hash] [--ignorearch] [--ignoreos] [--ignoresize] [-i|--install] [--justdb] [--nodeps] [--nofiledigest] [--nomd5] [--nocontexts] [--noorder] [--nosuggest] [--noscripts] [--notriggers] [--oldpackage] [--percent] [--prefix=<dir>] [--relocate=<old>=<new>] [--replacefiles] [--replacepkgs] [--test] [-U|--upgrade <packagefile>+] [--quiet] [-D|--define 'MACRO EXPR'] [-E|--eval 'EXPR'] [--macros=<FILE:...>] [--nodigest] [--nosignature] [--rcfile=<FILE:...>] [-r|--root ROOT] [--querytags] [--showrc] [--quiet] [-v|--verbose] [--version] [-?|--help] [--usage] [--scripts] [--setperms] [--setugids] [--conflicts] [--obsoletes] [--provides] [--requires] [--info] [--changelog] [--xml] [--triggers] [--last] [--dupes] [--filesbypkg] [--fileclass] [--filecolor] [--fscontext] [--fileprovide] [--filerequire] [--filecaps]
Since I knew the package name I could run rpm -qi mpich2, which provides loads of information, but crucially not where the files are located:
Name        : mpich2                       Relocations: (not relocatable)
Version     : 1.2.1                             Vendor: CentOS
Release     : 2.3.el6                       Build Date: Fri 12 Nov 2010 05:23:32 AM GMT
Install Date: Wed 18 Apr 2012 10:29:31 AM BST      Build Host: c5b2.bsys.dev.centos.org
Group       : Development/Libraries         Source RPM: mpich2-1.2.1-2.3.el6.src.rpm
Size        : 7302214                          License: MIT
Signature   : RSA/8, Sun 03 Jul 2011 05:45:52 AM BST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://www.mcs.anl.gov/research/projects/mpich2
Summary     : A high-performance implementation of MPI
Description :
MPICH2 is a high-performance and widely portable implementation of the
MPI standard. This release has all MPI-2.1 functions and features
required by the standard with the exeption of support for the
"external32" portable I/O format.

The mpich2 binaries in this RPM packages were configured to use the default
process manager 'MPD' using the default device 'ch3'. The ch3 device
was configured with support for the nemesis channel that allows for
shared-memory and TCP/IP sockets based communication.

This build also include support for using '/usr/sbin/alternatives'
and/or the 'module environment' to select which MPI implementation to use
when multiple implementations are installed.
In order to find where the files are actually located I had to run rpm -ql mpich2, which provides the required information:
/etc/mpich2-x86_64
/etc/mpich2-x86_64/mpe_callstack_ldflags.conf
....
/usr/share/man/mpich2/man1/mpif90.1.gz

Friday, 17 June 2011

Build a simple RPM that packages a single file

I find this objective bizarre, although perhaps I should be used by now that some objectives just don't make sense. In this case, I just think that this is something that it is unlikely to be done by system admin. To be fair it is much cooler to give somebody an rpm with your scripts but still.

The first thing is to install the rpmdevtools package:
yum install rpmdevtools -y
You now need to create the source tree, which you can do manually (You'll need BUILD,BUILDROOT, RPMS, SPECS,SOURCE,SRPMS) or you can just use:
rpmdev-setuptree
Since the objective calls for a least one file to be packaged, let's just create a script, say greetings.sh, and copy it to its own folder in the home/user/rpmbuild/SOURCES directory:
echo 'echo "hello `whoami`";' >> greetings.sh; chmod +x greetings.sh ; mkdir /home/user/rpmbuild/SOURCES/greet-1.0; cp greetings.sh /home/user/rpmbuild/SOURCES/greet-1.0
Create a tarball out of the directory with the greetings.sh script, from SOURCES directory:
tar -czvf greet.tar.gz greet-1.0
Now, you need a spec file and you can create a sample spec file with, again from SOURCES directory:
rpmdev-newspec ../SPECS/greet.spec
You can now edit this file to this:
Name:           greet
Version:       1.0
Release:        1%{?dist}
Summary:        Greets the invoker

Group:         Greetings Group
License:        GPL
URL:          http://www.sgniteerg.com
Source0:        greet.tar.gz
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)


%description

%prep
%setup -q
%build
%install
install -m 0755 -d $RPM_BUILD_ROOT/opt/greet
install -m 0777 greetings.sh $RPM_BUILD_ROOT/opt/greet/greetings.sh

%clean
#rm -rf $RPM_BUILD_ROOT

%files
%dir /opt/greet
/opt/greet/greetings.sh

%defattr(-,root,root,-)
%doc
%changelog
You can build this file with from the SPECS directory:
rpmbuild -bb greet.spec
This will create an rpm, greet-1.0-1.el6.x86_64.rpm, in the RPMS/x86_64 directory of your buildtree, which you can then proceed to install. If you are not using the x86_64 architecture, the directory will be different. You could add BuildArch: noarch to the spec file.

You can now package all your scripts and pass them to your friends as an rpm file. How cool is that?