-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck
More file actions
executable file
·88 lines (72 loc) · 2.68 KB
/
check
File metadata and controls
executable file
·88 lines (72 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
set -e
exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging
# save payload in tmp for later inspection
cat > /tmp/payload <&0
# print input
payload=$(cat /tmp/payload)
echo "payload: $payload"
# print first parameter
echo "First Parameter is $1"
# extract parameters
OPSMAN_IP_ADDRESS=$(echo $payload | jq -r '.source.OPSMAN_ADDRESS')
OPS_MGR_USR=$(echo $payload | jq -r '.source.OPSMAN_USERNAME')
OPS_MGR_PWD=$(echo $payload | jq -r '.source.OPSMAN_PASSWORD')
IAAS=$(echo $payload | jq -r '.source.IAAS')
PIVNET_TOKEN=$(echo $payload | jq -r '.source.PIVNET_TOKEN')
EXCLUDE_TILE_LIST=$(echo $payload | jq -r '.source.EXCLUDE_TILE_LIST // ""')
CURRENT_VERSION=$(echo $payload | jq -r '.version // ""')
echo "OPSMAN_IP_ADDRESS : $OPSMAN_IP_ADDRESS"
echo "OPS_MGR_USR : $OPS_MGR_USR"
echo "IAAS : $IAAS"
echo "EXCLUDE_TILE_LIST : $EXCLUDE_TILE_LIST"
echo "CURRENT_VERSION : $CURRENT_VERSION"
# Get current opsman Versions
diagnostic_report=$(
om-linux \
-t https://$OPSMAN_IP_ADDRESS \
-u $OPS_MGR_USR \
-p $OPS_MGR_PWD \
-k \
curl --silent --path "/api/v0/diagnostic_report"
)
if [[ -z "$EXCLUDE_TILE_LIST" ]]; then
EXCLUDE_TILE_LIST=[]
fi
current_versions=$( echo $diagnostic_report |
jq --arg exceptions $EXCLUDE_TILE_LIST \
--arg iaas $IAAS \
-r \
'[
.added_products.deployed[]
| select (.name | inside($exceptions) | not)
| .stemcell
| capture("bosh-stemcell-(?<major>[0-9]{4,5}).(?<minor>[0-9]{1,4})-" + $iaas + "-hyperv-ubuntu-trusty-go_agent.tgz")
| { version: (.major + "." + .minor), major: .major, minor: .minor} ]
| unique'
)
echo "current releases : $current_versions"
releases=$(curl -s -H "Authorization: Token token=\"$PIVNET_TOKEN\"" https://network.pivotal.io/api/v2/products/stemcells/releases)
new_releases=$(
echo $releases | jq -c -r --argjson current "$current_versions" '
[ .releases[].version
| capture("(?<major>[0-9]{4,5})\\.(?<minor>[0-9]{1,5})")
| select( .major
| inside($current | .[].major) )
| select( .major as $major
| (.minor | tonumber) > ($current[] | select(.major == $major) | .minor | tonumber)
)
] | group_by(.major) | [ .[] | max_by(.minor) | (.major + "." + .minor) ]' | jq -R -c '{versions : . }')
echo "new releases : $new_releases"
versions="[$CURRENT_VERSION]"
if [[ $new_releases != "[]" ]]; then
if [[ -z "$CURRENT_VERSION" ]]; then
versions="[$new_releases]"
else
versions="[$CURRENT_VERSION,$new_releases]"
fi
fi
#echo "VERSIONS ARE: $versions"
#echo "[ $new_releases ]" >&3
echo $versions >&3