#!/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> #* [--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 <<EOF; usage: buildp4rpm.pl --rpmroot <path> [--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 ( <FH> ) { 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 ( <IN> ) { 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 <<EOF; Can't find the supporting scripts in the directory p4-$DISTRO. Please locate these files and rerun this script. EOF exit( 0 ); } # Ensure we can see the specfile $SPECFILE="p4-$DISTRO/p4.spec"; if ( ! -f $SPECFILE ) { print( "Specfile $SPECFILE missing.\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 ); GetFile( $P4WEB_FTP_PATH ); GetFile( $P4FTP_FTP_PATH ); chmod( 0755, "p4", "p4d", "p4web", "p4ftpd" ); } else { # check they exist foreach my $file ( qw( p4 p4d p4web p4ftpd ) ) { die( "$file is not found in current directory" ) if ( ! -f "./$file" ); } } # Now work out the versions print( "Computing version info ...\n" ); my $version; my $client_build; my $server_build; my $web_build; my $ftp_build; ( $version, $client_build ) = GetVersInfo( "./p4" ); ( $version, $server_build ) = GetVersInfo( "./p4d" ); ( $version, $web_build ) = GetVersInfo( "./p4web" ); ( $version, $ftp_build ) = GetVersInfo( "./p4ftpd" ); # Now edit the spec file print( "Editing specfile ...\n" ); EditSpec( $version, $server_build, $server_build, $client_build, $web_build, $ftp_build ); # Create a tarball from the distro sources system( "tar zcf $TARBALL p4-$DISTRO" ); # Now distribute the files in the RPM build tree. print( "Populating RPM build tree ...\n" ); copy( $TARBALL, "$rpmroot/SOURCES/p4.tar.gz" ); copy( $TMPFILE, "$rpmroot/SPECS/p4.spec" ); copy( "p4", "$rpmroot/SOURCES/p4" ); copy( "p4d", "$rpmroot/SOURCES/p4d" ); copy( "p4web", "$rpmroot/SOURCES/p4web" ); copy( "p4ftpd", "$rpmroot/SOURCES/p4ftpd" ); unlink( $TMPFILE ); # Now build the RPM and SRPM print( "Building RPM and SRPM ...\n" ); system( "rpm -ba --target=i386 $rpmroot/SPECS/p4.spec" );
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 734 | Tony Smith |
Updated for 2001.1. Also removed the PATH searching since it wasn't working properly anyway and added a bit more clarity to the README file. |
||
#2 | 498 | Tony Smith |
Rework so that the specfile does not get edited in place 'coz that would confuse Perforce ( writable files and all that ). |
||
#1 | 495 | Tony Smith | Re-ordered directory structure for the ( hopefully ) last time | ||
//guest/tony_smith/perforce/RPM/RedHat/buildp4rpm.pl | |||||
#2 | 491 | Tony Smith |
Adjustments. Now downloads 2000.2 by default and the buildscript now takes a --distro argument so you can specify what style of RPM you want. Means I've got to rename these paths again I guess. The tarball is now built on the fly based on the distro you pick. |
||
#1 | 487 | Tony Smith |
Renamed the RPM building tree because this RPM is quite RedHat specific. SuSE RPM builder to be added |
||
//guest/tony_smith/perforce/SRPM/buildp4rpm.pl | |||||
#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! |