#!/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 <path> #* [--tarball <path>] #* [--specfile <path>] #* [--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 $TARBALL ); #******************************************************************************* #* Configuration section #******************************************************************************* $SPECFILE="p4.spec"; $TMPFILE="p4.spec.tmp"; $TARBALL="p4.tar.gz"; $FTPHOST="ftp.perforce.com"; $P4_FTP_PATH="/pub/perforce/r00.1/bin.linux52x86/p4"; $P4D_FTP_PATH="/pub/perforce/r00.1/bin.linux52x86/p4d"; $EMAIL_ADDRESS="someone\@somewhere.com"; sub croaksyntax() { print <<EOF; usage: buildp4rpm.pl --rpmroot <path> [--tarball <path>] [--specfile <specfile>] [--ftp] where: --tarball - Path to p4.tar.gz tarball containing the RPM support files. --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. --specfile - Specifies the name of the specfile to edit. If not specified, then defaults to $SPECFILE. 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 ( <FH> ) { 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 ( <IN> ) { 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 = "p4"; my $p4d_path = "p4d"; my $rpmroot = ""; GetOptions( 'rpmroot=s' => \$rpmroot, 'tarball=s' => \$TARBALL, 'specfile=s' => \$SPECFILE, 'ftp' => \$use_ftp ); # RPM root is mandatory if ( $rpmroot eq "" ) { croaksyntax(); } # Ensure that we can see the p4 tarball if ( ! -f $TARBALL ) { print <<EOF; Can't find the supporting tarball $TARBALL. Please locate the file and re-run this script EOF exit( 0 ); } # Ensure we can see the specfile if ( ! -f $SPECFILE ) { print( "Specfile $SPECFILE not found. Please supply a valid specfile.\n"); exit( 0 ); } # Get the files using FTP if required. if ( $use_ftp ) { print( "Fetching files using FTP ...\n" ); GetFile( $P4_FTP_PATH ); GetFile( $P4D_FTP_PATH ); chmod( 0755, "p4", "p4d" ); # Make sure that we execute the downloaded p4 and p4d to get # version info. $p4_path = "./p4"; $p4d_path ="./p4d"; } # Now work out the versions print( "Computing version info ...\n" ); my $version; my $client_build; my $server_build; ( $version, $client_build ) = GetVersInfo( $p4_path ); ( $version, $server_build ) = GetVersInfo( $p4d_path ); # Now edit the spec file print( "Editing specfile ...\n" ); EditSpec( $version, $server_build, $client_build ); # Now distribute the files in the RPM build tree. print( "Populating RPM build tree ...\n" ); copy( $TARBALL, "$rpmroot/SOURCES/p4.tar.gz" ); copy( $SPECFILE, "$rpmroot/SPECS/p4.spec" ); copy( $p4_path, "$rpmroot/SOURCES/p4" ); copy( $p4d_path, "$rpmroot/SOURCES/p4d" ); # Now build the RPM and SRPM print( "Building RPM and SRPM ...\n" ); system( "rpm -ba $rpmroot/SPECS/p4.spec" );
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 487 | Tony Smith |
Renamed the RPM building tree because this RPM is quite RedHat specific. SuSE RPM builder to be added |
||
#3 | 458 | Tony Smith |
Fixed the checkpoint deletion script which was previously broken. Tweaked the spec file so that the perforce user is created prior to the file installation so the ownership is set correctly. Updated the build script so that the target type is always set to i386 since that's how p4 and p4d are built. |
||
#2 | 449 | Tony Smith | Corrected some minor irritations. | ||
#1 | 448 | Tony Smith |
Updated RPM building kit so that it will automatically download the latest binaries from ftp.perforce.com. Spec file is also a bit more clever, and logrotate, checkpointing and verify support has been added. Thanks to Matthew Rice for the logrotate script! |