#!/bin/bash
set -u
declare -i ErrorCount=0
declare ThisScript=${0##*/}
declare ThisHost=${HOSTNAME%%.*}
declare ThisUser=
declare Version=1.4.3
declare ThisScriptHome=/p4/common/site/bin
declare SDPHostsCfg=/p4/common/site/config/sdp_hosts.cfg
declare FromHost=
declare HostUpgradeLog=
declare HostUpgradeCmd=
declare -i NoOp=1
declare LogTime=
declare Log=
declare H1="=============================================================================="
declare H2="------------------------------------------------------------------------------"
declare H3="++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
function msg () { echo -e "$*"; }
function errmsg () { msg "\nError: ${1:-Unknown Error}\n"; ErrorCount+=1; }
function bail () { errmsg "${1:-Unknown Error}"; exit "${2:-$ErrorCount}"; }
function usage () { msg "$ThisScript - Global Topology Upgrade."; exit 2; }
#------------------------------------------------------------------------------
# Function: terminate
# shellcheck disable=SC2317
function terminate
{
# Disable signal trapping.
trap - EXIT SIGINT SIGTERM
#dbg "$ThisScript: EXITCODE: $ErrorCount"
# Stop logging.
[[ "$Log" == off ]] || msg "\nLog is: $Log\n${H1}"
# With the trap removed, exit.
exit "$ErrorCount"
}
declare -i shiftArgs=0
set +u
while [[ $# -gt 0 ]]; do
case $1 in
(-h) usage -h;;
(-man) usage -man;;
(-V) msg "$ThisScript version $Version"; exit 2;;
(-y) NoOp=0;;
(-from) FromHost="$2"; shiftArgs=1;;
(-L) Log="$2"; shiftArgs=1;;
(-D) set -x;; # Debug; use 'set -x' mode.
(-*) usage -h "Unknown option ($1).";;
(*) usage -h "Unknown 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
source "$SDPHostsCfg" ||\
bail "Could not do: 'source $SDPHostsCfg'"
LogTime=$(date +'%Y-%m-%d-%H%M%S')
Log="${LOGS}/${ThisScript%.sh}.main.${LogTime}.log"
if [[ "$Log" != off ]]; then
touch "$Log" || bail "Could not touch log: $Log"
exec > >(tee "$Log")
exec 2>&1
msg "${H1}\nLog is: $Log\n"
fi
ThisUser=$(id -n -u)
msg "Starting $ThisScript version $Version as $ThisUser@$ThisHost on $(date)."
trap terminate EXIT SIGINT SIGTERM
msg "${H1}\nDoing Outer-to-Inner Upgrades ..."
if [[ "$ThisHost" == $HMS_HOST && -z "$FromHost" ]]; then
for h in $ALL_SDP_HOSTS; do
msg "${H2}\nKicking off upgrade on $h."
HostUpgradeCmd="$ThisScriptHome/$ThisScript -from $ThisHost"
[[ "$NoOp" -eq 0 ]] && HostUpgradeCmd+=" -y"
HostUpgradeLog="${LOGS}/${ThisScript%.sh}.${h}.${LogTime}.log"
ssh -q "$h" "$HostUpgradeCmd" > "$HostUpgradeLog" 2>&1 ||\
bail "$ThisScript failed on host $h. See: $HostUpgradeLog"
msg "Verified: Upgrade AOK on $h. Details in $HostUpgradeLog"
done
fi
if [[ -z "$FromHost" ]]; then
if [[ "$ThisHost" == $HMS_HOST ]]; then
msg "${H3}\nALL DONE!"
exit 0
else
bail "A Global Topology Upgrade must be kicked off from the HMS server, $HMS_HOST."
fi
fi
cd /hxdepots || bail "Could not do: cd /hxdepots"
[[ -d downloads ]] || mkdir downloads
cd downloads || bail "Could not do: cd downloads [from $PWD]."
[[ -d new ]] && mv new old."$(date +'%Y%m%d-%H%M%S')"
[[ -e sdp.Unix.tgz ]] && mv sdp.Unix.tgz sdp.Unix.old."$(date +'%Y%m%d-%H%M%S')"
curl -s -L -O https://workshop.perforce.com/download/guest/perforce_software/sdp/downloads/sdp.Unix.tgz
ls -l sdp.Unix.tgz
mkdir new || bail "Could not do: mkdir new [from $PWD]."
cd new || bail "Could not do: cd new [from $PWD]."
tar -xzf ../sdp.Unix.tgz || bail "Could not do: tar xzf ../sdp.Unix.tgz [from $PWD]."
cd /hxdepots/downloads/new/sdp/Server/Unix/p4/common/sdp_upgrade ||\
bail "Could not do: cd /hxdepots/downloads/new/sdp/Server/Unix/p4/common/sdp_upgrade"
./sdp_upgrade.sh || bail "SDP Upgrade preflight failed on $ThisHost. Aborting."
if [[ "$NoOp" -eq 0 ]]; then
sleep 2
./sdp_upgrade.sh -y || bail "SDP Upgrade failed on $ThisHost. Aborting."
else
msg "DRY RUN: Not executing sdp_upgrade.sh with '-y'."
fi
cd /p4/sdp/helix_binaries || bail "Could not do: cd /p4/sdp/helix_binaries"
if [[ "$NoOp" -eq 0 ]]; then
./get_helix_binaries.sh -r r24.2 || bail "Call to get_helix_binaries.sh failed."
else
msg "DRY RUN: Executing ./get_helix_binaries.sh with '-n'."
./get_helix_binaries.sh -r r24.2 -n || bail "Call to get_helix_binaries.sh failed."
fi
cd /home/perforce || bail "Could not do: cd /home/perforce"
upgrade.sh || bail "P4D Upgrade preflight failed on $ThisHost. Aborting."
if [[ "$NoOp" -eq 0 ]]; then
sleep 2
upgrade.sh -y || bail "P4D Upgrade failed on $ThisHost. Aborting."
else
msg "DRY RUN: Not executing upgrade.sh with '-y'."
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]> |