Skip to content

Instantly share code, notes, and snippets.

@drhuffman12
Last active September 9, 2016 17:56
Show Gist options
  • Save drhuffman12/f75f3bf41eceeada94655bc0d29df2b3 to your computer and use it in GitHub Desktop.
Save drhuffman12/f75f3bf41eceeada94655bc0d29df2b3 to your computer and use it in GitHub Desktop.
Helper script to create a Ruby app folder (w/ a '.versions.conf' file) and configure RVM
#!/usr/bin/env bash
me="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"
# echo $me
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]
then
echo
echo 'To create a Ruby app folder and configure it for RVM usage, use the following syntax:'
echo
echo ' bash --login './$me 'PROJ_ROOT PROJ_NAME PROJ_RUBY_VER PROJ_GEMSET_NAME'
echo
echo 'This will also:'
echo ' * Create a ".versions.conf" RVM config file w/ the specified Ruby version and gemset name'
echo ' * Install the specified version of Ruby (if not yet installed)'
echo ' * Switch to the specified Ruby version'
echo ' * Install bundler gem in the global gemset (if not yet installed)'
echo ' * Create a gemset for the specified gemset name'
echo ' * Switch to the specified gemset'
echo
echo 'See "https://rvm.io/workflow/projects" for more RVM config info.'
echo
else
PROJ_ROOT=$1
PROJ_NAME=$2
PROJ_RUBY_VER=$3
PROJ_GEMSET_NAME=$4
PROJ_PATH=$PROJ_ROOT/$PROJ_NAME
PROG_RV_GN=$PROJ_RUBY_VER@$PROJ_GEMSET_NAME
echo 'Adding path:' $PROJ_PATH
mkdir -p $PROJ_PATH
cd $PROJ_PATH
PROJ_FULL_PATH=$pwd
echo 'Adding Bundler to:' $PROJ_RUBY_VER@global
rm .versions.conf
rvm --create --versions-conf $PROJ_RUBY_VER@global
cd ..
cd $PROJ_FULL_PATH
# $rvm_recommended_ruby # broken?
# See "https://github.com/rvm/rvm/issues/3158"
rvm install $PROJ_RUBY_VER
rvm use $PROJ_RUBY_VER
rvm gemset use global
gem install bundler
echo 'Adding gemset:' $PROG_RV_GN
rm .versions.conf
rvm --create --versions-conf $PROG_RV_GN
cd ..
cd $PROJ_FULL_PATH
touch Gemfile
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment