hms_exe_versions.sh #1

  • //
  • p4-hms/
  • dev/
  • p4/
  • common/
  • site/
  • lib/
  • hms_exe_versions.sh
  • View
  • Commits
  • Open Download .zip Download (5 KB)
# hms_exe_versions.sh
Version=2.0.0

#==============================================================================
# Copyright and license info is available in the LICENSE file included with
# the Helm Management System (HMS), and also available online:
# https://workshop.perforce.com/projects/p4-hms/main/LICENSE
#------------------------------------------------------------------------------

declare ExeVersionsBaseURL="https://updates.perforce.com/static"
declare -A ExeVersionsURL        # URL indexed by lowercase name, e.g. 'p4d'.
declare -A ExeVersionsFile       # Local file indexed by exe, e.g. 'p4d'.
declare -A ExeVersionsDownloaded # Indication of whether new version had to
                                 # be downloaded.
declare -A StagedExe             # Downloaded exe, staged for upgrade.
declare -A ExePatchAvailable     # 1 if newer patch available, else 0.
declare -A ExeUpgradeAvailable   # 1 if newer major version available, else 0.

declare -a P4Exes
declare StagingDir=

P4Exes[0]='p4'
P4Exes[1]='p4d'
P4Exes[2]='p4broker'
P4Exes[3]='p4p'

ExeVersionsURL['p4']="$ExeVersionsBaseURL/P4/P4.json"
ExeVersionsURL['p4d']="$ExeVersionsBaseURL/P4D/P4D.json"
ExeVersionsURL['p4broker']="$ExeVersionsBaseURL/P4Broker/P4Broker.json"
ExeVersionsURL['p4p']="$ExeVersionsBaseURL/P4Proxy/P4Proxy.json"

ExeVersionsFile['p4']="${P4TMP:-/tmp}/P4.json"
ExeVersionsFile['p4d']="${P4TMP:-/tmp}/P4D.json"
ExeVersionsFile['p4broker']="${P4TMP:-/tmp}/P4Broker.json"
ExeVersionsFile['p4p']="${P4TMP:-/tmp}/P4Proxy.json"

StagingDir="$P4TMP/staged.$$.$RANDOM"
StagedExe['p4']="$StagingDir/p4"
StagedExe['p4d']="$StagingDir/p4d"
StagedExe['p4broker']="$StagingDir/p4broker"
StagedExe['p4p']="$StagingDir/p4p"

ExeVersionsDownloaded['p4']=0
ExeVersionsDownloaded['p4d']=0
ExeVersionsDownloaded['p4broker']=0
ExeVersionsDownloaded['p4p']=0

#==============================================================================
# HMS Library Functions.

#------------------------------------------------------------------------------
# get_latest_exe_version (Exe, Platform)
#
# Input:
# $1 - Exe name, e.g. 'p4d', 'p4broker', etc.
# $2 - Platform (optional), e.g. 'linux2x6x86_64'; this value is the default.
#------------------------------------------------------------------------------
function get_latest_exe_version () {
   vvmsg "CALL: get_latest_exe_version ($*)"
   declare Exe="${1:-Unset}"
   declare Platform="${2:-linux26x86_64}"
}

#------------------------------------------------------------------------------
# get_latest_exe_minor_version (Exe, MajorVersion, Platform)
#
# Input:
# $1 - Exe name, e.g. 'p4d', 'p4broker', etc.
# $2 - MajorVersion, e.g. 'r20'
# $3 - Platform (optional), e.g. 'linux2x6x86_64'; this value is the default.
#------------------------------------------------------------------------------
function get_latest_exe_patch_version () {
   vvmsg "CALL: get_latest_exe_patch_version ($*)"
   declare Exe="${1:-Unset}"
   declare MajorVersion="${2:-Unset}"
   declare Platform="${3:-linux26x86_64}"
}

#------------------------------------------------------------------------------
# get_latest_exe_patch_version (Exe, MajorVersion, MinorVersion, Platform)
#
# Input:
# $1 - Exe name, e.g. 'p4d', 'p4broker', etc.
# $2 - MajorVersion, e.g. 'r20'
# $3 - MinorVersion, e.g. '1' (the '1' in 'r20.1').
# $4 - Platform (optional), e.g. 'linux2x6x86_64'; this value is the default.
#------------------------------------------------------------------------------
function get_latest_exe_patch_version () {
   vvmsg "CALL: get_latest_exe_patch_version ($*)"
   declare Exe="${1:-Unset}"
   declare MajorVersion="${2:-Unset}"
   declare MinorVersion="${3:-Unset}"
   declare Platform="${4:-linux26x86_64}"
}

#------------------------------------------------------------------------------
function download_versions_data () {

   cd "${P4TMP:-/tmp}" || return 1

   for exe in ${P4Exes[@]}; do
      if [[ -r "${ExeVersionsFile[$exe]}" ]]; then
         msg "Using existing versions data file: ${ExeVersionsFile[$exe]}"
         continue
      fi

      ExeVersionsDownloaded[$exe]=1

      if curl -s -k -O "${ExeVersionsURL[$exe]}"; then
         msg "Downloaded ${ExeVersionsFile[$exe]}"
      else
         errmsg "Failed to download from URL: ${ExeVersionsURL[$exe]}"
      fi
   done

   cd - > /dev/null 2>&1 ||:
}

#------------------------------------------------------------------------------
function load_exe_versions () {
   declare -i Force="${1:-0}"

   if [[ "$Force" -eq 1 || ! -r "$ExeVersionsFile" ]]; then
      download_versions_data
      ExeVersionsDataLoaded=0
   fi

   [[ "$ExeVersionsDataLoaded" -eq 0 && "$Force" -eq 0 ]] && return

}
# Change User Description Committed
#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]>