-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_asdf.bash
91 lines (77 loc) · 3.8 KB
/
install_asdf.bash
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
#!/bin/bash
###
# Script installs asdf.
#
# Execute:
# DEBUG=1 VERSION=0.14.0 INSTALL_DIR=tmp-here ./src/scripts/gen/install_asdf.bash
###
# Path Initialization
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P || exit 1)"
ROOT_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd -P || exit 1)"
# Library Sourcing
SHELLPACK_DEPS_DIR="${SHELLPACK_DEPS_DIR:-"${ROOT_DIR}/.shellpack_deps"}"
SHELL_GR_DIR="${SHELL_GR_DIR:-"${SHELLPACK_DEPS_DIR}/@github/rynkowsg/shell-gr@81b70c3da598456200d9c63fda779a04012ff256"}"
########################################################################################################################
## common library (shared)
########################################################################################################################
# shellcheck source=.shellpack_deps/@github/rynkowsg/shell-gr@81b70c3da598456200d9c63fda779a04012ff256/lib/color.bash
source "${SHELL_GR_DIR}/lib/color.bash"
# shellcheck source=.shellpack_deps/@github/rynkowsg/shell-gr@81b70c3da598456200d9c63fda779a04012ff256/lib/fs.bash
source "${SHELL_GR_DIR}/lib/fs.bash" # normalized_path
########################################################################################################################
## asdf-orb-specific
########################################################################################################################
# in this section I we can convert orb input to the script intput
DEBUG=${PARAM_DEBUG:-${DEBUG:-0}}
if [ "${DEBUG}" = 1 ]; then
set -x
fi
VERSION="${PARAM_VERSION:-${VERSION:-}}"
INSTALL_DIR="$(normalized_path "${PARAM_INSTALL_DIR:-${INSTALL_DIR:-}}")"
# shellcheck source=src/scripts/internal/asdf_orb_common_start.bash
source "${SCRIPT_DIR}/internal/asdf_orb_common_start.bash"
# shellcheck source=src/scripts/internal/asdf_orb_common_input.bash
source "${SCRIPT_DIR}/internal/asdf_orb_common_input.bash"
########################################################################################################################
## asdf-specific (shared)
########################################################################################################################
# shellcheck source=src/scripts/internal/asdf_common.bash
source "${SCRIPT_DIR}/internal/asdf_common.bash"
########################################################################################################################
## asdf-orb-specific
########################################################################################################################
# $1 - install_dir
ci_post_asdf_install() {
if [ "${CIRCLECI}" = "true" ]; then
local install_dir="${1}"
asdf_validate_install_dir "${install_dir}"
# needed for following jobs
echo ". ${install_dir}/asdf.sh" >>"${BASH_ENV}"
# needed when we SSH to machine for debugging
echo ". ${install_dir}/asdf.sh" >>~/.bashrc
fi
}
main() {
local version install_dir
version="${VERSION}"
install_dir="$(asdf_determine_install_dir "${INSTALL_DIR}")"
if ! asdf_is_installed; then
printf "${YELLOW}%s${NC}\n" "${NAME} is not yet installed."
asdf_install "${version}" "${install_dir}"
ci_post_asdf_install "${install_dir}"
elif ! asdf_is_version "${version}"; then
printf "${YELLOW}%s${NC}\n" "The installed version of ${NAME} ($(asdf_version)) is different then expected (${version})."
asdf_install "${version}" "${install_dir}"
ci_post_asdf_install "${install_dir}"
else
printf "${YELLOW}%s${NC}\n" "${NAME} is already installed in $(which "${CMD_NAME}")."
fi
}
# shellcheck disable=SC2199
# to disable warning about concatenation of BASH_SOURCE[@]
# It is not a problem. This part pf condition is only to prevent `unbound variable` error.
if [[ -n "${BASH_SOURCE[@]}" && "${BASH_SOURCE[0]}" != "${0}" ]]; then
[[ -n "${BASH_SOURCE[0]}" ]] && printf "%s\n" "Loaded: ${BASH_SOURCE[0]}"
else
main "$@"
fi