forked from arcturo/Railcar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RCBootstrapper.rb
108 lines (83 loc) · 2.89 KB
/
RCBootstrapper.rb
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require 'RCBrewManager'
require 'RCRubyManager'
class RCBootstrapper
attr_accessor :delegate
def installDependencies(fromSource = true)
@fromSource = fromSource
puts("starting")
if needsInstall?
begin
checkForCompiler if buildFromSource?
if needsBrew?
installBrew
else
delegate.brewInstalled
end
if needsRbEnv?
installRbenv
else
delegate.rbenvInstalled
end
if needsRuby?
installRuby
else
delegate.rubyInstalled
end
installDefaultGems
rescue StandardError => e
delegate.errorOccurred(e.message)
end
else
delegate.noInstallNeeded
end
end
def needsBrew?
!(File.exist?(File.join(NSBundle.mainBundle.bundlePath, "homebrew", "bin", "brew")))
end
def needsRbEnv?
!(File.exist?(File.join(NSBundle.mainBundle.bundlePath, "homebrew", "Cellar", "rbenv", RBENV_VERSION, "bin", "rbenv")))
end
def needsRuby?
!(File.exist?(File.join(NSBundle.mainBundle.bundlePath, "rbenv", "versions", DEFAULT_RUBY_VERSION, "bin", "ruby")))
end
def checkForCompiler
puts("checking for compiler")
if File.exist?("/usr/bin/gcc")
delegate.compilerExists
else
raise "Compiler not found! Please install XCode or GCC."
end
end
def installBrew
puts("installing brew")
pathToScript = NSBundle.mainBundle.pathForResource('install_brew', ofType:"sh")
`/bin/sh #{pathToScript} #{BREW_DOWNLOAD_URL} #{NSBundle.mainBundle.bundlePath}`
raise "Brew install failed!" if ($?.exitstatus > 0)
brewPath = File.join(NSBundle.mainBundle.bundlePath, "homebrew", "bin", "brew")
`#{brewPath} tap jm/env`
($?.exitstatus > 0) ? raise("Brew tap failed!") : delegate.brewInstalled
end
def installRbenv
puts("installing rbenv")
brewInstaller = RCBrewManager.new
raise "RbEnv install failed!" unless brewInstaller.install("rbenv")
brewInstaller.install("ruby-build-fork") ? delegate.rbenvInstalled : raise("ruby-build install failed!")
end
def installRuby(version = nil)
puts("installing ruby")
rubyInstaller = RCRubyManager.new
rubyInstaller.install((version || DEFAULT_RUBY_VERSION), buildFromSource?) ? delegate.rubyInstalled : raise("Ruby install failed!")
end
def installDefaultGems(version = nil)
puts("installing gems")
pathToInitializer = File.join(NSBundle.mainBundle.bundlePath, "initializers", "rbenv_init_#{version || DEFAULT_RUBY_VERSION}.sh")
`source #{pathToInitializer} && rbenv exec gem install --no-rdoc --no-ri #{DEFAULT_GEMS}`
($?.exitstatus > 0) ? raise("Gems installation failed!") : delegate.gemsInstalled
end
def needsInstall?
Dir.glob(File.join(NSBundle.mainBundle.bundlePath, "initializers", "rbenv_init_*.sh")).empty?
end
def buildFromSource?
@fromSource
end
end