#!/bin/bash #============================================================================== # Copyright and license info is available in the LICENSE file included with # the Server Deployment Package (SDP), and also available online: # https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE #------------------------------------------------------------------------------ #============================================================================== # Declarations and Environment # Allow override of P4U_HOME, which is set only when testing P4U scripts. export P4CBIN=${P4CBIN:-/p4/common/bin} export P4U_HOME=${P4U_HOME:-/p4/common/bin} export P4U_LIB=${P4U_LIB:-/p4/common/lib} export P4U_ENV=$P4U_LIB/p4u_env.sh export P4U_LOG="/tmp/install_sdp_perl.sh.$(date +'%Y%m%d-%H%M%S').log" export VERBOSITY=${VERBOSITY:-3} # Environment isolation. For stability and security reasons, prepend # PATH to include dirs where known-good scripts exist. # known/tested PATH and, by implication, executables on the PATH. export PATH=$P4U_HOME:$PATH:~/bin:/usr/local/bin:$PATH export P4CONFIG=${P4CONFIG:-.p4config} [[ -r "$P4U_ENV" ]] || { echo -e "\nError: Cannot load environment from: $P4U_ENV\n\n" exit 1 } declare BASH_LIBS="$P4U_ENV $P4U_LIB/libcore.sh $P4U_LIB/libp4u.sh" for bash_lib in $BASH_LIBS; do source $bash_lib done declare Version=1.5.4 declare -i SilentMode=0 #============================================================================== # Local Functions #------------------------------------------------------------------------------ # Function: terminate function terminate { # Disable signal trapping. trap - EXIT SIGINT SIGTERM # Don't litter. cleanTrash vvmsg "$THISSCRIPT: EXITCODE: $OverallReturnStatus" # Stop logging. [[ "${P4U_LOG}" == off ]] || stoplog # With the trap removed, exit. exit $OverallReturnStatus } #------------------------------------------------------------------------------ # Function: usage (required function) # # Input: # $1 - style, either -h (for short form) or -man (for man-page like format). #------------------------------------------------------------------------------ function usage { declare style=${1:--h} echo "USAGE for $THISSCRIPT v$Version: $THISSCRIPT [-R rel] [-P perl_rel] [-r perl_root] [-f] [-d downloads_dir] [-w work_dir] [-L <log>] [-si] [-v<n>] [-n] [-D] or $THISSCRIPT [-h|-man|-V] " if [[ $style == -man ]]; then echo -e " DESCRIPTION: This builds installs ActivePerl, the Perforce API, and P4Perl to the standard SDP location. PLATFORM SUPPORT: This works on Red Hat Linux and CentOS platforms. It works on CentOS 6.4 thru 6.8 and likely on other Linux derivatives with no modification. It supports the bin.linux26_64 (Linux) and bin.darwin90x86_64 (Mac OSX/Darwin) architectures. REQUIREMENTS: The Perforce Server Deployment Packge (Rev SDP/Unix/2014.3+) must be installed and configured. In particular the SDP Environment file [$SDPEnvFile] must define a value for OSUSER. Development utilities such as 'make' and the 'gcc' compiler must be installed and available in the PATH. The 'wget' utility must be installed and available in the PATH. (Note that 'wget' is not installed with OSX by default, at least not os of OSX 10.9/Mavericks. However, it can be acquired and compiled using XCode). OPTIONS: -R rel Specify the Perforce release, e.g. r16.1. The default is $PerforceRel. This is used for both the Perforce API and P4Perl. -P perl_rel Specify the ActivePerl release, e.g. 5.22.3.2204. The default is $PerlRel. -r perl_root Specify the python root. The default is $PerlRoot This can be used doing a dry run of an an installation. It should not be used for a production install, since the SDP environment file, /p4/common/bin/p4_vars, defines the default Perl root in the PATH. -f Specify -f (force) to re-install the SDP Perl if it is already installed. By default, in will be installed only if the Perl root dir (see -r) does not exist. -w work_dir Specify the working dir. By default, a temporary working directory is created under $Tmp, with a random name. This temporary working directory can be removed upon successful completion. -d downloads_dir Specify a directory to use to find downloads. The default is: $DownloadsDir The downloads directory is checked for these needed tarfiles: $PerlTarFile $P4APITarFile -v<n> Set verbosity 1-5 (-v1 = quiet, -v5 = highest). -L <log> Specify the path to a log file, or the special value 'off' to disable logging. By default, all output (stdout and stderr) goes to: $(dirname ${P4U_LOG}). NOTE: This script is self-logging. That is, output displayed on the screen is simultaneously captured in the log file. Do not run this script with redirection operators like '> log' or '2>&1', and do not use 'tee.' -si Operate silently. All output (stdout and stderr) is redirected to the log only; no output appears on the terminal. This cannot be used with '-L off'. -n No-Op. Prints commands instead of running them. -D Set extreme debugging verbosity. HELP OPTIONS: -h Display short help message -man Display man-style help message -V Dispay version info for this script and its libraries. FILES: EXAMPLES: SEE ALSO: " fi exit 1 } #============================================================================== # Command Line Processing declare -i shiftArgs=0 declare -i Force=0 #declare -i KeepWorkingDir=0 declare -i KeepWorkingDir=1 declare PerlRoot=/p4/common/perl declare Tmp=${P4TMP:-/tmp} declare WorkingDir=$Tmp/perl.$$.$RANDOM declare DownloadsDir=$Tmp/downloads/p4perl declare PerlBuildDir= declare P4PerlBuildDir= declare APIDir= declare ApiArch= declare RunUser= declare RunArch=x86_64 declare PerforceRel=r16.1 declare PerlRel=5.22.3.2204 declare GLibcVer=glibc-2.15-401614 declare PublicDepotPort=public.perforce.com:1666 declare PublicDepotReaderUser=sdp_reader declare P4PerlPublicDepotPath=//guest/perforce_software/p4perl/... declare PerlTarFile=ActivePerl-${PerlRel}-${RunArch}-linux-${GLibcVer}.tar.gz declare P4APITarFile=p4api.tgz declare P4PerlCloneCmd= declare SDPEnvFile=/p4/common/bin/p4_vars declare ThisArch= declare ThisOS= set +u while [[ $# -gt 0 ]]; do case $1 in (-R) PerforceRel=$2; shiftArgs=1;; (-R) PerlRel=$2; shiftArgs=1;; (-r) PerlRoot=$2; shiftArgs=1;; (-f) Force=1;; (-w) if [[ ${2^^} == KEEP ]]; then KeepWorkingDir=1 else WorkingDir=$2 KeepWorkingDir=1 fi ;; (-d) DownloadsDir=$2; shiftArgs=1;; (-h) usage -h;; (-man) usage -man;; (-V) show_versions; exit 1;; (-v1) export VERBOSITY=1;; (-v2) export VERBOSITY=2;; (-v3) export VERBOSITY=3;; (-v4) export VERBOSITY=4;; (-v5) export VERBOSITY=5;; (-L) export P4U_LOG=$2; shiftArgs=1;; (-si) SilentMode=1;; (-n) export NO_OP=1;; (-D) set -x;; # Debug; use 'set -x' mode. (*) usageError "Unknown arg ($1).";; esac # Shift (modify $#) the appropriate number of times. shift; while [[ $shiftArgs -gt 0 ]]; do [[ $# -eq 0 ]] && usageError "Bad usage." shiftArgs=$shiftArgs-1 shift done done set -u [[ $KeepWorkingDir -eq 0 ]] && GARBAGE+="$WorkingDir" #============================================================================== # Command Line Verification [[ $SilentMode -eq 1 && $P4U_LOG == off ]] && \ usageError "Cannot use '-si' with '-L off'." #============================================================================== # Main Program trap terminate EXIT SIGINT SIGTERM declare -i OverallReturnStatus=0 [[ ! -d $Tmp ]] && bail "Missing SDP tmp dir [$Tmp]. Aborting." if [[ "${P4U_LOG}" != off ]]; then touch ${P4U_LOG} || bail "Couldn't touch log file [${P4U_LOG}]." # Redirect stdout and stderr to a log file. if [[ $SilentMode -eq 0 ]]; then exec > >(tee ${P4U_LOG}) exec 2>&1 else exec >${P4U_LOG} exec 2>&1 fi initlog fi if [[ ! -r "$SDPEnvFile" ]]; then bail "Missing or unreadable SDP Environment File [$SDPEnvFile]. Aborting." fi RunUser=$(grep '^export OSUSER=' $SDPEnvFile |\ tail -1 | cut -d '=' -f 2) RunUser=$(echo $RunUser) if [[ -n "$RunUser" ]]; then msg "The OSUSER defined in the SDP environment file is $RunUser." else bail "Could not detect OSUSER in SDP environment file [$SDPEnvFile]. Aborting." fi if [[ $USER == $RunUser ]]; then msg "Verified: Running as $USER." else bail "Running as $USER. Run this only as the OSUSER [$RunUser] defined in the SDP Environment File [$SDPEnvFile]. Aborting." fi msg "Starting $THISSCRIPT v$Version at $(date) with command line:\n\t$CMDLINE\n\n" msg "Verifying dependencies." [[ -z "$(which gcc 2>/dev/null)" || -z "$(which g++ 2>/dev/null)" ]] && \ bail "No gcc found in the path. You may need to install it. Please\n check that the gcc.x86_64 and gcc-c++.x86_64 packages are\n installed, e.g. with:\n\tyum install -y gcc.x86_64 gcc-c++.x86_64\n\n" [[ -z "$(which wget 2>/dev/null)" ]] && \ bail "No wget found in the path. You may need to install it. Please check that the wget.x86_64 packages is installed, e.g. with:\n\tyum install -y wget.x86_64\n\n" ThisArch=$(uname -m) if [[ $ThisArch == $RunArch ]]; then msg "Verified: Running on a supported architecture [$ThisArch]." ThisOS=$(uname -s) ApiArch=UNDEFINED_API_ARCH case $ThisOS in (Darwin) ApiArch="darwin90x86_64";; (Linux) ApiArch="linux26x86_64";; (*) bail "Unsupported value returned by 'uname -m': $ThisOS. Aborting.";; esac else bail "Running on architecture $ThisArch. Run this only on hosts with '$RunArch' architecture. Aborting." fi if [[ -d $PerlRoot ]]; then if [[ $Force -eq 0 ]]; then bail "The SDP Perl root directory exists: [$PerlRoot]. Aborting." else run "/bin/rm -rf $PerlRoot" || bail "Could not remove SDP Perl root dir [$PerlRoot]. Aborting." fi fi if [[ ! -d $WorkingDir ]]; then run "/bin/mkdir -p $WorkingDir" || bail "Could not create working dir [$WorkingDir]." fi if [[ ! -d $DownloadsDir ]]; then run "/bin/mkdir -p $DownloadsDir" || bail "Could not create downloads dir [$DownloadsDir]." fi cd "$DownloadsDir" || bail "Could not cd to [$DownloadsDir]." msg "Downloading dependencies to $DownloadsDir." if [[ ! -r $PerlTarFile ]]; then run "wget -q --no-check-certificate http://downloads.activestate.com/ActivePerl/releases/$PerlRel/$PerlTarFile" ||\ bail "Could not get $PerlTarFile." else msg "Skipping download of existing $PerlTarFile file." fi if [[ ! -r $P4APITarFile ]]; then run "wget -q http://ftp.perforce.com/perforce/$PerforceRel/bin.$ApiArch/$P4APITarFile" ||\ bail "Could not get file '$P4APITarFile' for $PerforceRel." else msg "Skipping download of existing $P4APITarFile file." fi if [[ -d p4perl/.p4root ]]; then if [[ $Force -eq 0 ]]; then msg "Skipping clone of existing p4perl cloned workspace." export P4CONFIG=.p4config msg "Fetching latest updates from Workshop in cloned p4perl workspace in $PWD." run "p4 -d $PWD/p4perl/main fetch" || bail "Failed to update p4perl cloned workspace." else msg "Removing existing p4perl clone workspace." run "/bin/rm -rf $PWD/p4perl" || bail "Could not remove p4perl workspace dir [$PWD/p4perl]. Aborting." fi fi if [[ ! -d p4perl/.p4root ]]; then run "mkdir p4perl" "Creating base dir for cloning P4Perl" ||\ bail "Failed to create dir [$PWD/p4perl] for cloning P4Perl" run "p4 -u $PublicDepotReaderUser -d $PWD/p4perl clone -p $PublicDepotPort -f $P4PerlPublicDepotPath" ||\ bail "Failed to clone P4Perl from The Workshop [P4PORT=$PublicDepotPort]." fi cd "$WorkingDir" || bail "Could not cd to working dir [$WorkingDir]." PerlBuildDir=$(tar -tzf $DownloadsDir/$PerlTarFile|head -1|cut -d '/' -f1) run "tar -xzpf $DownloadsDir/$PerlTarFile" cd "$PerlBuildDir" || bail "Could not cd to Perl build dir [$PerlBuildDir]." echo -e "yes\nyes\n" > tmp.input.txt ./install.sh --license-accepted --prefix=$PerlRoot < tmp.input.txt ||\ bail "Failed to install ActivePerl." export PATH=$PerlRoot/site/bin:$PerlRoot/bin:$PATH cd "$WorkingDir" || bail "Could not cd to working dir [$WorkingDir]." APIDir=$PWD/$(tar -tf $DownloadsDir/$P4APITarFile|head -1|cut -d '/' -f1) run "tar -xzpf $DownloadsDir/$P4APITarFile" P4PerlBuildDir="$DownloadsDir/p4perl/main" cd "$P4PerlBuildDir" ||\ bail "Could not cd to P4Perl build dir [$P4PerlBuildDir]." if [[ ! -r Version ]]; then echo "Warning: No Version file found, generating a sample Version file." echo -e "RELEASE = 2016 1 testbuild ;\nPATCHLEVEL = 1429849 ;\nSUPPDATE = 2017 01 18 ;" > Version fi if [[ ! -r RELNOTES.txt ]]; then echo "Warning: No RELNOTES.txt file found, generating a sample file." echo -e "Release Notes for P4Perl, Perforce's script API for Perl\n Version 2016.1\n Introduction\n\n\tThis is a sample release notes file with no actual release notes.\n To determine the version of your P4Perl, issue the following command: perl -MP4 -e \"print P4::Identify()\"\n" > RELNOTES.txt fi echo -e "Building P4Perl, logging to $PWD/build.log, with this version file: $(cat Version)\n" run "perl Makefile.PL -apidir=$APIDir < /dev/null" \ "Generating Makefile for building P4Perl." ||\ bail "Failed to generate Makefile for P4Perl." run "make install" "Building and installing P4Perl." ||\ bail "Failed to build P4Perl." msg "Add this to your PATH: $PerlRoot/site/bin:$PerlRoot/bin" msg "Add this to your MANPATH: $PerlRoot/site/man:$PerlRoot/man" if [[ $OverallReturnStatus -eq 0 ]]; then msg "${H}\nSuccess. P4Perl is ready.\n" else msg "${H}\nProcessing completed, but with errors. Scan above output carefully.\n" fi # Illustrate using $SECONDS to display runtime of a script. msg "That took about $(($SECONDS/3600)) hours $(($SECONDS%3600/60)) minutes $(($SECONDS%60)) seconds.\n" # See the terminate() function, which is really where this script exits. exit $OverallReturnStatus
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 23205 | Robert Cowham | Merged all changes from dev to test | ||
#4 | 22477 | Robert Cowham | Bring latest dev changes into test | ||
#3 | 22142 | Robert Cowham | Merge in latest changes from Dev | ||
#2 | 20726 | Robert Cowham | Catch up from dev | ||
#1 | 18586 | Robert Cowham | Branching using cowhamr.sdp.dev | ||
//guest/perforce_software/sdp/dev/Server/Unix/setup/install_sdp_perl.sh | |||||
#8 | 16870 | C. Thomas Tyler |
Updated to ActivePerl 5.20.3.2003, as 5.18 is no longer available on ActiveState.com. UPDATE 2016/-1/21 ttyler: I moved the checkout to the 'dev' branch instead of the 'main' branch, so I'm filing a new review and closing the old one. |
||
#7 | 16832 | Robert Cowham |
Update p4perl versions from 5.18 which is no longer available on ActiveState site to public. declare PerlRel=5.22.1.2201 declare GLibcVer=glibc-2.15-299574 #review-16833 @ttyler @rjackson |
||
#6 | 16563 | C. Thomas Tyler |
Routine Merge Down to dev from main using: p4 merge -b perforce_software-sdp-dev p4 resolve -as |
||
#5 | 16029 | C. Thomas Tyler |
Routine merge to dev from main using: p4 merge -b perforce_software-sdp-dev |
||
#4 | 13930 | C. Thomas Tyler | Path tweak to help find wget on Mac. | ||
#3 | 13902 | C. Thomas Tyler |
Modified install_sdp_python and install_sdp_perl to use independent donwloads directories, since each may need to build with a separate version of the core Perforce C++ API. For example, presently P4Python 2015.1 builds with 2015.1 of the API, why P4Perl 2014.1 uses the 2014.1 API. Moved version ID near the top of the file. Updated default versions for utilities to install. |
||
#2 | 12028 | C. Thomas Tyler | Refreshed SDP dev branch, merging down from main. | ||
#1 | 10994 | Robert Cowham | Catchup from Main | ||
//guest/perforce_software/sdp/main/Server/Unix/setup/install_sdp_perl.sh | |||||
#1 | 10973 | C. Thomas Tyler |
Added script to build and install ActivePerl and P4Perl to standard SDP location, /p4/common/perl. Corresponding updates to p4_vars.template: * Added PERLHOME and PYHOME vars. * Updated PATH and MANPATH. |