diff --git a/setup.sh b/setup.sh index 79e41a3d779038a0aed4f8e51fb95794e857f84b..12de8b71a0b97a831aa89d1c8c89c013e5ec1f45 100644 --- a/setup.sh +++ b/setup.sh @@ -194,15 +194,49 @@ function manage_plugins() { clear mkdir -p Plugins cd Plugins - echo "Adding plugins..." - + echo "Adding/updating plugins..." for i in ${!plugins[@]} do + # Check if plugin is already present + repo_name_with_extension=${plugin_repositories[$i]##*/} + repo_name=${repo_name_with_extension%*.git} + path=$(git config -f .gitmodules --get "submodule.Plugins/${repo_name}.path") + if [ $? -ne 0 ] + then + plugin_present=true + else + plugin_present=false + fi + if [ -n "${plugin_branches[$i]}" ] then - echo "${plugins[$i]}" - git submodule add -b ${plugin_branches[$i]} ${plugin_repositories[$i]} + if [ "$plugin_present" == false ] + then + # Plugin was not yet added, call git submodule add + echo "Add new plugin: ${plugins[$i]}" + git submodule add -b ${plugin_branches[$i]} ${plugin_repositories[$i]} + else + # Updating existing plugin + echo "Update plugin: ${plugins[$i]}" + cd $repo_name + git fetch + git checkout ${plugin_branches[$i]} + git pull + cd .. + fi + else + if [ "$plugin_present" == true ] + then + # Remove plugin! + git submodule deinit -f "$repo_name" + git rm -f "$repo_name" + + git config -f ../.gitmodules --remove-section "submodule.Plugins/${repo_name}" + if [ -z "$(cat ../.gitmodules)" ]; then + git rm -f ../.gitmodules + fi + fi fi done cd ..