pre-sdp_upgrade.sh #1

  • //
  • p4ms/
  • dev/
  • p4/
  • common/
  • site/
  • upgrade/
  • pre-sdp_upgrade.sh
  • View
  • Commits
  • Open Download .zip Download (6 KB)
#!/bin/bash
#==============================================================================
set -u

#==============================================================================
# Declarations and Environment
declare ThisScript=${0##*/}
declare Version=1.0.7
declare ThisUser=
declare SDPInstallRoot="/p4"
declare SDPCommon="$SDPInstallRoot/common"
declare SDPPackageRoot="$SDPInstallRoot/sdp"
declare -i Debug=0
declare -i ErrorCount=0
declare OutputFile=

#==============================================================================
# Local Function
function msg () { echo -e "$*"; }
function dbg () { [[ "$Debug" -eq 0 ]] || msg "DEBUG: $*"; }
function errmsg () { msg "\\nError: ${1:-Unknown Error}\\n"; ErrorCount+=1; }
function bail () { errmsg "${1:-Unknown Error}"; exit "${2:-1}"; }
function usage () {
   local style=${1:--h}
   local usageErrorMsg=${2:-}

   [[ -n "$usageErrorMsg" ]] && msg "\\n\\nUsage Error: $usageErrorMsg\\n\\n"

   msg "USAGE for $ThisScript v$Version:

$ThisScript [-d|-D]

or

$ThisScript [-h|-man]
"
   if [[ $style == -man ]]; then
      msg "
DESCRIPTION:
	This script, pre-sdp_upgrade.sh, symlink'd as pre-upgrade.sh, does
	does HMS preflight checks for SDP and Helix Core upgrades.

	The SDP scripts sdp_upgrade.sh (that upgrades the SDP) and upgrade.sh
	(that upgrades Helix Core) both have a built-in mechanism to call
	site-local preflight checks in addition to the standard SDP preflight
	checks.  The mechansim based simply on the existence of a file (or
	symlink).  If /p4/common/site/upgrade/pre-sdp_upgrade.sh exists, it
	will be called by sdp_upgrade.sh as additional preflight checks.  If
	/p4/common/site/pre-upgrade.sh exists, it will be called by upgrade.sh
	as additional preflight checks.

	In an HMS managed environment, the additional preflight checks are done
	to ensure that we are \"Tight Ship\" compliant prior to starting
	upgrades across a set of Helix Core servers.

	The pre-sdp_ugprade.sh (or pre-upgrade.sh if called as a symlink) are
	primarily intended to be called by the other scripts, but can also be
	called directly for manual flight checks.

	This script does does only reporting. It does not change any data.
	If the preflight is determined to have failed, the corresponding SDP
	or Helix Core upgrade will abort before attempting the upgrade.
	Manual changes are generally needed to get back into Tight Ship
	condition on the current machine before proceeding.

OPTIONS:
 -d     Specify '-d' to enable debug mode, for more verbose output.

 -D     Speicfy '-D' to include '-d' and use bash 'set -x' extreme debugging mode.

HELP OPTIONS:
 -h	Display short help message
 -man	Display man-style help message

EXAMPLES:
	Example 1: Typical usage with no options:

	$ThisScript

	Example 2: Verbose usage:

	$ThisScript -d

SEE ALSO:
	For info on sdp_upgrade.sh, run: sdp_ugprade.sh -man

	For info on upgrade.sh, run: ugprade.sh -man
"
   fi

   exit 2
}

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

declare -i shiftArgs=0

set +u
while [[ $# -gt 0 ]]; do
   case $1 in
      (-h) usage -h;;
      (-man) usage -man;;
      (-d) Debug=1;;
      (-D) Debug=1; set -x;; # Use bash 'set -x' extreme debugging mode.
      (-*) dbg "$ThisScript: Ignoring unhandled option ($1).";;
      (*) dbg "$ThisScript: Ignoring unhandled parameter ($1).";;
   esac

   # Shift (modify $#) the appropriate number of times.
   shift; while [[ $shiftArgs -gt 0 ]]; do
      [[ $# -eq 0 ]] && usage -h "Incorrect number of arguments."
      shiftArgs=$shiftArgs-1
      shift
   done
done
set -u

#==============================================================================
# Command Line Verification

#==============================================================================
# Main Program

ThisUser=$(id -n -u)
msg "Started $ThisScript as $ThisUser@${HOSTNAME%%.*} on $(date)."

cd "$SDPCommon" || bail "Could not cd to $SDPCommon."

OutputFile=$(mktemp)
export P4CONFIG=/p4/.p4config.SDP

msg "Checking status of key SDP versioned directories."
for d in "$SDPCommon"/* "$SDPPackageRoot"/helix_binaries; do
   if [[ -d "$d" ]]; then
      [[ "$d" =~ /sample_depot/$|/test$ ]] && continue

      cd "$d" || bail "Could not cd to $d"

      msg "Operating in: $PWD"

      p4 opened ... > "$OutputFile" 2>&1

      if grep -q 'not opened on this client' "$OutputFile"; then
         dbg "Verified: Directory $d/... has no checked out files."
      else
         errmsg "The $d directory may have opened files. A 'p4 opened ...' in this directory reported:"
         cat "$OutputFile"
      fi

      msg "Doing: p4 -s flush $PWD/..."
      p4 -s flush $PWD/... > "$OutputFile" 2>&1
      cat "$OutputFile"

      p4 status > "$OutputFile" 2>&1

      if grep -q 'to reconcile' "$OutputFile"; then
         dbg "Verified: Directory $d/... is versioned and clean."
      else
         errmsg "The $d directory is dirty. A 'p4 status' reported:"
         cat "$OutputFile"
      fi
   fi
done

msg "Checking status of SDP Version file: $SDPPackageRoot/Version"
p4 opened "$SDPPackageRoot/Version" > "$OutputFile" 2>&1
if grep -q 'not opened on this client' "$OutputFile"; then
   dbg "Verified: The $SDPPackageRoot/Version file is not chedcked out."
else
   errmsg "The $SDPPackageRoot/Version file may be checked out. A 'p4 opened $SDPPackageRoot/Version' reported:"
   cat "$OutputFile"
fi

p4 status "$SDPPackageRoot/Version" > "$OutputFile" 2>&1
if grep -q 'to reconcile' "$OutputFile"; then
   dbg "$SDPPackageRoot/Version is clean."
else
   errmsg "The $SDPPackageRoot/Version file is dirty. A 'p4 status' reported:"
   cat "$OutputFile"
fi

rm -f "$OutputFile"

if [[ "$ErrorCount" -eq 0 ]]; then
   msg "\\nVerified: Key SDP folders and and the Version file are clean, versioned, and free of cruft."
else
   errmsg "Could not verify that key SDP folders are clean, versioned, and free of cruft."
fi

exit "$ErrorCount"
# Change User Description Committed
#1 31797 C. Thomas Tyler p4 merge -b HMS_to_P4MS; p4 resolve -as; p4 submit
//guest/perforce_software/hms/dev/p4/common/site/upgrade/pre-sdp_upgrade.sh
#1 30521 C. Thomas Tyler Added sample upgrade scripts.