#!/bin/bash
#------------------------------------------------------------------------------
set -u
#------------------------------------------------------------------------------
# The SDP upgrade.sh script add files/symlinks to /p4/common/bin. This
# script captures them.
#------------------------------------------------------------------------------
# Declarations and Environment
declare ThisScript=${0##*}
declare Version=1.1.1
declare ThisUser=
declare -i ErrorCount=0
declare -i NoOp=1
declare RunMode="Dry Run"
declare Dir=
declare DirList=
#------------------------------------------------------------------------------
# Local Function
function msg () { echo -e "$*"; }
function errmsg () { msg "\\nError: ${1:-Unknown Error}\\n"; ErrorCount+=1; }
function bail () { errmsg "${1:-Unknown Error}"; exit "${2:-1}"; }
#------------------------------------------------------------------------------
# Command Line Procesing
[[ "$*" == *-y* ]] && NoOp=0
#------------------------------------------------------------------------------
# Main Program
ThisUser=$(id -n -u)
[[ "$NoOp" -eq 0 ]] && RunMode="Live Operation"
msg "Started $ThisScript ($RunMode) as $ThisUser@${HOSTNAME%%.*} on $(date)."
export P4CONFIG=/p4/.p4config.SDP
# List of dirs to process. Include /p4/sdp/helix_binaries, and all dirs under
# /p4/common except a select few special dirs that we don't want upgrades to
# interact with.
DirList="/p4/sdp/helix_binaries $(ls -d /p4/common/* | grep -E -v '(python|perl|ruby)$')"
for Dir in $DirList; do
msg "Post-upgrade HMS updates in: $Dir"
cd "$Dir" || bail "Could not do: cd \"$Dir\""
msg "Operating in directory: $PWD"
if [[ "$NoOp" -eq 0 ]]; then
msg "Running: p4 -s flush ..."
p4 -s flush ...
msg "Running: p4 rec"
p4 rec
if [[ -n "$(p4 -ztag -F %depotFile% opened ...)" ]]; then
msg "Submitting ..."
p4 -s submit -d "Post-upgrade updates in $PWD/..." ...
else
msg "No changes to submit in $PWD/..."
fi
else
msg "NO-OP: Would do: p4 -s flush ..."
p4 status
msg "Submitting ..."
msg "NO-OP: Would do: p4 -s submit -d \"Post-upgrade updates in $PWD/...\""
fi
done
if [[ "$NoOp" -eq 0 ]]; then
msg "Running: p4 -s flush /p4/sdp/Version"
p4 -s flush /p4/sdp/Version
msg "Running: p4 rec /p4/sdp/Version"
p4 rec /p4/sdp/Version
if [[ -n "$(p4 -ztag -F %depotFile% opened /p4/sdp/Version)" ]]; then
msg "Submitting /p4/sdp/Version."
p4 -s submit -d "Post-upgrade update to /p4/sdp/Version." /p4/sdp/Version
else
msg "No changes to submit to /p4/sdp/Version."
fi
else
msg "NO-OP: Would do: p4 -s flush /p4/sdp/Version"
p4 status /p4/sdp/Version
msg "Submitting /p4/sdp/Version."
msg "NO-OP: Would do: p4 -s submit -d \"Post-upgrade update of /p4/sdp/Version\""
fi
exit "$ErrorCount"