Last active
December 17, 2015 13:19
-
-
Save hunner/5616520 to your computer and use it in GitHub Desktop.
`vvagrant` command which reads an environment variable `$VAGRANT_VERSION` (or command argument) to determine which version of vagrant to use. Useful for having both 1.0.x and 1.2.x installed at the same time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Make a directory like this for each version you want | |
| vv% ls -l ~/local/share/rbenv/gemsets | |
| total 0 | |
| drwxr-xr-x 8 hunner staff 272 Apr 22 15:06 vagrant_1.0.7/ | |
| drwxr-xr-x 8 hunner staff 272 Apr 22 15:12 vagrant_1.2.2/ | |
| ## Put this in vagrant_*/Gemfile | |
| vv% cat vagrant_1.2.1/Gemfile | |
| source 'https://rubygems.org' | |
| gem 'vagrant', :path => File.expand_path('vagrant', File.dirname(__FILE__)) | |
| ## Clone the vagrant repo for each version you want and install gemsets | |
| vv% git clone https://github.com/mitchellh/vagrant.git ~/local/share/rbenv/gemsets/vagrant_1.2.2/vagrant | |
| vv% cd !$ | |
| vv% git checkout v1.2.2 | |
| vv% bundle update | |
| ## Use `vvagrant` (see script below) | |
| vv% vvagrant 1.2.2 box list | |
| CentOS-6.4-x86_64-v20130309 (virtualbox) | |
| centos-6.3-x86_64-minimal-pe2.7.2 (virtualbox) | |
| debian-70rc1-x64-vbox4210 (virtualbox) | |
| vv% export VAGRANT_VERSION=1.0.7 | |
| vv% vvagrant box list | |
| CentOS-6.4-x86_64-v20130309 | |
| centos-6.3-x86_64-minimal-pe2.7.2 | |
| centos-64-x64-vbox4210 | |
| debian-607-x64-vbox4210 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| if [[ $1 =~ [0-9]\.[0-9]\.[0-9] ]] ; then | |
| vversion=$1 | |
| vargs=${@:2} | |
| elif [[ ! -z $VAGRANT_VERSION ]] ; then | |
| vversion=$VAGRANT_VERSION | |
| vargs=$@ | |
| else | |
| echo "$0: version argument missing" | |
| exit 1 | |
| fi | |
| gem_bin='vagrant' | |
| gemset="vagrant_${vversion}" | |
| gemset_root="${HOME}/local/share/rbenv/gemsets/${gemset}" | |
| gem_path="${gemset_root}/vagrant/bin/${gem_bin}" | |
| gemfile="${gemset_root}/Gemfile" | |
| if [ -e "$gem_path" ]; then | |
| export VAGRANT_HOME="${gemset_root}/vagrant.d" | |
| export VAGRANT_INSTALLER_ENV=bugmenot #disable warning message | |
| export BUNDLE_GEMFILE="$gemfile" | |
| exec bundle exec "${gem_path}" $vargs | |
| else | |
| echo "Unable to execute $0; backing executable '${gem_path}' missing or not executable" >&2 | |
| exit 255 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment