forked from palantir/bouncer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbouncerw
executable file
·59 lines (51 loc) · 1.72 KB
/
bouncerw
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
#!/usr/bin/env bash
# If your TF env has multiple simultaneous bouncer invocations, you're in a race condition
# for downloading the binary, so that's why we handle a lockfile
lockfile='.bouncer_download_lock'
fd='200'
lock_timeout='30'
lock() {
echo "Attempting to lock ${lockfile}"
eval "exec ${fd}>${lockfile}"
if flock -w ${lock_timeout} ${fd}; then
echo "Lock acquired"
return 0
else
echo "Timed-out waiting for lock"
return 1
fi
}
unlock() {
echo "Releasing lock on ${lockfile}"
if flock -u ${fd}; then
echo "Lock released"
return 0
else
echo "Error releasing log"
return 1
fi
}
download() {
if [ "${BOUNCER_VERSION}" == "" ]; then
echo "BOUNCER_VERSION is not set. Looking for the latest bouncer release..."
# Terraform Enterprise environment doesn't have jq, replace with this once it does:
# export BOUNCER_VERSION=$(curl -s "https://api.bintray.com/packages/palantir/releases/bouncer" | jq -r '.latest_version')
BOUNCER_VERSION=$(curl -s https://api.github.com/repos/palantir/bouncer/releases/latest | jq | grep "tag_name" | sed 's/.\(.*\)/\1/' | sed 's/\(.*\)./\1/' | tr -d '"' | sed "s/.*v//")
export BOUNCER_VERSION
fi
# Strip a leading 'v' if someone adds one, or one winds-up there somehow
BOUNCER_VERSION="${BOUNCER_VERSION//v}"
export BOUNCER_VERSION
echo "Installing bouncer version ${BOUNCER_VERSION}"
wget -q -O bouncer.tgz "https://github.com/palantir/bouncer/releases/download/v${BOUNCER_VERSION}/bouncer-${BOUNCER_VERSION}-linux-amd64.tgz"
tar -xzf bouncer.tgz
chmod 755 ./bouncer
}
lock || exit 1
if [ ! -f ./bouncer ]; then
download || exit 1
else
echo "Bouncer already installed, using local copy"
fi
unlock || exit 1
./bouncer "$@"