Skip to content
25 changes: 14 additions & 11 deletions scripts/check_for_updates.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ github_url="https://api.github.com/repos/perforce/p4prometheus/commits?per_page=
github_download_url="https://raw.githubusercontent.com/perforce/p4prometheus/master/scripts"

function msg () { echo -e "$*"; }
function bail () { msg "\nError: ${1:-Unknown Error}\n"; exit ${2:-1}; }
function bail () { msg "\nError: ${1:-Unknown Error}\n"; exit "${2:-1}"; }

function usage
{
Expand All @@ -35,6 +35,12 @@ Uses the github API and stores a local file with current status.

Depends on 'curl' and 'jq' being in the path.
"
if [[ "$style" == -man ]]; then
# Add full manual page documentation here.
true
fi

exit 2
}

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
Expand All @@ -49,10 +55,10 @@ ConfigFile=".update_config"
set +u
while [[ $# -gt 0 ]]; do
case $1 in
(-h) usage -h && exit 0;;
# (-man) usage -man;;
(-h) usage -h;;
(-man) usage -man;;
(-c) ConfigFile=$2; shiftArgs=1;;
(-*) usage -h "Unknown command line option ($1)." && exit 1;;
(-*) usage -h "Unknown command line option ($1).";;
esac

# Shift (modify $#) the appropriate number of times.
Expand All @@ -67,18 +73,15 @@ set -u
cd "$SCRIPT_DIR" || bail "Can't cd to $SCRIPT_DIR"

# Check for dependencies

curl=$(which curl)
[[ $? -eq 0 ]] || bail "Failed to find curl in path"
jq=$(which jq)
[[ $? -eq 0 ]] || bail "Failed to find jq in path"
[[ -n "$(command -v curl)" ]] || bail "Failed to find curl in PATH."
[[ -n "$(command -v jq)" ]] || bail "Failed to find jq in PATH."

last_github_sha=""
last_github_date=""
#last_github_date=""

if [[ -e "$ConfigFile" ]]; then
last_github_sha=$(grep last_github_sha "$ConfigFile" | cut -d= -f2)
last_github_date=$(grep last_github_date "$ConfigFile" | cut -d= -f2)
#last_github_date=$(grep last_github_date "$ConfigFile" | cut -d= -f2)
fi

github_sha=$(curl "$github_url" | jq '.[] | .sha')
Expand Down
17 changes: 12 additions & 5 deletions scripts/install_p4prom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function bail () { msg "\nError: ${1:-Unknown Error}\n"; exit "${2:-1}"; }

function usage
{
declare style=${1:--h}
declare errorMessage=${2:-Unset}

if [[ "$errorMessage" != Unset ]]; then
Expand Down Expand Up @@ -58,6 +59,12 @@ Examples:
./install_p4prom.sh -nosdp -m /p4metrics -u perforce

"
if [[ "$style" == -man ]]; then
# Add full manual page documentation here.
true
fi

exit 2
}

# Command Line Processing
Expand All @@ -72,14 +79,14 @@ declare P4LOG=""
set +u
while [[ $# -gt 0 ]]; do
case $1 in
(-h) usage -h && exit 1;;
# (-man) usage -man;;
(-h) usage -h;;
(-man) usage -man;;
(-m) metrics_root=$2; shiftArgs=1;;
(-u) OsUser="$2"; shiftArgs=1;;
(-push) InstallPushgateway=1;;
(-nosdp) UseSDP=0;;
(-l) P4LOG="$2"; shiftArgs=1;;
(-*) usage -h "Unknown command line option ($1)." && exit 1;;
(-*) usage -h "Unknown command line option ($1).";;
(*) export SDP_INSTANCE=$1;;
esac

Expand All @@ -97,8 +104,7 @@ if [[ $(id -u) -ne 0 ]]; then
exit 1
fi

wget=$(which wget)
[[ $? -eq 0 ]] || bail "Failed to find wget in path"
[[ -n "$(command -v wget)" ]] || bail "Failed to find wget in PATH."

if command -v getenforce > /dev/null; then
selinux=$(getenforce)
Expand Down Expand Up @@ -126,6 +132,7 @@ if [[ $UseSDP -eq 1 ]]; then
source /p4/common/bin/p4_vars "$SDP_INSTANCE" ||\
{ echo -e "\\nError: Failed to load SDP environment.\\n"; exit 1; }

# shellcheck disable=SC2153
p4="$P4BIN -u $P4USER -p $P4PORT"
$p4 info -s || bail "Can't connect to P4PORT: $P4PORT"
p4prom_config_dir="/p4/common/config"
Expand Down
13 changes: 10 additions & 3 deletions scripts/install_prom_graf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function bail () { msg "\nError: ${1:-Unknown Error}\n"; exit "${2:-1}"; }

function usage
{
declare style=${1:--h}
declare errorMessage=${2:-Unset}

if [[ "$errorMessage" != Unset ]]; then
Expand All @@ -41,6 +42,12 @@ or
-push Means install pushgateway (otherwise it won't be installed)

"
if [[ "$style" == -man ]]; then
# Add full manual page documentation here.
true
fi

exit 2
}

# Command Line Processing
Expand All @@ -51,10 +58,10 @@ declare -i InstallPushgateway=0
set +u
while [[ $# -gt 0 ]]; do
case $1 in
(-h) usage -h && exit 1;;
(-h) usage -h;;
(-push) InstallPushgateway=1;;
# (-man) usage -man;;
(-*) usage -h "Unknown command line option ($1)." && exit 1;;
(-man) usage -man;;
(-*) usage -h "Unknown command line option ($1).";;
esac

# Shift (modify $#) the appropriate number of times.
Expand Down
Loading