#!/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] #* #* Default behaviour is to build the RPM and SRPM based on the current #* versions of p4 and p4d which it will find in the PATH. With the --ftp #* flag, this script will download the latest binary from the Perforce #* FTP site (currently this is Release 2000.1). #* #******************************************************************************* 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 $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/r00.2/bin.linux52x86/p4"; $P4D_FTP_PATH="/pub/perforce/r00.2/bin.linux52x86/p4d"; $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" ); $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. P4D?\/\w+\/([\d\.]+)\/(\d+)/ ) { $version = $1; $build = $2; } } close( FH ); return ( $version, $build ); } sub EditSpec( $$$ ) { my $version = shift; my $server_build = shift; my $client_build = shift; open( IN, "$SPECFILE" ) or croak( "Cannot open $SPECFILE for reading" ); open( OUT, ">$TMPFILE" ) or croak( "Cannot open $TMPFILE for writing" ); my $seen_client = 0; while ( ) { if ( /^Version:/ ) { print( OUT "Version: $version\n" ); } elsif ( /^Release:\s*(\d+)/ ) { if ( $seen_client ) { print( OUT "Release: $client_build\n" ); } else { print( OUT "Release: $server_build\n" ); } } else { print( OUT $_ ); } if ( /^\%package.*p4-client/ ) { $seen_client = 1; } } close( IN ); close( OUT ); rename( $SPECFILE, "$SPECFILE.bck" ); rename( $TMPFILE, $SPECFILE ); } #******************************************************************************* #* Start of main script #******************************************************************************* # Check command line my $use_ftp = ''; my $p4_path = [ -f "./p4" ] ? "./p4" : "p4"; my $p4d_path = [ -f "./p4d" ] ? "./p4d" : "p4d"; 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 <