#!/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 P4 upgrades.
The SDP scripts sdp_upgrade.sh (that upgrades the SDP) and upgrade.sh
(that upgrades P4) 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 P4 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 only reporting. It does not change any data.
If the preflight is determined to have failed, the corresponding SDP
or P4 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 Specify '-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 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 | |
|---|---|---|---|---|---|
| #2 | 33529 | C. Thomas Tyler |
Cosmetic: normalize double-backslash \\n / \\t to single-backslash \n / \t An older version of ShellCheck once recommended escaping backslash-n and backslash-t as \\n / \\t in double-quoted strings; a later version reversed that guidance since it was unnecessary. Both forms behave identically at runtime, but the double-backslash form is visual clutter. Applied via tools/sed_fixer.sh across the tree; no functional change. |
||
| #1 | 33516 | C. Thomas Tyler |
Consistency pass: fix absolute URLs, p4ms->hms renames, script/doc typos and bugs - Convert absolute workshop.perforce.com URLs to relative paths in dlp/ReadMe.md - Fix case-mismatch link to HMS_Product_Roadmap.md in README.md - Rename reset_p4ms.sh -> reset_hms.sh and p4broker_p4ms_test -> p4broker_hms_test - Fix .sh-suffix bugs: bin/hms calling global_replica_status.sh (should be no ext), and matching SEE ALSO / doc references for sdp_sync and global_replica_status - Add missing scripts (gtu, hrun, irun, global_replica_status) to gen_script_man_pages.sh - Add stub scripts: nj_help.sh, broker_njob.pl, broker_mkproj.pl, broker_jr.pl - Remove dangling absolute symlinks HostCM/p4 and HostCM/p4d (cruft) - Rename test/b -> test/broker_ctl.sh for clarity - Fix real bugs: broker_imply-u.pl broken regex match, gen_dlp_broker_cfg.sh and gen_nj_broker_cfg.sh copy-pasted Version-file existence check, garbled comment in broker_must_be_owner.pl, unclosed quote in tools/gsr.sh usage(), missing 'h' in HMS_SystemComponents.md broker command example (^ms$ -> ^hms$) - Fix broken sed command and incomplete sentence in HMS_Install_Notes.md and SDP_and_HMS_Update_Process.md - Fix broken markdown table in HMS_Product_Roadmap.md - Fix unclosed parenthesis, missing verb, and FKA Swarm mislabel in HMSDeploymentPlanning.adoc - Standardize //streams/main/... naming in HostCM/ReadMe.md - Numerous typo fixes across README.md, HMS_SystemComponents.md, SDP_and_HMS_Update_Process.md, HMS_TightShipManagement.adoc, HMSDeploymentPlanning.adoc, HostCM/ReadMe.md, and various scripts Co-authored-by: Copilot <[email protected]> |