Improve tools setup

Log full semver of tools installed with composer

Refactor adding paths to PATH
This commit is contained in:
Shivam Mathur
2022-01-11 06:04:19 +05:30
parent b7cdb2373c
commit f3010adf3e
5 changed files with 90 additions and 55 deletions

View File

@ -60,6 +60,34 @@ get() {
fi
}
# Function to get shell profile.
get_shell_profile() {
case "$SHELL" in
*bash*)
echo "${HOME}/.bashrc"
;;
*zsh*)
echo "${HOME}/.zshrc"
;;
*)
echo "${HOME}/.profile"
;;
esac
}
# Function to add a path to the PATH variable.
add_path() {
path_to_add=$1
[ ! -d "$path_to_add" ] && [[ ":$PATH:" == *":$path_to_add:"* ]] && return
if [[ -n "$GITHUB_PATH" ]]; then
echo "$path_to_add" | tee -a "$GITHUB_PATH" >/dev/null 2>&1
else
profile=$(get_shell_profile)
([ -e "$profile" ] && grep -q ":$path_to_add\"" "$profile" 2>/dev/null) || echo "export PATH=\"\${PATH:+\${PATH}:}\"$path_to_add" | sudo tee -a "$profile" >/dev/null 2>&1
fi
export PATH="${PATH:+${PATH}:}$path_to_add"
}
# Function to download and run scripts from GitHub releases with jsdeliver fallback.
run_script() {
repo=$1