2019-11-27 01:24:29 -07:00
|
|
|
# -*- sh -*-
|
|
|
|
|
2017-07-30 11:02:19 -07:00
|
|
|
handle_failure() {
|
|
|
|
local install_path="$1"
|
|
|
|
rm -rf "$install_path"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
handle_cancel() {
|
|
|
|
local install_path="$1"
|
2017-12-27 07:54:00 -07:00
|
|
|
echo -e "\\nreceived sigint, cleaning up"
|
2017-07-30 11:02:19 -07:00
|
|
|
handle_failure "$install_path"
|
|
|
|
}
|
|
|
|
|
2015-05-17 01:49:28 -07:00
|
|
|
install_command() {
|
2015-05-21 22:28:18 -07:00
|
|
|
local plugin_name=$1
|
2015-05-17 00:46:56 -07:00
|
|
|
local full_version=$2
|
2015-06-24 08:11:13 -07:00
|
|
|
|
|
|
|
if [ "$plugin_name" = "" ] && [ "$full_version" = "" ]; then
|
|
|
|
install_local_tool_versions
|
2016-12-18 10:52:23 -07:00
|
|
|
elif [[ $# -eq 1 ]]; then
|
|
|
|
display_error "You must specify a name and a version to install"
|
|
|
|
exit 1
|
2015-06-24 08:11:13 -07:00
|
|
|
else
|
2017-09-04 10:04:56 -07:00
|
|
|
install_tool_version "$plugin_name" "$full_version"
|
2015-06-24 08:11:13 -07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-06-28 20:56:33 -07:00
|
|
|
get_concurrency() {
|
2019-11-29 09:15:38 -07:00
|
|
|
if command -v nproc >/dev/null 2>&1; then
|
2017-09-04 10:04:56 -07:00
|
|
|
nproc
|
2019-11-29 09:15:38 -07:00
|
|
|
elif command -v sysctl >/dev/null 2>&1 && sysctl hw.ncpu >/dev/null 2>&1; then
|
2017-09-04 10:04:56 -07:00
|
|
|
sysctl -n hw.ncpu
|
2016-06-28 20:56:33 -07:00
|
|
|
elif [ -f /proc/cpuinfo ]; then
|
2017-09-04 10:04:56 -07:00
|
|
|
grep -c processor /proc/cpuinfo
|
2016-06-28 20:56:33 -07:00
|
|
|
else
|
|
|
|
echo "1"
|
|
|
|
fi
|
|
|
|
}
|
2015-06-24 08:11:13 -07:00
|
|
|
|
|
|
|
install_local_tool_versions() {
|
2019-05-30 22:32:12 -07:00
|
|
|
local plugins_path
|
|
|
|
plugins_path=$(get_plugin_path)
|
2015-06-24 08:11:13 -07:00
|
|
|
|
2019-05-30 22:32:12 -07:00
|
|
|
local search_path
|
|
|
|
search_path=$(pwd)
|
|
|
|
|
|
|
|
local some_tools_installed
|
|
|
|
|
2019-11-29 09:15:38 -07:00
|
|
|
if ls "$plugins_path" &>/dev/null; then
|
|
|
|
for plugin_path in "$plugins_path"/*; do
|
2019-05-30 22:32:12 -07:00
|
|
|
local plugin_name
|
|
|
|
plugin_name=$(basename "$plugin_path")
|
|
|
|
|
|
|
|
local plugin_version_and_path
|
2019-10-22 16:03:05 -07:00
|
|
|
plugin_version_and_path="$(find_versions "$plugin_name" "$search_path")"
|
2019-05-30 22:32:12 -07:00
|
|
|
|
|
|
|
if [ -n "$plugin_version_and_path" ]; then
|
|
|
|
local plugin_version
|
2019-06-17 17:38:17 -07:00
|
|
|
some_tools_installed='yes'
|
2019-11-29 09:15:38 -07:00
|
|
|
plugin_versions=$(cut -d '|' -f 1 <<<"$plugin_version_and_path")
|
2019-10-22 15:58:30 -07:00
|
|
|
for plugin_version in $plugin_versions; do
|
|
|
|
install_tool_version "$plugin_name" "$plugin_version"
|
|
|
|
done
|
2016-01-16 19:30:53 -07:00
|
|
|
fi
|
2019-05-30 22:32:12 -07:00
|
|
|
done
|
2015-06-24 08:11:13 -07:00
|
|
|
else
|
2019-05-30 22:32:12 -07:00
|
|
|
echo "Install plugins first to be able to install tools"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$some_tools_installed" ]; then
|
2015-06-24 08:11:13 -07:00
|
|
|
echo "Either specify a tool & version in the command"
|
|
|
|
echo "OR add .tool-versions file in this directory"
|
2017-10-10 10:02:42 -07:00
|
|
|
echo "or in a parent directory"
|
2015-06-24 08:11:13 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
install_tool_version() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local full_version=$2
|
2017-09-04 10:04:56 -07:00
|
|
|
local plugin_path
|
|
|
|
plugin_path=$(get_plugin_path "$plugin_name")
|
|
|
|
check_if_plugin_exists "$plugin_name"
|
2015-05-07 22:58:07 -07:00
|
|
|
|
2018-10-07 11:35:36 -07:00
|
|
|
if [ "$full_version" = "system" ]; then
|
|
|
|
return
|
|
|
|
fi
|
2015-06-24 08:11:13 -07:00
|
|
|
|
2019-11-29 09:15:38 -07:00
|
|
|
IFS=':' read -r -a version_info <<<"$full_version"
|
2015-05-21 21:47:27 -07:00
|
|
|
if [ "${version_info[0]}" = "ref" ]; then
|
2015-05-17 00:46:56 -07:00
|
|
|
local install_type="${version_info[0]}"
|
|
|
|
local version="${version_info[1]}"
|
|
|
|
else
|
|
|
|
local install_type="version"
|
2019-11-22 11:37:53 -07:00
|
|
|
|
|
|
|
if [ "${version_info[0]}" = "latest" ]; then
|
2019-11-22 11:37:53 -07:00
|
|
|
local version
|
2019-11-27 01:24:29 -07:00
|
|
|
version=$(asdf latest "$plugin_name" "${version_info[1]}")
|
2019-11-22 11:37:53 -07:00
|
|
|
full_version=$version
|
|
|
|
else
|
|
|
|
local version="${version_info[0]}"
|
|
|
|
fi
|
2015-05-17 00:46:56 -07:00
|
|
|
fi
|
2015-05-07 22:58:07 -07:00
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
local install_path
|
|
|
|
install_path=$(get_install_path "$plugin_name" "$install_type" "$version")
|
|
|
|
local concurrency
|
|
|
|
concurrency=$(get_concurrency)
|
2017-07-30 11:02:19 -07:00
|
|
|
trap 'handle_cancel $install_path' INT
|
|
|
|
|
|
|
|
if [ -d "$install_path" ]; then
|
2015-05-21 22:28:18 -07:00
|
|
|
echo "$plugin_name $full_version is already installed"
|
2015-05-21 22:17:44 -07:00
|
|
|
else
|
2015-06-24 08:11:13 -07:00
|
|
|
(
|
|
|
|
export ASDF_INSTALL_TYPE=$install_type
|
|
|
|
export ASDF_INSTALL_VERSION=$version
|
|
|
|
export ASDF_INSTALL_PATH=$install_path
|
2016-06-28 20:56:33 -07:00
|
|
|
export ASDF_CONCURRENCY=$concurrency
|
2017-07-30 11:02:19 -07:00
|
|
|
mkdir "$install_path"
|
2019-01-19 12:16:13 -07:00
|
|
|
asdf_run_hook "pre_asdf_install_${plugin_name}" "$full_version"
|
2017-07-30 11:02:19 -07:00
|
|
|
bash "${plugin_path}"/bin/install
|
2015-06-24 08:11:13 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
local exit_code=$?
|
|
|
|
if [ $exit_code -eq 0 ]; then
|
2019-11-27 01:24:29 -07:00
|
|
|
asdf reshim "$plugin_name" "$full_version"
|
2019-01-19 12:00:33 -07:00
|
|
|
asdf_run_hook "post_asdf_install_${plugin_name}" "$full_version"
|
2015-06-24 08:11:13 -07:00
|
|
|
else
|
2017-07-30 11:15:21 -07:00
|
|
|
handle_failure "$install_path"
|
2015-06-24 08:11:13 -07:00
|
|
|
fi
|
2015-05-21 22:17:44 -07:00
|
|
|
fi
|
2015-05-17 00:46:56 -07:00
|
|
|
}
|
2019-11-27 01:24:29 -07:00
|
|
|
|
|
|
|
install_command "$@"
|