#!/usr/bin/perl -w #******************************************************************************* #* Name : buildp4rpm.pl #* Description : Build an RPM based on the latest versions of p4 and #* p4d on Perforce's FTP site. #* #* Syntax : buildp4rpm.pl --rpmroot #* [--distro [redhat|suse]] #* [--ftp] #* #* Builds the RPMS from the Perforce binaries in the current directory. Use #* --ftp to get the script to download the latest build for you prior to #* doing the build. #******************************************************************************* use Net::FTP; use Getopt::Long; use File::Copy; use Carp; use strict; use vars qw( $SPECFILE $TMPFILE $FTPHOST $P4_FTP_PATH $P4D_FTP_PATH $P4WEB_FTP_PATH $P4FTP_FTP_PATH $EMAIL_ADDRESS $DISTRO $TARBALL ); #******************************************************************************* #* Configuration section #******************************************************************************* $SPECFILE="p4.spec"; $TMPFILE="p4.spec.tmp"; $TARBALL="p4.tar.gz"; $FTPHOST="ftp.perforce.com"; $P4_FTP_PATH="/pub/perforce/r01.1/bin.linux52x86/p4"; $P4D_FTP_PATH="/pub/perforce/r01.1/bin.linux52x86/p4d"; $P4WEB_FTP_PATH="/pub/perforce/r01.1/bin.linux52x86/p4web"; $P4FTP_FTP_PATH="/pub/perforce/r01.1/bin.linux52x86/p4ftpd"; $EMAIL_ADDRESS="someone\@somewhere.com"; #******************************************************************************* #* End of configuration section #******************************************************************************* sub croaksyntax() { print < [--distro [redhat|suse]] [--ftp] where: --distro - Type of distribution to build RPM for. Valid values are "redhat" and "suse" only at the moment. --rpmroot - Path to RPM build root directory. This script will place all the files required to build the RPM in the build tree. --ftp - Causes the latest builds to be downloaded from the Perforce FTP site prior to editing the spec file. If not specified, then the binaries in the PATH are used. EOF exit( 0 ); } sub GetFile( $ ) { my $file = shift; print( "Fetching file $file from $FTPHOST ...\n" ); my $ftp = new Net::FTP( "$FTPHOST", 'Passive' => 1 ); $ftp->login( "anonymous", $EMAIL_ADDRESS ) or croak( "Failed to login to $FTPHOST. Download aborted." ); $ftp->get( "$file" ) or croak( "Failed to download file: $file." ); } sub GetVersInfo( $ ) { my $file = shift; my $version; my $build; open( FH, "$file -V |" ) or croak( "Can't execute $file to work out it's version" ); while ( ) { if ( /^Rev. P4\w*\/\w+\/([\d\.]+)\/(\d+)/ ) { $version = $1; $build = $2; } } close( FH ); return ( $version, $build ); } sub EditSpec { my $version = shift; my @builds = @_; open( IN, "$SPECFILE" ) or croak( "Cannot open $SPECFILE for reading" ); open( OUT, ">$TMPFILE" ) or croak( "Cannot open $TMPFILE for writing" ); while ( ) { if ( /^Version:/ ) { print( OUT "Version: $version\n" ); } elsif ( /^Release:\s*(\d+)/ ) { print( OUT "Release: ", shift(@builds), "\n" ); } else { print( OUT $_ ); } } close( IN ); close( OUT ); } #******************************************************************************* #* Start of main script #******************************************************************************* # Check command line my $use_ftp = ''; my $rpmroot = ""; $DISTRO = "redhat"; GetOptions( 'rpmroot=s' => \$rpmroot, 'distro=s' => \$DISTRO, 'ftp' => \$use_ftp ); # RPM root is mandatory and if ( $rpmroot eq "" ) { croaksyntax(); } $DISTRO = lc $DISTRO; # Ensure that we can see the distro if ( ! -d "p4-$DISTRO" ) { print <