#!/bin/bash set -u declare ThisScript=${0##*/} declare ThisUser= declare Version=1.0.1 declare TmpFile= declare TestCmd= declare SwarmTriggerConf="/opt/perforce/etc/swarm-trigger.conf" declare -i ErrorCount=0 function msg () { echo -e "$*"; } function errmsg () { msg "\\nError: ${1:-Unknown Error}\\n"; ErrorCount+=1; } function bail () { errmsg "Error: ${1:-Unknown Error}"; exit "${2:-1}"; } ThisUser=$(whoami) msg "\\nStarting $ThisScript v$Version as $ThisUser@${HOSTNAME%%.*}." msg "Loading Swarm trigger configuration from: $SwarmTriggerConf" if source "$SwarmTriggerConf"; then msg "Settings loaded:" cat "$SwarmTriggerConf" else bail "Failed to load Swarm trigger configuration. Aborting." fi TmpFile=$(mktemp) TestCmd="wget --timeout 10 --post-data shelve,1234 $SWARM_HOST/queue/add/$SWARM_TOKEN" msg "Running: $TestCmd" if wget --timeout 10 --post-data "shelve,1234" "$SWARM_HOST/queue/add/$SWARM_TOKEN" > $TmpFile 2>&1; then if grep -q "200 OK" "$TmpFile"; then cat "$TmpFile" msg "Verified: Swarm host is accessible and returned expected 200 message." else cat "$TmpFile" errmsg "Swarm host did not reply with expected 200 message. Output:\\n" fi else cat "$TmpFile" errmsg "The wget command failed.\\n" fi # Cleanup Swarm tokens and the temp file. msg "Cleanup up temp files." find . -type f -name "$SWARM_TOKEN*" -print -exec rm -f {} \; rm -f "$TmpFile" exit "$ErrorCount"
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 27909 | C. Thomas Tyler | Fixed bug in output display. | ||
#3 | 27908 | C. Thomas Tyler | Added info re: ticket duration; replaced error with warning if trigger is short-term. | ||
#2 | 27907 | C. Thomas Tyler |
Added internal documentation. Enhanced to safely run from anywhere, and cleand up the cleanup logic. Added test that the configured Swarm user has a long-term ticket. chmod +x |
||
#1 | 27906 | C. Thomas Tyler | Added baseline script. |