install_sdp_perl.sh #18

  • //
  • guest/
  • perforce_software/
  • sdp/
  • main/
  • Server/
  • Unix/
  • setup/
  • install_sdp_perl.sh
  • View
  • Commits
  • Open Download .zip Download (10 KB)
#!/bin/bash
#------------------------------------------------------------------------------
set -u

#==============================================================================
# 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=Unset
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
   # shellcheck disable=SC1090
   source "$bash_lib"
done

declare Version=1.9.0
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 [-f] [-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 7.6 and likely on other Linux derivatives
	with no modification.

REQUIREMENTS:
	The Perforce Server Deployment Packge (Rev SDP/Unix/2019.1+)
	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/g++' compiler
	must be installed and available in the PATH.

OPTIONS:

 -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, $PerlRoot, does not exist.

 -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:
	/tmp/install_sdp_perl.sh.<datestamp>.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.

EXAMPLES:
Typical usage is after after installing the SDP, called with no arguments:

cd /hxdepots/sdp/Server/Unix/setup
./install_sdp_perl.sh

"
   fi

   exit 1
}

#==============================================================================
# Command Line Processing

declare -i shiftArgs=0
declare -i Force=0
declare -i KeepWorkingDir=1
declare PerlRoot=/p4/common/perl
declare Tmp=${P4TMP:-/tmp}
declare RunUser=
declare RunArch=x86_64
declare PerforceRel=r18.2
declare PublicDepotPort=public.perforce.com:1666
declare PublicDepotReaderUser=ftp
declare P4PerlPublicDepotPath="//guest/perforce_software/p4perl/..."
declare SDPEnvFile="/p4/common/bin/p4_vars"
declare ThisArch=
declare ThisOS=
declare WorkingDir=$Tmp/p4perl.$$.$RANDOM

set +u
while [[ $# -gt 0 ]]; do
   case $1 in
      (-f) Force=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'."

[[ "$P4U_LOG" == "Unset" ]] && \
   P4U_LOG="/tmp/install_sdp_perl.sh.$(date +'%Y%m%d-%H%M%S').log"

#==============================================================================
# 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 | tr -d ' ')

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 package dependencies."

[[ -z "$(command -v gcc)" || -z "$(command -v g++)" ]] && \
   bail "No gcc found in the path.  You may need to install it.  Please\\n check that the gcc and gcc-c++ packages are\\n installed, e.g. with:\\n\\tyum install -y gcc gcc-c++\\n\\nOr, on SuSE, with:\\n\\tzypper in gcc gcc-c++\\n\\n"

[[ -z "$(command -v make)" ]] && \
   bail "No make found in the path.  You may need to install it.  Please\\n check that the make packages is\\n installed, e.g. with:\\n\\tyum install -y make\\n\\nOr, on SuSE, with:\\n\\tzypper in make\\n\\n"

ThisArch=$(uname -m)

if [[ "$ThisArch" == "$RunArch" ]]; then
   msg "Verified:  Running on a supported architecture [$ThisArch]."
   ThisOS=$(uname -s)
   case $ThisOS in
      (Darwin|Linux) msg "Verified: Running on a supported OS [$ThisOS].";;
      (*) 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

cd "$WorkingDir" || bail "Could not cd to [$WorkingDir]."

if [[ -d ws/.p4root ]]; then
   if [[ $Force -eq 0 ]]; then
      msg "Skipping clone of existing p4perl cloned workspace."

      export P4CONFIG=.p4config.p4perl.local
      export P4ENVIRO=/dev/null/.p4enviro
      msg "Fetching latest updates from Public Depot in cloned p4perl workspace in $PWD."
      run "p4 -d $PWD/ws fetch" || bail "Failed to update p4perl cloned workspace."
   else
      msg "Removing existing p4perl clone workspace."
      run "/bin/rm -rf $PWD/ws" || bail "Could not remove p4perl workspace dir [$PWD/ws]. Aborting."
      unset P4CONFIG P4ENVIRO
   fi
fi

if [[ ! -d $PWD/ws/.p4root ]]; then
   run "mkdir ws" "Creating base dir for cloning P4Perl, $PWD/ws." ||\
      bail "Failed to create dir [$PWD/ws] for cloning P4Perl."

   export P4ENVIRO=/dev/null/.p4enviro
   export P4CONFIG=.p4config.p4perl.local
   run "p4 -u $PublicDepotReaderUser -d $PWD/ws clone -p $PublicDepotPort -f $P4PerlPublicDepotPath" ||\
      bail "Failed to clone P4Perl from Public Depot [P4PORT=$PublicDepotPort]."
   unset P4CONFIG P4ENVIRO
fi

cd "$WorkingDir/ws/main" || bail "Could not cd to [$WorkingDir/ws/main]."

run "./install_p4perl.sh -r $PerlRoot" \
   "Calling install_p4perl.sh from P4Perl package to build/install Perl/P4Perl $PerforceRel." ||\
   bail "Failed to build and install P4Perl."

export PATH=$PerlRoot/site/bin:$PerlRoot/bin:$PATH

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

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
#19 27331 C. Thomas Tyler Released SDP 2020.1.27325 (2021/01/29).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#18 25311 C. Thomas Tyler Released SDP 2019.1.25309 (2019/03/07).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#17 25245 C. Thomas Tyler Released SDP 2019.1.25238 (2019/03/02).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#16 22685 Russell C. Jackson (Rusty) Update main with current changes from dev.
#15 22185 C. Thomas Tyler Released SDP 2017.2.22177 (2017/05/17).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#14 21723 C. Thomas Tyler Released SDP 2017.1.21720 (2017/02/17).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#13 21244 C. Thomas Tyler Released SDP 2016.2.21239 (2016/12/06).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#12 21176 C. Thomas Tyler Enhanced SDP Python installer to 'http:' protocol in place of
'ftp:' in URL references.  This works around a problem I encountered
with outbound 'ftp' being blocked by some corporate firewall (not the
local machine firewall).  Using 'http:' in the URL works just as well
for the purposes of this script.

Enhanced SDP Perl installer in the same way, but the SDP Perl is broken
now for unrelated reasons.
#11 20353 C. Thomas Tyler Released SDP 2016.1.20348.
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev',
with selective removal of changes related to work-in-progress
changes.
#10 18961 C. Thomas Tyler Released: SDP/MultiArch/2016.1/18958 (2016/04/08).
#9 17315 C. Thomas Tyler Released SDP/MultiArch/2016.1/17297 (2016/02/03).

Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#8 16525 C. Thomas Tyler Tweaked ActivePerl version from 5.18.4.1804 to 5.18.4.1805.
#7 16524 C. Thomas Tyler Updated to support new standard -V (show version innfo) flag.
#6 15843 C. Thomas Tyler Fixed typos in copyright message.
#5 15833 C. Thomas Tyler Replaced the big license comment block with a shortened
form referencing the LICENSE file included with the SDP package.

Doc and Copyright/LICENSE updates for install_sdp_(perl|python).sh.

Update copyright year in the LICENSE file.

#review
#4 13937 C. Thomas Tyler Pushing SDP 2015.1.13934.
#3 13908 C. Thomas Tyler Pushing SDP 2015.1.13906.
#2 11763 C. Thomas Tyler Updated selected Perl version from 5.16 to 5.18, as 5.16 is no
longer available from ActiveState.com.

According to P4Perl release notes for 2014.1 (the latest
release as of now), Perl up to 5.16 is supported.  Preliminary
testing indicates that Perl 5.18 compiles OK and works OK.

#review.
#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.