Skip to content

Instantly share code, notes, and snippets.

@overplumbum
Last active December 25, 2015 01:19
Show Gist options
  • Save overplumbum/6894178 to your computer and use it in GitHub Desktop.
Save overplumbum/6894178 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
## options
rvm_version=1.22.18
ruby_version=ruby-1.9.3-p448 # full qualified only
bundler_version=1.3.5
rvms_root=./rvms
## vars
rvm_dir=$rvms_root/rvm-$rvm_version
rvm_tar=$rvms_root/$rvm_version.tar.gz
ruby_dir=$rvm_dir/rubies/$ruby_version
ruby_dst=ruby
vexec_path=./vexec
path_orig="$PATH"
## getting requested ruby version
mkdir -p $rvms_root/
test -e $rvm_tar || wget "https://github.com/wayneeseguin/rvm/archive/$rvm_version.tar.gz" -P $rvms_root/
test -e $rvm_dir || tar -xzf $rvm_tar -C ./$rvms_root/
mkdir -p $rvm_dir/archives $rvm_dir/rubies
test -e $ruby_dir || $rvm_dir/bin/rvm install $ruby_version
## setting up venv
export GEM_HOME=$rvm_dir
export PATH=$rvm_dir/gems/$ruby_version@global/bin:$ruby_dir/bin:/bin:/usr/bin
if [ ! -x $rvm_dir/gems/$ruby_version@global/bin/bundle ]; then
gem install --no-rdoc --no-ri bundler -v $bundler_version
fi
bundle install --deployment --without development test
mkdir -p $ruby_dst/
rsync -ra --copy-links $ruby_dir/* $ruby_dst/
cp $rvm_dir/gems/$ruby_version@global/gems/bundler-$bundler_version/bin/bundle $ruby_dst/bin/
bundle_dst=$(echo vendor/bundle/ruby/?.*)
# remove files containing absolute links to this build directory
rm -f $ruby_dst/config
rm -fr $ruby_dst/lib/pkgconfig/
rm -f $bundle_dst/bin/executable-hooks-uninstaller
cat > $vexec_path <<zzz
#!/usr/bin/python -Su
from os.path import abspath, dirname, join
import os, sys
root = dirname(abspath(__file__))
path = os.getenv('PATH')
path = ":".join((
join(root, "$ruby_dst/bin"),
path,
))
os.putenv('PATH', path)
os.execv(
join(root, "$ruby_dst/bin/bundle"),
['bundle', 'exec'] + list(sys.argv[1:])
)
zzz
chmod +x $vexec_path
echo -e "\033[34;1m"
echo "Environment ready"
echo "Deploy $ruby_dst and $bundle_dst (or whole vendor/) and $vexec_path dirs to your production"
echo "Run commands thru $vexec_path, like:"
echo "$vexec_path irb -r rubygems -r rest-client"
echo -e "\033[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment