-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatest
executable file
·51 lines (43 loc) · 1.33 KB
/
latest
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
#!/bin/bash
set -eu
#
# latest - Retrieve the latest version available,
# based on a variety of heuristics.
#
# USAGE: latest PACKAGE
#
# i.e.: latest safe
# latest cf
#
if [[ -z "${1:-}" ]]; then
echo >&2 "USAGE: $0 PACKAGE"
exit 1
fi
from_github() {
curl -sL https://api.github.com/repos/$1/releases/latest | jq -r .tag_name | sed -e 's/^v//'
}
from_hashicorp() {
curl -sL https://releases.hashicorp.com/$1/ | grep 'a href="/'$1 | grep -v '[+-]' | head -n1 | sed -e 's/ *<[^>]*>//g;s/^'$1'_//'
}
case $1 in
cf)
curl -v https://packages.cloudfoundry.org/stable?release=debian64 2>&1 | \
grep Location | sed -e 's@.*/releases/v@@;s@/.*@@'
;;
bbr) from_github cloudfoundry-incubator/bosh-backup-and-restore ;;
bosh) from_github cloudfoundry/bosh-cli ;;
credhub) from_github cloudfoundry-incubator/credhub-cli ;;
fly) from_github concourse/concourse ;;
genesis) from_github genesis-community/$1 ;;
jq) from_github stedolan/$1 | sed -e 's/^jq-//' ;;
kubectl) from_github kubernetes/kubernetes ;;
s3|osb|boss) from_github jhunt/$1 ;;
safe|gotcha) from_github starkandwayne/$1 ;;
shield) from_github shieldproject/$1 ;;
spruce) from_github geofffranks/$1 ;;
vault|terraform) from_hashicorp $1 ;;
*)
echo >&2 "$0: unrecognized package name '$1'!"
exit 1
;;
esac