-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathinstall.sh
executable file
·63 lines (49 loc) · 2 KB
/
install.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
#!/usr/bin/env bash
set -o nounset -o pipefail -o errexit
github_last_release() {
if [[ ${#} -ne 1 ]]; then
printf "%bUsage: github_last_release owner/repo%b\n" "${RED}" "${RESET}"
return 1
fi
local RED="\033[31m"
local RESET="\033[0m"
local HTTP_OUTPUT="http_output.txt"
local CLIENT_ARGS=("curl" "-q" "-sSL" "--max-time" "30" "-o" "${HTTP_OUTPUT}" "-w" "%{http_code}")
if [[ -n ${GITHUB_OAUTH_TOKEN:-} ]]; then
CLIENT_ARGS+=("-H" "Authorization: token ${GITHUB_OAUTH_TOKEN}")
fi
local LATEST_RELEASE
LATEST_RELEASE="$("${CLIENT_ARGS[@]}" "https://api.github.com/repos/${1}/releases/latest")"
if [[ ${LATEST_RELEASE} != "200" ]]; then
printf "%bUnable to list latest release for %s%b\n" "${RED}" "${1}" "${RESET}"
cat "${HTTP_OUTPUT}" && rm "${HTTP_OUTPUT}"
return
fi
python -c "import json; print(json.load(open('${HTTP_OUTPUT}'))['tag_name'])"
rm "${HTTP_OUTPUT}"
}
main() {
local BLUE="\033[34m"
local RESET="\033[0m"
local PLUGIN_VERSION
PLUGIN_VERSION="$(github_last_release MeilleursAgents/terraform-provider-ansiblevault)"
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m | tr '[:upper:]' '[:lower:]')
if [[ ${ARCH} == "x86_64" ]]; then
ARCH="amd64"
fi
local PLUGIN_DIR="${HOME}/.terraform.d/plugins/${OS}_${ARCH}/"
local TARGET_NAME="terraform-provider-ansiblevault_${PLUGIN_VERSION}"
local ARCHIVE_PATH="terraform-provider-ansiblevault_${PLUGIN_VERSION#v}_${OS}_${ARCH}.zip"
printf "%bInstalling terraform-provider-ansiblevault version %s into %s%b\n" "${BLUE}" "${PLUGIN_VERSION}" "${PLUGIN_DIR}" "${RESET}"
mkdir -p "${PLUGIN_DIR}"
(
cd "${PLUGIN_DIR}" || return
curl -q -sSL -O "https://github.com/MeilleursAgents/terraform-provider-ansiblevault/releases/download/${PLUGIN_VERSION}/${ARCHIVE_PATH}"
unzip "${ARCHIVE_PATH}" -d "${TARGET_NAME}_content"
mv "${TARGET_NAME}_content/${TARGET_NAME}" "${TARGET_NAME}"
rm -rf "${ARCHIVE_PATH}" "${TARGET_NAME}_content"
chmod +x "${TARGET_NAME}"
)
}
main