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