1
0
Fork 0
mirror of synced 2024-11-15 22:18:58 -05:00
tpm/scripts/install_plugins.sh

115 lines
3 KiB
Bash
Raw Normal View History

2014-05-18 18:35:55 -04:00
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/shared_functions.sh"
clone() {
2015-05-27 15:56:30 -04:00
local plugin; plugin="$1"
cd "$SHARED_TPM_PATH" &&
2015-02-08 09:38:55 -05:00
GIT_TERMINAL_PROMPT=0 git clone --recursive $plugin
2014-05-18 18:35:55 -04:00
}
2015-05-27 15:56:30 -04:00
install_plugin_git() {
local plugin; plugin="$1"
local branch; branch=":${1##*:}"
plugin="${1%$branch}"
clone "$plugin" ||
clone "git:$plugin"
if [ "${branch}" != ":${1}" ]; then #if exists branch/revision
(cd "$SHARED_TPM_PATH"/$(shared_plugin_name "$plugin") &&
git checkout -q "${branch#:}" 2>&1 >/dev/null)
fi
}
2014-05-18 18:35:55 -04:00
# tries cloning:
# 1. plugin name directly - works if it's a valid git url
# 2. expands the plugin name to point to a github repo and tries cloning again
2015-05-27 15:56:30 -04:00
install_plugin_github() {
local plugin; plugin="$1"
local branch; branch=":${1##*:}"
plugin="${1%$branch}"
2014-05-24 17:15:13 -04:00
clone "$plugin" ||
clone "https://git::@github.com/$plugin"
2015-05-27 15:56:30 -04:00
if [ "${branch}" != ":${1}" ]; then #if exists branch/revision
(cd "$SHARED_TPM_PATH"/$(shared_plugin_name "$plugin") &&
git checkout -q "${branch#:}" 2>&1 >/dev/null)
fi
}
install_plugin_web() {
local plugin; plugin="$1"
local plugin_name; plugin_name="$(shared_plugin_name "$plugin")"
(cd "$SHARED_TPM_PATH" && mkdir "${plugin_name}" &&
cd "${plugin_name}" && (wget --no-check-certificate "${plugin}" ||
curl -k -s -O "${plugin}"))
}
install_plugin_local() {
local plugin; plugin="$1"
local plugin_name; plugin_name="$(shared_plugin_name "$plugin")"
(cd "$SHARED_TPM_PATH" && mkdir "${plugin_name}" &&
cd "${plugin_name}" && cp -r "${plugin}" .)
2014-05-18 18:35:55 -04:00
}
# pull new changes or clone plugin
2014-08-05 12:15:07 -04:00
install_plugin() {
2015-05-27 15:56:30 -04:00
local plugin; plugin="$1"
local plugin_name; plugin_name="$(shared_plugin_name "$plugin")"
2014-08-05 14:50:47 -04:00
if plugin_already_installed "$plugin"; then
# plugin is already installed
2014-08-05 14:50:47 -04:00
echo_message "Already installed \"$plugin_name\""
2014-05-24 17:15:13 -04:00
else
2014-08-05 14:50:47 -04:00
echo_message "Installing \"$plugin_name\""
2015-05-27 15:56:30 -04:00
local handler; handler="${1%%:*}:"
plugin="${1#$handler}"
case "${handler}" in
''|*/*) case "${1}" in
/*|~*|\$*) install_plugin_local "${1}" ;;
*) install_plugin_github "${1}" ;;
esac ;;
gh*|github*|git@github.com*) install_plugin_github "${plugin}" ;;
git:) install_plugin_git "${plugin}" ;;
file:) install_plugin_local "${plugin#//}" ;;
http:|ftp:) install_plugin_web "${1}" ;;
https:)
case "${1}" in
*github.com/*) install_plugin_github "${plugin#//github.com/}";;
*) install_plugin_web "${1}";;
esac ;;
*) set_false ;;
esac
[ X"${?}" = X"0" ] &&
2014-08-05 14:50:47 -04:00
echo_message " \"$plugin_name\" download success" ||
echo_message " \"$plugin_name\" download fail"
2014-05-24 17:15:13 -04:00
fi
2014-05-18 18:35:55 -04:00
}
2014-08-05 12:15:07 -04:00
install_plugins() {
2014-05-24 17:15:13 -04:00
local plugins=$(shared_get_tpm_plugins_list)
for plugin in $plugins; do
2014-08-05 12:15:07 -04:00
install_plugin "$plugin"
2014-05-24 17:15:13 -04:00
done
2014-05-18 18:35:55 -04:00
}
ensure_tpm_path_exists() {
2014-05-24 17:15:13 -04:00
mkdir -p $SHARED_TPM_PATH
}
2014-05-18 18:35:55 -04:00
reload_tmux_environment() {
2014-05-24 17:15:13 -04:00
tmux source-file ~/.tmux.conf >/dev/null 2>&1
2014-05-18 18:35:55 -04:00
}
main() {
2014-05-24 17:15:13 -04:00
reload_tmux_environment
shared_set_tpm_path_constant
ensure_tpm_path_exists
2014-08-05 12:15:07 -04:00
install_plugins
2014-05-24 17:15:13 -04:00
reload_tmux_environment
end_message
2014-05-18 18:35:55 -04:00
}
main