Skip to content

Instantly share code, notes, and snippets.

@triplepoint
Created February 7, 2016 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triplepoint/00e5f015815a25c6f944 to your computer and use it in GitHub Desktop.
Save triplepoint/00e5f015815a25c6f944 to your computer and use it in GitHub Desktop.
Bash function to only install Vagrant plugins if they're not already installed.
# This would install vagrant-aws, if it's not already installed
# And do nothing if it was already installed.
vagrant_plugin_install vagrant-aws
# Don't reinstall Vagrant plugins, if they're already installed
# We can always call `vagrant plugin update` explicitly.
vagrant_plugin_install () {
set +v
installed_packages=$(vagrant plugin list | cut -f1 -d' ')
if ! [[ $installed_packages =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then
vagrant plugin install $1
else
echo $'\e[4m''Notice'$'\e[0m'": Vagrant plugin '$1' is already installed. Use 'vagrant plugin update $1' to force an upgrade."
fi
set -v
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment