#!/usr/bin/perl # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # # It was written by Andy Jeffries while under the employment # of Internet Assist Ltd. # # Copyright (C) 2002 Internet Assist Ltd. All Rights Reserved. # # V1.0.0 $module = $ARGV[0]; if ($ARGV[1] != "--no-test") { $test=1; } if ($ARGV[1] != "--no-gzip-man") { $gzman=1; } # OK, first thing is to get the modules listing from CPAN print "Obtaining the list of modules from ftp.cpan.org\n"; `wget -q ftp://ftp.cpan.org/pub/CPAN/modules/02packages.details.txt.gz`; if (! -e "02packages.details.txt.gz") { print "ERROR: Failed to download module list from ftp.cpan.org, probably too busy\n"; exit(); } print "Extracting the list of modules found\n"; `gunzip 02packages.details.txt.gz`; print "Looking for the latest version of $module\n"; open PACKAGES_LIST, "02packages.details.txt"; while ($line = ) { if ($line =~ /^(\S+)\s*([0-9.]*)\s*(\S*)/) { if (lc($1) eq lc($module)) { $module = $1; $new_version = $2; $full_filename = "http://www.cpan.org/authors/id/$3"; $full_filename =~ /([a-zA-Z0-9.\-]*)\s*$/; $filename = $1; } } } close PACKAGES_LIST; if (!$new_version) { print "Sorry $module wasn't found on CPAN.\n"; @lines = `grep -i $module 02packages.details.txt`; if (@lines) { print "\nHowever, searching for $module within the database found the following:\n"; foreach $line (@lines) { print "$line"; } } `rm 02packages.details.txt*`; exit(); } `rm 02packages.details.txt*`; $module_ver_variable = '$'.$module."::VERSION"; $current_version = `perl -e 'use $module; print "$module_ver_variable";' 2>/dev/null`; if ($new_version eq $current_version) { print "Your version $current_version is already up-to-date.\n"; exit(); } $t1=$current_version+0; $t2=$new_version+0; if ($t1 > $t2) { print "Your version $t1 is newer than the $t2 version on CPAN.\n"; exit(); } print "Downloading version $new_version of $module\n"; `wget -q $full_filename`; `cp $filename /usr/src/redhat/SOURCES`; print "Extracting version $new_version of $module\n"; $tar = `tar zxvf $filename`; $tar =~ /^(\S*?)\//; $extract_folder=$1; open README, "$extract_folder/README"; while ($line = ) { chomp($line); if ($line =~ /^NAME/) { $line = ; chomp($line); $line =~ s/^\s*//; $title = $line; print "Title is: $title\n"; } if ($line =~ /^DESCRIPTION/) { while (($line = ) && ($line =~ /^\s+/)) { chomp($line); $line =~ s/^\s*//; $description .= "$line\n"; } print "Description is:\n$description\n"; } } close README; if (!$title) { print "Please enter a title, followed by Enter:"; $title = ; chomp($title); print "Title: $title\n"; } if (!$description) { print "Please enter a description, followed by a dot on a line of it's own:\n"; while ($line !~ /^\./) { $description .= $line; $line = ; } print "Summary:\n$description\n"; } $title =~ s/[^a-zA-Z0-9.\-: ]//; $description =~ s/[^a-zA-Z0-9.\-: \n]//mg; print "Extracting the files and making\n"; # Ascertain the files list `cd $extract_folder; perl Makefile.PL 2>&1`; $tmp = `grep "PREFIX = " $extract_folder/Makefile`; $tmp =~ /= (.*)/; $prefix=$1; $log = `cd $extract_folder; make 2>&1; make PREFIX="./install" install 2>&1`; while ($log =~ /^(Installing|Skipping) (.*)/mg) { $file = $2; chomp($file); $file =~ s/ \(unchanged\)//; $file =~ s/install\//$prefix\//; if (($file =~ /\/man\//) && (!$gzman)) { $file .= ".gz"; } push @files, $file; } while ($log =~ /^Warning: prerequisite (.*?) failed to load/mg) { push @missing, $1; print "Missing $1\n"; } if (@missing) { print "Creation of RPM failed! Missing:\n"; foreach ($missing) { print "\tRequires $_\n"; } } else { $spec_name="perl-$module"; $spec_name =~ s/::/-/; open SPECFILE, ">$spec_name.spec"; print SPECFILE "Name: $spec_name\n"; print SPECFILE "Version: $new_version\n"; print SPECFILE "Release: 1\n"; print SPECFILE "Source: $full_filename\n"; print SPECFILE "Copyright: Unknown\n"; print SPECFILE "Summary: $title\n"; print SPECFILE "Group: System Environment/Libraries\n"; print SPECFILE "Buildroot: \%{_tmppath}/\%{name}-build.root\n"; print SPECFILE "\%description\n"; print SPECFILE "$description\n"; print SPECFILE "\%prep\n"; print SPECFILE "\%setup -n $extract_folder\n\n"; # print SPECFILE "tar zxvf $filename\n"; # print SPECFILE "cd $extract_folder\n\n"; print SPECFILE "\%clean\n"; print SPECFILE "rm -rf \$RPM_BUILD_ROOT\n\n"; print SPECFILE "\%build\n"; print SPECFILE "perl Makefile.PL\nmake\n"; if ($test) { print SPECFILE "make test\n\n"; } print SPECFILE "\%install\n"; print SPECFILE "make -e PREFIX=\"\$RPM_BUILD_ROOT/$prefix\" install\n\n"; print SPECFILE "\%files\n"; foreach $file (@files) { print SPECFILE "$file\n"; } } `rm -rf $extract_folder`; `mv $filename /usr/src/redhat/SOURCES/`; `mv $spec_name.spec /usr/src/redhat/SPECS/`; `rpm -ba /usr/src/redhat/SPECS/$spec_name.spec`;