public
Description: Virtualize Ruby installations
Homepage:
Clone URL: git://github.com/chneukirchen/virtualrb.git
virtualrb / get-ruby
100755 72 lines (61 sloc) 1.543 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env ruby
# get-ruby - Download and install Ruby
#
# Copyright (C) 2008 Christian Neukirchen <chneukirchen@gmail.com>
# Licensed under the same terms as Ruby itself.
#
# Usage:
# get-ruby onenine
# get-ruby oldrevision trunk@112233
# get-ruby oneeight branches/ruby_1_8_7
#
# You can kill $root/src/ruby or cd there, svn up and make install to
# refresh the install.
 
root = ARGV[0] || abort("Usage: get-ruby <root> [revision]")
rev = ARGV[1] || "trunk"
 
root = File.expand_path root
 
require 'fileutils'
 
def sh(*args)
  puts "$ #{args.join(' ')}"
  system(*args)
  abort unless $?.success?
end
 
FileUtils.mkdir_p(root)
Dir.chdir(root) {
  FileUtils.mkdir_p("src")
  sh "svn co http://svn.ruby-lang.org/repos/ruby/#{rev} src/ruby"
}
Dir.chdir(root + "/src/ruby") {
  sh "autoconf"
  sh "configure --disable-install-doc --prefix=#{root}"
  sh "make"
  sh "make install"
}
File.open("#{root}/bin/activate", "wb") { |script|
  script.write(<<EOF)
#!/bin/sh
if [ -z "$PS1" ]; then
echo "activate must be run by sourcing." >/dev/stderr
exit -1
fi
 
if [ "$_VRB_ROOT" ]; then
echo "Don't activate without deactivating first." >/dev/stderr
return
fi
 
_VRB_ROOT="#{root}"
_OLD_VRB_PATH="$PATH"
_OLD_VRB_PS1="$PS1"
 
deactivate() {
export PATH="$_OLD_VRB_PATH"
export PS1="$_OLD_VRB_PS1"
hash -r
unset _VRB_ROOT
unset -f deactivate
}
 
export PS1="(`basename "$_VRB_ROOT"`) $PS1"
export PATH="$_VRB_ROOT/bin:$PATH"
hash -r
EOF
}
File.chmod(0755, "#{root}/bin/activate")
 
puts "* Built and installed #{rev} to #{root}"