asdf/lib/commands/reshim.sh

119 lines
3.3 KiB
Bash
Raw Normal View History

2015-05-24 02:32:38 -07:00
shim_command() {
local plugin_name=$1
2015-05-24 02:42:30 -07:00
local executable_path=$2
2015-05-24 02:32:38 -07:00
local plugin_path=$(get_plugin_path $plugin_name)
2015-05-17 11:20:51 -07:00
check_if_plugin_exists $plugin_path
2015-05-17 00:46:56 -07:00
ensure_shims_dir
2015-05-24 02:32:38 -07:00
generate_shim_for_executable $plugin_name $executable_path
}
2015-05-17 06:32:47 -07:00
2015-05-24 02:32:38 -07:00
reshim_command() {
local plugin_name=$1
local full_version=$2
local plugin_path=$(get_plugin_path $plugin_name)
check_if_plugin_exists $plugin_path
ensure_shims_dir
2015-05-17 06:32:47 -07:00
2015-05-24 02:32:38 -07:00
if [ "$full_version" != "" ]; then
# generate for the whole package version
generate_shims_for_version $plugin_name $full_version
2015-05-17 06:32:47 -07:00
else
# generate for all versions of the package
2015-05-29 09:24:31 -07:00
local plugin_installs_path=$(asdf_dir)/installs/${plugin_name}
2015-05-17 06:32:47 -07:00
2015-05-29 09:24:31 -07:00
for install in ${plugin_installs_path}/*/; do
2015-05-21 21:49:39 -07:00
local full_version_name=$(echo $(basename $install) | sed 's/ref\-/ref\:/')
2015-05-24 02:32:38 -07:00
generate_shims_for_version $plugin_name $full_version_name
2015-05-17 00:46:56 -07:00
done
fi
}
2015-05-10 10:25:42 -07:00
2015-05-11 09:43:24 -07:00
ensure_shims_dir() {
# Create shims dir if doesn't exist
2015-05-17 03:47:45 -07:00
if [ ! -d $(asdf_dir)/shims ]; then
2015-05-11 09:43:24 -07:00
mkdir $(asdf_dir)/shims
fi
}
2015-05-10 10:25:42 -07:00
2015-05-11 09:43:24 -07:00
write_shim_script() {
2015-05-24 02:32:38 -07:00
local plugin_name=$1
2015-05-24 02:42:30 -07:00
local executable_path=$2
local executable_name=$(basename $executable_path)
local plugin_shims_path=$(get_plugin_path $plugin_name)/shims
local shim_path=$(asdf_dir)/shims/$executable_name
2015-05-11 09:43:24 -07:00
if [ -f $plugin_shims_path/$executable_name ]; then
cp $plugin_shims_path/$executable_name $shim_path
else
echo """#!/usr/bin/env bash
2015-10-01 10:31:53 -07:00
exec $(asdf_dir)/bin/private/asdf-exec ${plugin_name} ${executable_path} \"\$@\"
2015-05-11 09:43:24 -07:00
""" > $shim_path
fi
2015-05-11 09:43:24 -07:00
chmod +x $shim_path
}
2015-05-17 06:32:47 -07:00
generate_shim_for_executable() {
2015-05-24 02:32:38 -07:00
local plugin_name=$1
2015-05-24 02:42:30 -07:00
local executable=$2
2015-05-24 02:32:38 -07:00
local plugin_path=$(get_plugin_path $plugin_name)
2015-05-17 06:32:47 -07:00
2015-05-17 11:20:51 -07:00
check_if_plugin_exists $plugin_path
2015-05-17 06:32:47 -07:00
IFS=':' read -a version_info <<< "$full_version"
2015-05-21 21:47:27 -07:00
if [ "${version_info[0]}" = "ref" ]; then
2015-05-17 06:32:47 -07:00
local install_type="${version_info[0]}"
local version="${version_info[1]}"
else
local install_type="version"
local version="${version_info[0]}"
fi
2015-05-24 02:32:38 -07:00
write_shim_script $plugin_name $executable
2015-05-17 06:32:47 -07:00
}
2015-05-11 09:43:24 -07:00
generate_shims_for_version() {
local plugin_name=$1
2015-05-11 09:43:24 -07:00
local full_version=$2
local plugin_path=$(get_plugin_path $plugin_name)
2015-05-17 11:20:51 -07:00
check_if_plugin_exists $plugin_path
2015-05-10 10:25:42 -07:00
2015-05-11 09:43:24 -07:00
IFS=':' read -a version_info <<< "$full_version"
2015-05-21 21:47:27 -07:00
if [ "${version_info[0]}" = "ref" ]; then
2015-05-11 09:43:24 -07:00
local install_type="${version_info[0]}"
local version="${version_info[1]}"
else
local install_type="version"
local version="${version_info[0]}"
fi
2015-05-10 10:25:42 -07:00
local install_path=$(get_install_path $plugin_name $install_type $version)
2015-05-17 06:32:47 -07:00
2015-05-17 11:20:51 -07:00
if [ -f ${plugin_path}/bin/list-bin-paths ]; then
2015-05-21 22:17:44 -07:00
local space_seperated_list_of_bin_paths=$(
export ASDF_INSTALL_TYPE=$install_type
export ASDF_INSTALL_VERSION=$version
export ASDF_INSTALL_PATH=$install_path
bash ${plugin_path}/bin/list-bin-paths
)
else
local space_seperated_list_of_bin_paths="bin"
fi
2015-05-17 06:32:47 -07:00
IFS=' ' read -a all_bin_paths <<< "$space_seperated_list_of_bin_paths"
2015-05-11 09:43:24 -07:00
2015-05-17 06:32:47 -07:00
for bin_path in "${all_bin_paths[@]}"; do
#TODO check if it's actually an executable file
for executable_file in $install_path/$bin_path/*; do
2015-05-17 06:38:05 -07:00
# because just $executable_file gives absolute path; We don't want version hardcoded in shim
local executable_path_relative_to_install_path=$bin_path/$(basename $executable_file)
write_shim_script $plugin_name $executable_path_relative_to_install_path
2015-05-17 06:32:47 -07:00
done
2015-05-11 09:43:24 -07:00
done
}