-
Notifications
You must be signed in to change notification settings - Fork 148
/
install_vault.sh
executable file
·166 lines (137 loc) · 3.42 KB
/
install_vault.sh
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env bash
###########################################################################
# Download and Install Vault #
# This script is prepared for caching of the download directory #
###########################################################################
set -o errexit
EDITION="${EDITION:-oss}"
VAULT_OSS="${VAULT_OSS:-1.11.0}"
VAULT_ENT="${VAULT_ENT:-1.11.0}"
UNAME=$(uname -s | tr '[:upper:]' '[:lower:]')
VERBOSE=false
VAULT_DIRECTORY=vault
DOWNLOAD_DIRECTORY=download
PLATFORM=amd64
readonly script_name="$(basename "${BASH_SOURCE[0]}")"
function say() {
echo "$@"
}
function verbose() {
if [[ ${VERBOSE} == true ]]; then
echo "$@"
fi
}
function initialize() {
# cleanup
mkdir -p ${VAULT_DIRECTORY}
mkdir -p ${DOWNLOAD_DIRECTORY}
}
function usage() {
cat <<EOF
Usage: ${script_name} [OPTION]...
Download and extract HashiCorp Vault
Options:
-h|--help Displays this help
-v|--version Vault version number
-e|--edition oss|enterprise Vault Edition
EOF
}
function parse_options() {
local option
while [[ $# -gt 0 ]]; do
option="$1"
shift
case ${option} in
-h | -H | --help)
usage
exit 0
;;
--verbose)
VERBOSE=true
;;
-v | --version)
VAULT_VER="$1"
verbose "VAULT_VER=${VAULT_VER}"
shift
;;
-e | --edition)
EDITION="$1"
verbose "EDITION=${EDITION}"
shift
;;
*)
script_exit "Invalid argument was provided: ${option}" 2
;;
esac
done
}
function unpack() {
cd ${VAULT_DIRECTORY}
if [[ -f vault ]]; then
rm vault
fi
say "Unzipping ${VAULT_FILE}..."
verbose " unzip ../${DOWNLOAD_DIRECTORY}/${VAULT_FILE}"
if [[ ${VERBOSE} == true ]]; then
unzip "../${DOWNLOAD_DIRECTORY}/${VAULT_FILE}"
else
unzip -q "../${DOWNLOAD_DIRECTORY}/${VAULT_FILE}"
fi
chmod a+x vault
# check
./vault --version
cd ..
}
function download() {
if [[ ! -f "${DOWNLOAD_DIRECTORY}/${VAULT_FILE}" ]]; then
cd ${DOWNLOAD_DIRECTORY}
# install Vault
say "Downloading Vault from ${VAULT_URL}"
verbose "wget ${VAULT_URL} -O ${VAULT_FILE}"
if [[ ${VERBOSE} == true ]]; then
wget "${VAULT_URL}" -O "${VAULT_FILE}"
else
wget "${VAULT_URL}" -q -O "${VAULT_FILE}"
fi
if [[ $? != 0 ]]; then
echo "Cannot download Vault"
exit 1
fi
cd ..
fi
}
function download_oss() {
VAULT_VER="${VAULT_VER:-${VAULT_OSS}}"
VAULT_ZIP="vault_${VAULT_VER}_${UNAME}_${PLATFORM}.zip"
VAULT_FILE=${VAULT_ZIP}
VAULT_URL="https://releases.hashicorp.com/vault/${VAULT_VER}/${VAULT_ZIP}"
download
unpack
}
function download_enterprise() {
VAULT_VER="${VAULT_VER:-${VAULT_ENT}}"
VAULT_ZIP="vault-enterprise_${VAULT_VER}%2Bent_${UNAME}_${PLATFORM}.zip"
VAULT_FILE="vault-enterprise_${VAULT_VER}+ent_${UNAME}_${PLATFORM}.zip"
VAULT_URL="http://hc-enterprise-binaries.s3.amazonaws.com/vault/ent/${VAULT_VER}/${VAULT_ZIP}"
download
unpack
}
function main() {
initialize
parse_options "$@"
if [ "$(uname -m)" == aarch64 ]; then
PLATFORM=arm64
fi
if [ "$(uname -m)" == arm64 ]; then
PLATFORM=arm64
fi
if [[ ${EDITION} == 'oss' ]]; then
download_oss
elif [[ ${EDITION} == 'enterprise' ]]; then
download_enterprise
else
say "Ignoring edition option: ${EDITION} - oss and enterprise supported only"
exit 1
fi
}
main "$@"