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

Friday, October 10, 2008

How To Set Up A Headless X Server On Redhat Linux

Hey there,

Today we're going to throw out another Linux tip somewhat related to networking. Or, more correctly, we're going to throw another quick tip out there ;) Today we're going to look at setting up a headless X Server. It's not quite as difficult, or as scary, as it sounds. Running a headless X Server is kind of like Night Of The Living Dead (the original; although the remake was kind of fun) except without all the zombies and with exported displays instead of excoriated remains (best I could do in the almost-rhyming department on that one ;)

If you stick to the following steps (Tested on RedHat Enterprise Linux Update 4) and adjust slightly if your distro is either completely different, your system architecture varies or your RedHat release is just a version or so off, you should be up and running in no time.

1. Make sure that you install all of the following rpm's on the machine on which you want to run the headless X Server (ignore errors that state you already have any of the packages installed. If you run into dependency conflicts, run rpm with the --nodeps option. If you need to update any of the files, run rpm with the --update option. You may need to install these one by one, but you might get lucky and just be able to run rpm -ivh in a loop and have them all install the first time. You can also get around dependency issues by installing all of the rpm's on one line - i.e. rpm -ivh rpm1.rpm rpm2.rpm ... rpmN.rpm):

XFree-libs-data-4.3.0-78.EL.i386.rpm
XFree-xfs-4.3.0-78.EL.i386.rpm
XFree-libs-4.3.0-78.EL.i386.rpm
XFree86-xauth-4.3.0-35.EL.i386.rpm
XFree86-base-fonts-4.3.0-35.EL.i386.rpm
XFree86-4.3.0-78.EL.i386.rpm
cpp-3.2.3-47.i386.rpm
xinitrc-3.32-1.noarch.rpm
switchdesk-3.98.17.i386.rpm
desktop-file-utils-0.3-10.i386.rpm
XFree86-Xvfb-4.3.0-78.EL.i386.rpm
XFree86-ISO8859-14-100dpi-fonts-4.3.0-97.i386.rpm


2. Start up X's virtual frame buffer server like so:

Xvfb :0 –pn –nolisten tcp –audit 4 –screen 0 800x600x16 & <-- The 800x600 is the screen resolution and the x16 (16 bit)is the color depth. You can change these settings to suit your taste or satisfy any limitations your graphics driver might impose).

NOTE: If you have problems with the X Server going offline when you logoff, try running it with nohup and/or check out our previous post on what to do when nohup hangs up anyway!

And, how about that? I think this is, blessedly, the shortest post I've ever written :) Just pretend there are a couple more paragraphs of "ipsum lorem dolor sit amet" if you find yourself suffering from information underload ;)

Cheers,

, Mike




Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.

Monday, June 23, 2008

Securing Your Linux Or Unix System - Part 4a

Hey again,,

Well, so far in this series we've hit upon basic Linux and Unix installation security, even more security measures, user, group and account-based security and ensuring existing software's security. Today, we're going to continue by going over some additional security software that you may (or may not) want to add to your list of always-installed security-enhancing programs. This post, like the basic Linux and Unix installation security post, is going to end up being a two-(long)-parter. If only I planned my writing before I sat down and wrote these little novels... ;)

Cheers,

OS Installation Guidelines, Part 4: Additional Software Installation

Note: Our assumption here is that you've built your additional custom software to live in /usr/local/encap/PRODUCT-VERSION and packaged your it using a program called encap, originally developed at UIUC by a former manager of mine, who's name I will not mention because I haven't seen him in a long time and I don't publish anything personal about anyone else but me on this blog (unless they want me to ;) If you're reading this, you know who you are and my hat's still off to you, sir. Thanks for politely kicking me in the arse until I got my act together ;) I'm actually super-old-school on this, install all my custom software in /usr/local/encap, prefer version 1.2 (encap.pl) and haven't ever had the need to complicate my life with any of the newer versions. They should all be available for download from the above link, including instructions on proper usage.

Apologies for getting misty up there ;) Aside from our assumption, which will explain some of the instructions, any (or all) of this can be handled by Solaris pkg's or RedHat RPM's (rolling your own is my preference if I go down that road, but, these days, the products that come out are usually good enough if you're okay with "default build options"). The relative pro's and con's of using encap or epkg vs. regular packages are listed at the encap FAQ.

Note, also, that any packages for which there are no additional instructions do not require any additional setup, necessarily.

1. Clean up the /usr/local area as well as possible:

Remove all compilers (preferably, build the software on a different machine, or just clean up when you're done) if the machine is on our network’s perimeter. Be sure to check if they were installed, using pkginfo on Solaris or rpm -qa on RedHat, so you can remove them that way.

Remove any unnecessary programs, or rebuild them in encapped form before deleting them. If you do build new packages in encapped form, follow the same process as building any encapped software and place it in the /usr/local/encap directory.

2. Install encap to place software –

mkdir –p /usr/local/encap

3. assuming that you've built everything on another server, unpack your compiled software bundle into /usr/local/encap. A good collection of packages might look something like this, and then some (Note that a lot of these programs are included with Solaris 10, Open Solaris and RedHat, but have been included for folks still using older OS versions):

encap-1.2.
cops.
tcp-wrappers – tcpd.
chrootuid.
skey.
lsof.
gzip-gunzip.
John The Ripper.
Log management scripts.
Perl – Statically stripped in production environments.
egd – Entropy Gathering Daemon.
Open-SSH (Compiled to use EGD).
wu-ftpd or similar ftp server (if necessary).
The Coroner’s ToolKit (TCT).
top.
ntpd/xntpd
sudo
chkrootkit-latest-version (Or latest revision)


4. Create a file called /usr/local/encap/encap.exclude, which should include the lines:

cops
jtr
tct
tcp-wrappers
chkrootkit-latest-version


5. Run:

/usr/local/encap/encap-1.2/bin/encap.pl /usr/local/encap /usr/local

NOTE: You really don't need to run this command until you have successfully installed all of the packages per the instructions following for each. If you do, you will need to re-run it once you’ve completed your installations to ensure that all the links get made (or removed) as necessary.

6. Install cops:

mkdir /usr/local/encap/cops-VERSION

Copy your entire cops distribution to this directory.
Edit /usr/local/encap/cops-VERSION/cops and ensure that the secure directory is set to /usr/local/encap/cops-VERSION, the MMAIL variable is set to YES, the ONLY_DIFF variable is set to NO, the RUN_SUID variable is set to YES and the secure user is set to yourAdminGroup@yourhost.com.
Edit the cops executable script. Look for this section and add the noted line if it does not exist already:

if $TEST ! -s $RESULT".FILT" ; then
$RM -f $RESULT
$RM -f $RESULT".FILT"
<--- Add this line so your directory doesn't fill up with useless files.
exit 0
fi


Run cops.
Fix reported problems
Run cops again.
Repeat until you’re left with a report you can live with.
Run /usr/local/encap/cops/cfm (a script you can grab from this previous post on how to create a cops filter file).
Add “/usr/local/encap/cops-VERSION/cops –f /usr/local/encap/cops-VERSION/cops_filter” to root's cron.

7. Install the gzip-gunzip encap package.

8. Install S/key (configure only if not a heavy-user machine or if the machine acts as a login gateway) – (Check out the s/key entry in Wikipedia for lots of links to downloads and explanations of this one-time-password system. OPIE, SecuRemote, and others are all equally worthwhile but s/key is about the cheapest you can get (Free!!! :)

Run “keyinit username” for all user accounts except root and system accounts.
Change all user account login shells to /usr/local/bin/keysh.

to be continued...

, Mike

Wednesday, April 30, 2008

Creating Solaris Pkg's From RPM's - Take Two

Hey there,

Special thanks to K.Jans for pointing out the problem with our original script's specificity and for his help in putting together this new version which will address some other RPM's CPIO signatures!

I don't know if we can chalk it up to my enthusiasm or transient thought process, but, of course, the rpm2pkg rpm-to-pkg conversion script that we put out a while ago doesn't perfectly translate every Linux RPM into a usable Solaris Unix datastream pkg file (Mostly because of Solaris being fussy with the pkg names). Unfortunately, there are too many vendors creating too many different versions of the same file type, and using Perl to scrape around inside their CPIO files requires a little bit of modification for every single variation. Not that I'm complaining. I love to do this stuff :)

Still, I will probably write a post on the "process" one of these days (very soon), so that anyone can do it without having to try and read what might be some cryptic scripting ;)

So, today, we have another version of our original RPM to PKG conversion script (which will work with more RPM's, but not the one's the original one worked for, and probably not a lot of other ones ;) for you. If there's any interest in a patch, I can post one (or just email it to you if you request), but it's probably easier to just use one or the other script at this point.

And, here we go again... Enjoy :)


Creative Commons License


This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License

#!/usr/bin/perl

#
# rpm2pkg - creating Solaris pkg files from Linux rpm's
#
# 2008 - Mike Golvach - eggi@comcast.net
#
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
#

$rpm=$ARGV[0];
$tmp_dir="dir.$$";
$orig_dir=`pwd`;

mkdir("$tmp_dir");
chdir("$tmp_dir");
## FIX system("rpm2cpio ../$rpm|cpio -dim");
system("rpm2cpio ../$rpm >rpm.cpio.file");
system("cpio -d -i -m <rpm.cpio.file");
## ENDFIX
$proto_list=`find . -print|pkgproto|grep -v prototype`;
open(TMP_FILE, ">>prototype");
print TMP_FILE "i pkginfo\n";
print TMP_FILE $proto_list;
close(TMP_FILE);
# FIX @pkg_info=`strings ../$rpm`;
@pkg_info=`strings rpm.cpio.file`;
$count = 0;
foreach (@pkg_info) {
if ( $_ =~ /^Begin4/ ) {
push(@rpm_info, $_);
$count++;
} elsif ( $_ =~ /(^Copying-policy:|GPL$)/ ) {
last;
} elsif ( $count > 0 ) {
push(@rpm_info, $_);
}
}
$uname_s = `uname -s`;
$uname_r = `uname -r`;
$uname_p = `uname -p`;
$rpm_version = $rpm;
$rpm_version =~ s/\.rpm//;
chomp $uname_s;
chomp $uname_r;
chomp $uname_p;
chomp $rpm_info[1];
chomp $rpm_info[2];
chomp $rpm_info[4];
$rpm_info[1] =~ s/ * *//g;
$rpm_info[2] =~ s/ * *//g;
$rpm_info[4] =~ s/ * *//g;
$rpm_info[1] =~ s/Title://g;
$rpm_info[2] =~ s/Version://g;
open(PKGINFO, ">>pkginfo");
print PKGINFO "SUNW_PRODNAME=\"$uname_s\"\n";
print PKGINFO "SUNW_PRODVERS=\"$uname_r\"\n";
print PKGINFO "SUNW_PKGTYPE=\"usr\"\n";
print PKGINFO "PKG=\"$rpm_info[1]\"\n";
print PKGINFO "NAME=\"$rpm_info[1]\"\n";
print PKGINFO "VERSION=\"$rpm_info[2]\"\n";
print PKGINFO "VSTOCK=\"$rpm_version\"\n";
print PKGINFO "VENDOR=\"GENERIC\"\n";
print PKGINFO "ARCH=\"$uname_p\"\n";
print PKGINFO "EMAIL=\"me@xyz.com\"\n";
print PKGINFO "CATEGORY=\"application\"\n";
print PKGINFO "BASEDIR=/\n";
print PKGINFO "DESC=\"$rpm_info[4]\"\n";
print PKGINFO "PSTAMP=\"Your Name Here\"\n";
print PKGINFO "CLASSES=\"none\"\n";
close(PKGINFO);
system("pkgmk -o -b `pwd` -d /tmp");
system("pkgtrans -o -s /tmp `pwd`/${rpm_info[1]}.pkg $rpm_info[1]");
system("mv ${rpm_info[1]}.pkg ../");
system("cd ../;pwd;rm -r $tmp_dir");


, Mike

Monday, April 14, 2008

Converting Solaris Pkg's Into RPM's on Linux

Greetings,

Today, we're going to wrap up our series of posts on rpm/pkg mixing and matching, as this is about the last thing that's, technically, really worthwhile doing (I think). So far we've created the following scripts based on Linux RPM and/or Solaris Unix pkg dissection, translation and derivation:

How to unpack Solaris datastream packages without using Sun's pkg tools

How to build pkg's using spec files, like in Linux, with pkg-build

How to create RPM's from already installed RPM packages

How to create Solaris datastream pkg's from already installed pkg's

How to convert Linux RPM's into Solaris datastream pkg's

How to build Linux RPM's part 1- Initial points

How to build Linux RPM's part 2 - Starting your spec file

How to build Linux RPM's part 3 - Finalizing the spec file and building the RPM

How to build your own Solaris datastream pkg's quickly

How to build your own Solaris datastream pkg's (more theory than practice)


And, now, whether or not it will ever be practical, we've put together a script to convert Solaris pkg's to RPM's on a Linux system. If nothing else, it rounds everything out :)

The script is easy to run, and only requires one argument of the pkg file that you'll be converting. For instance, to convert the Solaris 9 m4 pkg from SunFreeware.com, you'd just type this (after unzipping the package with gunzip):

host # ./pkg2rpm m4-1.4.10-sol9-sparc-local

One special note about this Perl script: When the pkg gets converted to an RPM, it's done so with the files (listed under the "%files" specification in the "spec file") saved in the RPM with the full path to the temporary build root. This is done because "%files" won't accept relative pathnames and also won't allow you to add files that don't exist (if you, say, populate "%files" with %{prefix}/bin/whatever, etc). Instead, the "Prefix:" value is set to the "BASEDIR" value in the pkg file (e.g. /usr/local), but the "%files" listed are in their actual location during the build (otherwise we'd be forced to overwrite good Linux binaries with potentially unexecutable Solaris binaries just to build the RPM). Therefore, you'll need to install the newly created RPM with the "--relocate" switch.

So, in our example, assuming we ran the above command from "/home/user" (with the pkg file being in that directory), we would want to install the resulting RPM file by first determining where it's supposed to be relocated and then running the "rpm" command, like so:

host # ls
m4-1.4.10-sol9-sparc-local m4-1.4.10-1.x86_64.rpm
host # rpm -qif m4-1.4.10-1.x86_64.rpm|grep -i reloc
Name : m4-1.4.10-1 Relocations: /usr/local
<--- The "Relocations:" specification is where we'll be relocating "to."
host # rpm -qlf m4-1.4.10-1|head -1 <--- The trunk of this output shows us where we will be relocating "from." In this case "/home/user/SMCm4"
/home/user/SMCm4/bin/m4

Now we know where we're relocating "from" and "to," so we're ready to install (Note that you can install this RPM in your home directory, or the build directory, if you want to. The only downside is the inconvenience ;)

host # rpm --force --nodeps --relocate=/home/user/SMCm4=/usr/local -ivh m4-1.4.10-1.x86_64.rpm
Preparing... ########################################### [100%]
1:m4 ########################################### [100%]


Now, all we have to do is a quick verify and we should see that we're all set:

host # rpm -q m4-1.4.10-1
m4-1.4.10-1
host # rpm -ql m4-1.4.10-1.x86_64.rpm|head -5
/usr/local/bin/m4
/usr/local/doc/m4/AUTHORS
/usr/local/doc/m4/BACKLOG
/usr/local/doc/m4/COPYING
/usr/local/doc/m4/ChangeLog


Here's hoping we've covered every useful angle of Solaris Unix datastream pkg to Linux RPM conversion and manipulation that we possibly can. At least for the here and now ;)


Creative Commons License


This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License

Cheers,

#!/usr/bin/perl

#
# pkg2rpm - convert Solaris datastream pkg files to RPM's for Linux
#
# 2008 - Mike Golvach - eggi@comcast.net
#
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
#

if ( $#ARGV != 0 ) {
print "Usage: $0 pkg_file\n";
exit(1);
}

$pkg_name = $ARGV[0];

chomp($simple_header_check=`grep -i "package datastream" $pkg_name >/dev/null 2>&1;echo \$?`);

if ( $simple_header_check != 0 ) {
print "This doesn't appear to be a valid SVR4 DataStream pkg file. Exiting...\n";
exit;
}

open(PKG, "<$pkg_name");
@pkg_file = <PKG>;
close(PKG);

$header_end = 0;
$cpio_start = 0;
open (P_HEADERS, ">$pkg_name.headers");
foreach $line (@pkg_file) {
if ( $header_end == 0 && $line =~ /TRAILER/ && $line =~ /pkginfo/ ) {
print P_HEADERS $line;
$header_end = 1;
} elsif ( $header_end == 1 && $line =~ /pkginfo/ ) {
print P_HEADERS $line;
close(P_HEADERS);
$cpio_start = 1;
open(P_CPIO, ">$pkg_name.cpio");
} elsif ( $cpio_start == 0 ) {
print P_HEADERS $line;
} elsif ( $cpio_start == 1 ) {
print P_CPIO $line;
} else {
print STDERR "WTF?\n";
}
}
close(P_CPIO);

open(P_HEADERS, "<$pkg_name.headers");
@p_headers = <P_HEADERS>;
close(P_HEADERS);

$output_dir = 0;
$pkginfo_start = 0;
$pkginfo_seek = 0;
$pkgmap_start = 0;
foreach $p_head (@p_headers) {
if ( $output_dir eq 1 && $pkginfo_seek == 0 ) {
$output_dir = $p_head;
$output_dir =~ s/^(\w+)\W*.*$/$1/;
chomp($output_dir);
$pkginfo_seek = 1;
} elsif ( $output_dir eq 0 && $p_head =~ /datastream/i ) {
$output_dir = 1;
} elsif ( $output_dir eq 0 && $pkginfo_start == 0 ) {
next;
} elsif ( $output_dir ne 0 && $p_head =~ /pkgmap/ ) {
$pkgmap_start = 1;
$pkginfo_start = 0;
} elsif ( $pkgmap_start == 1 && $p_head =~ /pkginfo/ ) {
chomp($p_head);
push(@pkgmap, $p_head);
last;
} elsif ( $output_dir ne 0 && $p_head =~ /pkginfo.*PKG=/ ) {
$pkginfo_start = 1;
} elsif ( $output_dir ne 0 && $pkgmap_start == 1 ) {
chomp($p_head);
push(@pkgmap, $p_head);
} elsif ( $output_dir ne 0 && $pkginfo_start == 1 ) {
chomp($p_head);
push(@pkginfo, $p_head);
}
}

mkdir("$output_dir");
chdir("$output_dir");
open(PKGINFO_OUT, ">>pkginfo");
foreach $info (@pkginfo) {
print PKGINFO_OUT "$info\n";
}
close(PKGINFO_OUT);
open(PKGMAP_OUT, ">>pkgmap");
foreach $map (@pkgmap) {
print PKGMAP_OUT "$map\n";
}
close(PKGMAP_OUT);
open(RPM_SPEC_FILES, ">>${pkg_name}.specfiles");
foreach $specfile (@pkgmap) {
@specfile = split(" ", $specfile);
if ( $specfile[1] !~ /^d$/ && $specfile[2] =~ /^none$/ ) {
print RPM_SPEC_FILES "$specfile[3]\n";
}
}
close(RPM_SPEC_FILES);
system("cpio -iv <../$pkg_name.cpio >/dev/null 2>&1");
chdir("reloc");
system("tar cpf - *|(cd ../;tar xpf -)");
chdir("../");

$rpm_name=$pkg_name;
chomp($starting_point=`pwd`);
$temp_var=$$;

system("mkdir ${starting_point}/BUILD");
system("mkdir ${starting_point}/SOURCES");
system("mkdir ${starting_point}/SPECS");
system("mkdir ${starting_point}/SRPMS");
system("mkdir ${starting_point}/RPMS");
system("mkdir ${starting_point}/RPMS/noarch");
system("mkdir ${starting_point}/RPMS/`uname -i`");
system("mkdir $temp_var");
system("cd $temp_var");
open(PKGINFO_RPM, "<${starting_point}/pkginfo");
@pkginfo_rpm = <PKGINFO_RPM>;
close(PKGINFO_RPM);
($pkgrpm_name,$pkgrpm_arch,$pkgrpm_version,$pkgrpm_category,$pkgrpm_vendor,$pkgrpm_email,$pkgrpm_pstamp,$pkgrpm_basedir,$pkgrpm_classes) = @pkginfo_rpm;
$pkgrpm_name =~ s/.*=(.*)\n$/$1/;
$pkgrpm_arch =~ s/.*=(.*)\n$/$1/;
$pkgrpm_version =~ s/.*=(.*)\n$/$1/;
$pkgrpm_category =~ s/.*=(.*)\n$/$1/;
$pkgrpm_vendor =~ s/.*=(.*)\n$/$1/;
$pkgrpm_email =~ s/.*=(.*)\n$/$1/;
$pkgrpm_pstamp =~ s/.*=(.*)\n$/$1/;
$pkgrpm_basedir =~ s/.*=(.*)\n$/$1/;
$pkgrpm_classes =~ s/.*=(.*)\n$/$1/;
open(RPM_SPECIFICS, ">>$rpm_name.spec");
print RPM_SPECIFICS "%define _topdir $starting_point\n";
print RPM_SPECIFICS "Summary: $pkgrpm_name $pkgrpm_version\n";
print RPM_SPECIFICS "Name: $pkgrpm_name\n";
print RPM_SPECIFICS "Version: $pkgrpm_version\n";
print RPM_SPECIFICS "Release: 1\n";
print RPM_SPECIFICS "Copyright: $pkgrpm_pstamp\n";
print RPM_SPECIFICS "Group: $pkgrpm_category\n";
print RPM_SPECIFICS "Prefix: $pkgrpm_basedir\n";
print RPM_SPECIFICS "%description\n";
print RPM_SPECIFICS "Vendor = $pkgrpm_vendor - Email = $pkgrpm_email - Arch = $pkgrpm_arch - Classes = $pkgrpm_classes\n";
print RPM_SPECIFICS "%files\n";
open(RPM_SPEC_FILES, "<${starting_point}/$pkg_name.specfiles");
@specks = <RPM_SPEC_FILES>;
close(SPECKS);
foreach $speck (@specks) {
print RPM_SPECIFICS "${starting_point}/$speck\n";
}
close(RPM_SPECIFICS);

system("rpmbuild -bb $rpm_name.spec 2>&1|grep -v twice");
chdir("../");
system("mv -f ${starting_point}/RPMS/*/* .");
system("rm -rf $output_dir");
unlink "$pkg_name.headers";
unlink "$pkg_name.cpio";


, Mike




Tuesday, March 25, 2008

Creating Linux RPM's From Already Installed Packages

rpm_remk creating a new Mutt RPM


Click on the image for a higher resolution version of the output shown above!

Hey there,

Today's post is a follow up to, or the complement of, a post we did a little while ago on creating Solaris pkg files from already installed packages. Yes, there was a reason today's title sounded familiar ;)

Actually, I've been meaning to follow up on the Linux counterpart of this issue for a week or so now, but got caught up trying out various things. For instance, one of the more unusual (and interesting things) I ran across was a Perl project called alien that endeavours to pretty much translate between almost all package formats (dpkg, rpm, pkg, etc), but it didn't really address this specific issue. Still, pretty neat and in the experimental stage.

I also followed a lot of trial and error using rpmrebuild and standard rpm with the --repackage option, but found that both of these methods required the additional execution of at least one thing I didn't need to do to achieve my goal. For instance, using rpm with the --repackage option requires that you be upgrading, re-installing, deleting, etc, the RPM in question. All I want to do is create a package from existing source, and I'd rather not have to upgrade, re-install or delete the software on a live system to do it :)

Luckily, in the end, it boiled down to a fairly simple process. A lot of confusion came from various interpretations of the rpmbuild "spec file" and how, and why, it should be used. Many of the ideas I got that led me to an eventual solution came off of message boards rather than official sources. To put it somewhat humorously, a lot of those guys may not know what they're talking about, but they sure do know what they're doing ;) Seriously, if it weren't for the folks who strayed from the info-docs, this solution might have taken even longer to come around to.

You can call today's command (which I've name "rpm_remk" to remind me of my similar Solaris pkg project), very simply from the command line, like so:

host # ./rpm_remk mutt <--- If, for example, you wanted to create an RPM of the installed version of "mutt" on your system.

You can be as specific or general as RPM will let you when you use this command. For instance, on my box, I only have one instance of mutt:

host # rpm -qa|grep mutt
mutt-1.5.6i-64.9


So that simple command line suffices. For another program like, say, xaw3d, I would have to be more specific, because the underlying RPM system wouldn't know which package I was referring to. For example:

host # rpm -qa|grep xaw3d
xaw3d-1.5E-216.3
xaw3d-32bit-9-200407011229


Shows two different selections. RPM generally only picks the first one, like this:

host # rpm -q xaw3d
xaw3d-1.5E-216.3


So, if we ran the command with only "xaw3d" as the argument, we'd create that 1.5E RPM, which would be great unless we wanted the 32bit version ;) Specifying "xaw3d-32bit-9-200407011229" as the argument would guarantee that the intended RPM got built!

Here's hoping this script helps you out and makes it a little easier for you to retrieve some of those old installed software packages for which the original RPM's have long since disappeared :)


Creative Commons License


This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License

#!/bin/bash

# rpm_remk - Create new RPM's from installed RPM's
#
# 2008 - Mike Golvach - eggi@comcast.net
#
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
#

trap 'rm -rf $temp_var;exit 1' 1 2 3 9 15
if [ $# -ne 1 ]
then
echo "Usage: $0 PackageName"
exit 1
fi

existing_rpm=$1
starting_point=`pwd`
temp_var=$$

mkdir ${starting_point}/RPMS
mkdir ${starting_point}/RPMS/noarch
mkdir ${starting_point}/RPMS/`uname -i`
mkdir $temp_var
cd $temp_var

if [ `expr match \`rpm -q --queryformat "%{INSTALLPREFIX}\n" $existing_rpm\` '(none)'` -ne 0 ]
then
Prefix="/"
else
Prefix=`rpm -q --queryformat "Prefix: %{INSTALLPREFIX}\n" $existing_rpm`
fi

echo "%define _topdir $starting_point" >>$existing_rpm.spec
rpm -q --queryformat "Summary: %{SUMMARY}\n" $existing_rpm >>$existing_rpm.spec
rpm -q --queryformat "Name: %{NAME}\n" $existing_rpm >>$existing_rpm.spec
rpm -q --queryformat "Version: %{VERSION}\n" $existing_rpm >>$existing_rpm.spec
rpm -q --queryformat "Release: %{RELEASE}\n" $existing_rpm >>$existing_rpm.spec
rpm -q --queryformat "Copyright: %{COPYRIGHT}\n" $existing_rpm >>$existing_rpm.spec
rpm -q --queryformat "Group: %{GROUP}\n" $existing_rpm >>$existing_rpm.spec
echo "Prefix: $Prefix" >>$existing_rpm.spec
description=`rpm -q --queryformat "%{DESCRIPTION}\n" $existing_rpm`
echo "%description" >>$existing_rpm.spec
echo "$description" >>$existing_rpm.spec
echo "%files" >>$existing_rpm.spec
rpm -ql $existing_rpm|while read x
do
echo "%{prefix}$x" >>$existing_rpm.spec
done

rpmbuild -bb $existing_rpm.spec 2>&1|grep -v twice
cd $starting_point
mv -f ${starting_point}/RPMS/*/* .
rm -rf $temp_var ${starting_point}/RPMS


, Mike




Saturday, March 22, 2008

Common Pkg And RPM Command Cross Reference

Hey there,

Today, I thought I'd put out a little summary, if you will, to wrap up all the pkg-to-rpm-to-pkg type articles we've been dealing with for the last few weeks and try to boil it down to a quick cross reference. This way you can have, at a glance, the basic information you need to manipulate both Solaris Unix pkg files and Linux RedHat RPM's.

You can find more detailed information, if you prefer, in our previous posts on working with Linux RPM's and building Solaris packages. I have yet to write a post on working specifically with pkg files (just lots of different aspects), but I suppose I ought to now, huh? ;)

This will be pretty straightforward, with a format of:

What We Want To Do: RPM command - PKG command
>--- With PKG and RPM being the actual pkg and RPM names

Enjoy, and I hope this helps save you some time digging around We will most likely look at the apt and yum equivalents of these commands very soon, as well :)

Show package info: rpm -qi RPM - pkginfo -l PKG
Install package: rpm -ivh RPM_FILE - pkgadd -d PKG_FILE
Remove package: rpm -e RPM - pkgrm PKG
List the package that owns a particular FILE: rpm -qf FILENAME - pkgchk -l -p FILENAME
List all files in an already installed package: rpm -ql RPM - pkgchk -l PKG
List all files in an uninstalled package FILE: rpm -qlp RPM_FILE - pkgchk -l -d PKG_FILENAME
List all packages installed on your system: rpm -qa - pkginfo
Check that all files from a package are installed correctly: rpm -V RPM - pkgchk PKG
Check that all files from all packages are installed correctly: rpm -Va - pkginfo|awk '{print $2}'|xargs pkgchk
Check that a package FILE is OK before installing: rpm -K RPM_FILE - pkgchk -d PKG
Fix an altered package installation: rpm --setperms/--setugids RPM - pkgchk -f PKG


Cheers,

, Mike




Saturday, March 15, 2008

Converting Linux RPM's Into Solaris Pkg Files

Hey there,

As this week wraps up, I thought I'd put out the last few things I've been toying around with. Today, we've got a Perl script for you that will take an RPM (From Linux) and convert it to a Solaris datastream pkg file. Of course, we've got the opposite (just like we have the opposite of our post on creating Solaris pkg files from already installed content, which we'll post in the next few days. That might be a more useful script than this one (you might actually "need" to recreate a Linux RPM from what's on your box more often), but I thought this script was kind of cool :)

Basically, you can take any Linux RPM (I tested against RedHat AS and SUSE 9), feed it to this script, like so:

host # ./rpm2pkg PROGRAM-3.2-1.rpm

and end up with your own valid Solaris pkg file named:

PROGRAM-3.2-1.pkg

My thought was that this might be useful, since one of the commands used inside it (rpm2cpio) is already included in Solaris 9 and 10. For architecture-independent, and binary compatible, programs, there obviously exists a need to convert Linux RPM's to a cpio archive that can then be extracted to the local filesystem on a Solaris machine. In my mind, the logical next step would be to skip ahead and create a valid Solaris datastream pkg file from that cpio output. This way, the process could be completed once and then distributed easily as a single pkg installation file to all of your Solaris servers:)

The script works, as mentioned above, by using rpm2cpio to extract the Linux RPM's contents and then using the "strings" command on the actual RPM to extract all the header information that we require to seed the "pkginfo" file. The prototype file is the easiest necessary pkgmk file to create since you just have to use find and pkgproto on the extracted rpm2cpio output.

If you want to be able to tweak this more to your liking, there's a lot more information about the Solaris pkg making process in our previous posts on building Solaris pkg files quickly and, more theoretically, what you need to know to create your own Solaris pkg files.

Enjoy the script and have fun trying to get Linux binaries to run on your Solaris box (Hint: You're success rate will be much greater on Solaris 10, since they're finally buying into "open source" :)

Best wishes,


Creative Commons License


This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License

#!/usr/bin/perl

#
# rpm2pkg - creating Solaris pkg files from Linux rpm's
#
# 2008 - Mike Golvach - eggi@comcast.net
#
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
#

$rpm=$ARGV[0];
$tmp_dir="dir.$$";
$orig_dir=`pwd`;

mkdir("$tmp_dir");
chdir("$tmp_dir");
system("rpm2cpio ../$rpm|cpio -dim");
$proto_list=`find . -print|pkgproto|grep -v prototype`;
open(TMP_FILE, ">>prototype");
print TMP_FILE "i pkginfo\n";
print TMP_FILE $proto_list;
close(TMP_FILE);
@pkg_info=`strings ../$rpm`;
$count = 0;
foreach (@pkg_info) {
if ( $_ =~ /\# \@\(\#\)BegWS/ ) {
push(@rpm_info, $_);
$count++;
} elsif ( $_ =~ /\# \@\(\#\)EndWS/ ) {
last;
} elsif ( $count > 0 ) {
push(@rpm_info, $_);
}
}
$uname_s = `uname -s`;
$uname_r = `uname -r`;
$uname_p = `uname -p`;
$pkg_name = $rpm;
$pkg_name =~ s/\.rpm//;
chomp $uname_s;
chomp $uname_r;
chomp $uname_p;
chomp $rpm_info[1];
chomp $rpm_info[2];
chomp $rpm_info[5];
chomp $rpm_info[12];
open(PKGINFO, ">>pkginfo");
print PKGINFO "SUNW_PRODNAME=\"$uname_s\"\n";
print PKGINFO "SUNW_PRODVERS=\"$uname_r\"\n";
print PKGINFO "SUNW_PKGTYPE=\"usr\"\n";
print PKGINFO "PKG=\"$pkg_name\"\n";
print PKGINFO "NAME=\"$rpm_info[2]\"\n";
print PKGINFO "VERSION=\"$rpm_info[5]\"\n";
print PKGINFO "VENDOR=\"$rpm_info[1]\"\n";
print PKGINFO "ARCH=\"$uname_p\"\n";
print PKGINFO "EMAIL=\"me@xyz.com\"\n";
print PKGINFO "CATEGORY=\"application\"\n";
print PKGINFO "BASEDIR=/\n";
print PKGINFO "DESC=\"$rpm_info[12]\"\n";
print PKGINFO "PSTAMP=\"Your Name Here\"\n";
print PKGINFO "CLASSES=\"none\"\n";
close(PKGINFO);
system("pkgmk -o -b `pwd` -d /tmp");
system("pkgtrans -o -s /tmp `pwd`/${pkg_name}.pkg $pkg_name");
system("mv ${pkg_name}.pkg ../");
system("cd ../;pwd;rm -r $tmp_dir");


, Mike




Thursday, March 6, 2008

Finalizing The Spec File And Building Your Own Linux RPM

Hey There,

We're finally ready to create our very own Linux RPM package! Following up on yesterday's post regarding beginning to write your spec file and the preceding initial software build, we're now going to look at the "build" section of the RPM spec file and compile our new RPM.

The "build" section of the spec file follows the "header section" we went over previously, and contains all that the "rpmbuild" command needs to know in order to create your RPM for you. I should note here that, on some systems, this command may be called "rpm-build" and, on yet others, the rpmbuild flags may simply be options to the rpm command itself (as with SUSE 8.x)

The declarations required in this section are:

%clean <--- Well, not really required, but keeps things nice and tidy ;)
%prep
%setup
%files
%build
%install


These sections are defined as follows (Note that for these declarations, the values are listed beginning on the line below, rather than on the same line, as we did in the "header section":

%clean - this deletes everything in the RPM_BUILD_ROOT, as defined by either the BuildRoot declaration in the "header section" (Which we didn't use for this build) or by the system default. In our case, this should be /usr/src/packages/BUILD. Cautious users may want to add a line of code in front of this, assuring that the RPM_BUILD_ROOT variable isn't set to /. This method is not absolutely necessary, either, so the incredibly cautious can just not call it and remove old garbage files, whenever they want to, manually. It can also cause issues when running concurrent builds if using the same RPM_BUILD_ROOT! Some folks prefer to run this method at the end of the spec file, or script out what it does automatically. It's a matter of preference :)

%prep - This simply indicates that we're moving on to the next section of our spec file. It is necessary, as everything beyond it will be considered part of the build process, rather than part of the RPM definition process, listed above it.

%setup - This part of the spec file indicates that "rpmbuild" should do whatever is necessary to prepare the source for building/compilation. Of course, we've done this already (to make sure we could build from source properly), but this declaration is necessary so that rpmbuild sets everything up for the following sections. Note that without any arguments, in our setup, it's just going to unzip and untar our source package in /usr/src/packages/SOURCES to the /usr/src/packages/BUILD directory.

%files - This is where we have to list all of the files that are going to be in our RPM, for reference when its installed and/or removed using the "rpm" command. In our previous post on building the software from source, we created a file called FILELIST (from the output of the find command). On the line following the %files declaritive, you can just read that file list into your spec file. If you elect to type each file name in, that's your decision, but you should include only one file per line (which can make your spec file pretty long depending on what you're installing. Given how many files most software packages contain, you'll grow sick and tired of this method soon enough ;)

%build - Here you'll provide all the information required to build the software. This can be culled from the notes you took while compiling the program initially.

%install - And finally, here you'll provide all the information required to install the program (Basically, the "make install" command and all arguments from the original compile of the software that you did earlier.

Our spec file will look something like this:

%clean
%prep
%setup
%files
/usr/local/PACKAGE-3.2-1/bin/list
/usr/local/PACKAGE-3.2.1/lib/liblist.so
...
%build
./configure --prefix=%{prefix}
make
make check
%install
make install
/bin/chown -Rv root:root %{prefix}


Before we actually build our RPM, we'll want to change the names of all the files listed in the %files section, that we got from our initial build. Assuming you wanted the RPM to install in /usr/local, you would want to use your favorite editor to replace all instances of "/usr/local/PACKAGE-3.2-1" in this section with "/usr/local" - this would change our %files section from:

%files
/usr/local/PACKAGE-3.2-1/bin/list
/usr/local/PACKAGE-3.2.1/lib/liblist.so
...


to

%files
/usr/local/bin/list
/usr/local/lib/liblist.so
...


Now our spec file is complete and we can create our RPM using this one simple command: rpmbuild. For our purposes, we'll run:

host # rpmbuild -ba PACKAGE.spec

then we'll kick back and watch the magic happen :) Note that I used the "-ba" option to build both source and binary RPM packages. This created the files /usr/src/packages/SRPMS/PACKAGE-3.2-1.src.rpm and /usr/src/packages/RPMS/x86_64/PACKAGE-3.2-1.x86_64.rpm <--- Note that this directory may be slightly different depending on what OS version of Linux you're running.

Now, you're all set to run "rpm -ivh PACKAGE-3.2-1.x86_64.rpm" and your software package will be installed, and can be manipulated by all the standard "rpm" facilities.

Of course there are tons of other options and additions to the spec file (%post, etc) and rpmbuild command, but this should be enough to get you started. For more specific information, check out the online man pages and chat boards - You'd be surprised at what you can do with this software if you use your imagination :)

Best wishes,

, Mike




Wednesday, March 5, 2008

Beginning Your Spec File For Building Linux RPM's.

Hello Again,

This is a continuation of yesterdays post on doing the initial build of your software as the first step toward creating your own Linux RPM. Today we're going to continue on that path with our software package (cleverly named PACKAGE-3.2-1 ;) and move on to the next step in the RPM creation process; the creation of the specification file (which I'll refer to as the "spec file" from here on out) and its basic structure.

For the purposes of our example, we won't be including every single option you can include in a spec file, but we'll touch on all the required ones, and a few that might make your life a bit easier :)

We'll create our spec file by simply opening it up as a new file in our favorite editor. The spec file is simply a plain text file, describing our RPM's attributes, that we'll be supplying to the "rpmbuild" command later on. We'll look at the spec file, line by line, for our soon-to-be-completed package. We'll call it PACKAGE.spec

The first section is what I like to call the "header section," although I don't know that it's ever actually referred to as that. It looks like the following

Summary: The World Famous PACKAGE software
Name: PACKAGE
Version: 3.2
Release: 1
Copyright: Gnu Public License
Group: Applications
Source0: PACKAGE-3.2-1.tar.gz
Prefix: /usr/local
Provides: PACKAGE3, PACKAGE-devel, bunk
Requires: PACKAGE1, db
URL: http://xyz.com
Packager: Mike Tremell
# %define _topdir /users/me/softbuilds/rpm
%description
PACKAGE 3.2-1 Standard Build
%define PACKAGEDIR %{prefix}


The lines in this section are defined as follows:

Summary - This line should be a descriptive summary of your RPM package, in short form. It shouldn't be too wordy, but you can make it as long as you want.

Name - This is simply the name of your package. It must match the source package's name (which we created in /usr/src/packages/SOURCES/ in yesterday's post on setting up the initial build for your RPM. It will later be used (with the Version and Release keyword values appended) by rpmbuild to determine what source file it should look for in /usr/src/packages/SOURCES

Version - The version of your software. Again this must be exactly the same version of the source package you're building from.

Release - The release of the software. This, again, must be exactly the same as the release you're building from. Using the "Name," "Version," and "Release" variables, rpmbuild will surmise that we want to build our RPM from PACKAGE-3.2-1.tar.gz in /usr/src/packages/SOURCES. Note: The Release variable is required and (for whatever reason) cannot be an empty value. Thus we put in the obligatory 1 for our new build of the generic PACKAGE software. Whatever you're building will probably have a release number.

Copyright - Just attribution for the package and/or package source's author(s)

Group - This identifies our package as belonging to the "Applications" package group in Linux.

Source0 - The name (Yes, this is redundant ;) of the source package in /usr/src/packages/SOURCES. As the name implies, you can have more than one source in certain circumstances. Note that there is also a "Patch0," etc, declaration that you can use to specify diff files you may need to include, but that's beyond the scope of our exercise.

Prefix - The root under which the RPM will install itself. Note: You need to include the Prefix declaration if you want your RPM package to be "relocatable." If your package is not relocatable, all installs will always install to the same place. If your package is relocatable, it allows the user or administrator to change the prefix, or root install directory, of the RPM when they run the "rpm" command to install it!

Provides - What your RPM will "provide" once it is installed. This is mainly for rpm's dependency checking. You can have your package provide anything, but it's best to have it provide only useful values. This variable isn't necessary if your software package isn't providing anything significant and/or doesn't have another package that's dependant on it.

Requires - The RPM packages your RPM package needs to have installed on your system before it will install correctly. In our example, PACKAGE will not install correctly (it will fail the dependency check) if some version of the "db" (Berkeley Database) RPM isn't already installed on our system.

URL - The location where a user can download the latest version of the RPM source. Not necessary, but can be helpful.

Packager - The name of the guy (or gal) who put together the RPM. Again, not necessary unless you're seeking notoriety ;)

# %define _topdir /users/me/softbuilds/rpm - Note that this line is commented out for our build, since we're going with the system defaults. However, comments in spec files work just like comments in shell scripts, so if you wanted to change the top level directory for your RPM structure, you could do it by redefining the _topdir variable (In this case, simply by removing the comment). You may need to create its required BUILD, BUILDROOT, RPMS, SOURCES, SPECS and SRPMS subdirectories manually. This option is useful if you're trying to do a build as a regular user and don't have the system privilege that will allow you to manipulate your server's main RPM package working directories :)

%description - Just like the summary above, but should be more descriptive. Also, you should add your description on a new line following the %description declaration (unlike all the others). "rpmbuild" will spew error messages if you put your description's value on the same line as the variable. You can actually include "one" word on the same line as the %description variable, but the rest of your description must be below that line. It should also be noted that you can have multiple %description declarations, which is useful if you're building multiple RPM's from one spec file (although that's deeper than we want to go for now).

%define - This directive can be used over and over again. It's simple format is: %define variable_name value. You can call the variable name you define here using the %{} notation. For instance:

%define mydir /usr/local/bin

Would allow you to reference /usr/local/bin, at any point (from the point of definition on) in your spec file as %{mydir}

Tomorrow, we'll check out the next, and final section of the RPM spec file and use "rpmbuild" to create our RPM package!

Cheers,

, Mike




Tuesday, March 4, 2008

Creating Your Own Linux RPM's - The Initial Software Build.

Greetings,

A while back, we took a look at creating your own pkg files for Solaris Unix. Today we're going to continue in that tradition, but take a look at the (some would say) simpler process of creating your own RPM's for Linux. These builds have been tested on both RedHat and SUSE, since they seem like polar opposites to me no matter how many similarities they have ;)

The process of building RPM's is much simpler than creating packages for Solaris in that the post-software build portion only consists of creating one specification file and then running one command. Fewer steps, and the ability to add all of your software information into one specification file, makes for a much tighter (and easier to modify or reproduce) software packaging system.

Even though the process is simpler, I've split this post up into a few parts so that each aspect of RPM package creation could be given it's fair share of attention.

The first step in creating a Linux package (or RPM which - technically - stands for RedHat Package Manager, although the format is used on many flavors of Unix) is to actually compile (or build) the software you're going to be packaging. It's important to either log your output (or, at least, the commands you execute) during the build process, as that information is going to be needed by the "rpmbuild" command that we'll ultimately use to create the finished product.

For the purposes of this "how to," we'll assume that you've downloaded the source for PACKAGE-3.2-1.tar.gz already and have "gcc" (or a suitable compiler) and "make" on your system. Also, we'll assume that you have the user privilege required to build and install software on your system.

Now, we'll get going, step by step:

1. First copy off your PACKAGE-3.2-1.tar.gz file into an appropriate location (I usually put them in a place like /usr/src/packages/SOURCES, since that file will be where it needs to be later, but you can copy it off to anywhere you like):

host # pwd
/users/me/softbuilds
host # ls
PACKAGE-3.2-1.tar.gz
host # cp PACKAGE-3.2-1.tar.gz /usr/src/packages/SOURCES/.
<--- Note that /usr/src/packages may be a completely different location depending on the flavor of Linux you're running, but the subfolder SOURCES should always be there. The same note will apply to all other instance where I mention the /usr/src/packages directory.

2. Now use gzip and tar to unpack your gzipped source (or, use tar for both operations if possible. For instance, Gnu Tar has a -z flag that you can use to avoid calling "gunzip" (or "gzip") altogether:

host # gunzip PACKAGE-3.2-1.tar.gz
host # tar xpf PACKAGE-3.2-1.tar


or

host # gzip -d -c PACKAGE-3.2-1.tar.gz||tar xpf -

or

host # tar xzpf PACKAGE-3.2-1.tar.gz <--- Gnu tar required for this (Probably the default for your Linux OS)

3. Change directories into the directory created by unpacking your gzipped PACKAGE-3.2-1.tar.gz file and be sure to read the INSTALL and/or README file(s). One (or both) of these will almost invariably include the specific commands you need to run in order to build and install your software.

host # cd PACKAGE-3.2-1

4. Follow the instructions to build your software. Below, I've run down what a typical install of a generic software package would look like (and assumes no errors). The one important thing to note below is the use of the "--prefix=" argument to the "configure" command. We want to be sure to build our package into a completely separate directory than we actually intend for the RPM to install later. This may seem counter-intuitive, but it's actually the easiest way to complete some of the upcoming "rpmbuild" steps and avoid utter confusion or complication ;)

host # ./configure --prefix=/usr/local/PACKAGE-3.2-1
...
<--- Probably lots of output. Generally only helpful if you have errors. There may be any number of other options, aside from "--prefix=," that you'll need to pass to configure, but that should be explained in the INSTALL and/or README file(s). Worst case, you can run "./configure --help" to see a list of all available options for configuring the build of the software you're installing.
host # make <--- This is the command that will run through the compile/build of your software package.
host # make check <--- Sometimes "make test," although this option may not even be available in your software's Makefile.
host # make install <--- This will complete your installation.

The specifics of your build may be more or less complicated, but (from the above, assuming all went well) we should have noted the following successfully run commands, in order:

host # configure --prefix=/usr/local/PACKAGE-3.2-1
host # make
host # make check/test
host #make install


You actually won't be using the --prefix flag directly in your specification file later, but you'll need to know the prefix, so it's best just to jot it down.

5. Now that your build is complete, generate a list of all the files that got created when you did your build and keep this for future use (you'll need it for the specification file later). A quick and easy way to do this is:

host # find /usr/local/PACKAGE-3.2-1 >FILELIST <--- Redirect all your output to FILELIST.

or

host # find /usr/local/PACKAGE-3.2-1 >FILELIST 2>&1 <--- Only if, for some bizarre reason, find sends any output to STDERR that's important.

Now you've got your software package built and are ready to move on to the next step in building your RPM package. We'll pick up there tomorrow!

Until then,

, Mike




Saturday, December 22, 2007

Working with Linux RPM's

This post is a continuation, of sorts, of my last post. This is more of a general-audience post. Most experienced admins know most of this stuff already. Like I mentioned previously, I try to write this blog with an appreciation for what it was like when I first started out in the business. I owe my success to a great many patient and helpful people.

In this post, I wanted to hit on the basics of working with RPM's in Linux (RPM stands for the Redhat Package Management system - basically, they're the software packages that make up your system). In later posts we'll go into some neat tricks... But for now, we'll stick with the basics. Knowing the basics in any field of interest is invaluable in growing and mastering that skillset, just like knowing your ABC's can really help if you ever intend to read or write :)

Check the bottom for a recap of all the RPM options we're going to use and their literal meanings:

1. To display the basic information for any RPM, just type:

host # rpm -qi RPM_NAME - like:

host # rpm -qi bash
Name : bash Relocations: /usr
Version : 2.05 Vendor: Red Hat, Inc.
Release : 8.2 Build Date: Mon 28 Jun 2004 10:33:55 AM CDT
Install date: Thu 12 Jan 2006 01:25:27 PM CST Build Host: host.redhat.com
Group : System Environment/Shells Source RPM: bash-2.05-8.2.src.rpm
... EDITED OUT FOR BREVITY'S SAKE!


2. If you're not sure where to start with the above command, just have RPM spit out all the packages it knows about and pipe that to more, like so:

host # rpm -qa|more
redhat-logos-1.1.3-1
glibc-2.2.4-32.18
cracklib-2.7-12
dosfstools-2.7-1
gdbm-1.8.0-11
...


3. Now that you've figured out what package you want to inspect (Note that you don't have to include the full name to get the information from RPM. The redhat-logos-1.1.3-1 program can be referred to simply as redhat-logos) and have gotten some basic information about it, you can list out all the files associated with the package like this:

host # rpm -ql bash
/bin/bash
/bin/bash2
/bin/sh
/etc/skel/.bash_logout
...


4. Here's one that doesn't require a lot of output, since it's somewhat of a re-explanation. You can add the -p flag to the examples in points 1 and 3 if you're querying an RPM package, and not the RPM database!

host # rpm -qip bash-2.05-8.2.i386.rpm <--- Listing out information for the RPM package itself.
host # rpm -qlp bash-2.05-8.2.i386.rpm <--- Listing out files associated with the RPM package itself.

5. Of course, you may find a file and want to know what RPM package it belongs to. You can get that by typing:

host # rpm -qif /etc
Name : filesystem Relocations: (not relocateable)
Version : 2.1.6 Vendor: Red Hat, Inc.
Release : 2 Build Date: Mon 20 Aug 2001 03:34:02 PM CDT
Install date: Thu 12 Jan 2006 01:24:41 PM CST Build Host: host.redhat.com
Group : System Environment/Base Source RPM: filesystem-2.1.6-2.src.rpm Vendor: Red Hat, Inc.
... (Just as long as the description in point 1)


6. If you want to install a new RPM, you'll need the package file, and would run RPM like this:

host # rpm -i bash-2.05-8.2.i386.rpm

This isn't very interesting (which may be what you want -- I don't care to look at verbose output "all" the time). You can spice it up by adding the -v and/or -h flag, like so:

host # rpm -ivh bash-2.05-8.2.i386.rpm

7. If you want to uninstall an RPM, you'll just need to know the abbreviated name, like I mentioned in point 4). You can also make this as verbose and visually entertaining as the system will allow with -v and/or -h:

host # rpm -e bash

Note that this command would return an error if you had multiple instances of the bash RPM installed. In that case, you could still abbreviate, but would have to include the version number. So you'd type

host # rpm -e bash-2.05.8.2

instead of just bash.

So, to recap, and possibly explain anything I may have glossed over, these basic commands should get you started working with the RPM package management facility on Linux. The translations of the flags we've covered are as follows:

Major flags (usually the ones preceded with a dash, but you can arrange the flags in whatever order you choose - just be careful - see note in the minor flags):

q = query
i = install
e = remove/uninstall

Minor flags

i = information (not the same as the major flag i. Of course, you'll probably never use -ii or -ei, as the combinations would be redundant and opposite, respectively.
a = all
l = list
p = RPM package file (e.g. whatever.rpm)
f = file
v = verbose
h = hash (prints lots of # symbols while it completes your request :)

Enjoy getting started working with RPM packages. They're one of the foundations of the Linux operating system. In fact, a combination of certain packages actually "is" the operating system. Knowing how to manipulate them and have them work for you can make it easier to explore many other things (like new software you've always wanted to install and try out :)

Best wishes,

, Mike