forked from opf/openproject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.rb
executable file
·189 lines (148 loc) · 4.93 KB
/
setup.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env ruby
require 'yaml'
require 'fileutils'
$output_prefix = "==> "
$parsed_options = nil
def abort_installation!
puts $output_prefix + "Something went wrong :("
puts $output_prefix + "Installation aborted."
return false
end
def check_ruby_version
puts $output_prefix + "Checking Ruby Version"
ruby_version = `ruby --version`
version_check = ruby_version.scan("ruby 1.8.7")
patchlevel_check = ruby_version.scan("patchlevel 370")
if version_check.empty?
puts $output_prefix + "It seems you are not using the recommended ruby version."
puts $output_prefix + "Please make sure you have installed 'ruby 1.8.7 (2012-02-08 patchlevel 370)'"
elsif patchlevel_check.empty?
puts $output_prefix + "It seems you are not running the recommended patch level."
puts $output_prefix + "To avoid unexpected problems we would recommend to install 'ruby 1.8.7 (2012-02-08 patchlevel 370)'"
else
puts $output_prefix + "Found"
end
end
def check_bundler
puts $output_prefix + "Checking Bundler"
unless system "bundle --version > /dev/null"
puts $output_prefix + "It seems bundler is not installed. Please install bundler before running setup.rb."
puts $output_prefix + "For bundler and more information visit: http://gembundler.com/"
return false
else
puts $output_prefix + "Found"
return true
end
end
def check_git
puts $output_prefix + "Checking git"
unless system "git --version > /dev/null"
puts $output_prefix + "It seems git is not installed. Please install git before running setup.rb."
return false
else
puts $output_prefix + "Found"
return true
end
end
def check_for_db_yaml
unless File.exists?(ROOT + '/config/database.yml')
puts $output_prefix + "Please configure your database before installing OpenProject."
puts $output_prefix + "Create and configure config/database.yml to do that."
return false
else
return true
end
end
def concatenate_options(parsed_options, option)
return parsed_options[option] ? parsed_options[option].inject(""){|result,a| result + a + " "} : nil
end
def parse_argv(option)
return concatenate_options($parsed_options, option) if $parsed_options
params_hash = {}
name = nil
ARGV.each do |param|
if param[0,2] == "--"
name = param
params_hash[name] = []
else
params_hash[name] << param
end
end
$parsed_options = params_hash
return concatenate_options($parsed_options, option)
end
def checkout_default_plugins
exec_dir = Dir.pwd + "/vendor"
plugin_install_dir = Dir.pwd + "/vendor/plugins/"
default_plugin_file = File.join(Dir.pwd, "plugin_config.yml")
config = YAML.load_file(default_plugin_file)
forced = parse_argv("--force")
config.each_pair do |key, mod_config|
Dir.chdir exec_dir
plugin_path = File.join(exec_dir, key)
if forced and File.exists?(plugin_path)
puts $output_prefix + "Deleting #{plugin_path}.."
FileUtils.rm_rf(plugin_path)
end
if mod_config.keys.include?("repository") and not File.exists?(plugin_path)
system "git clone #{mod_config["repository"]} #{key}"
end
Dir.chdir plugin_path
if mod_config.keys.include?("branch")
unless `git branch`.split.include?(mod_config['branch'])
system "git branch #{mod_config["branch"]} origin/#{mod_config["branch"]}"
end
if `git branch | grep '*'`.delete('*').chomp.strip != mod_config["branch"]
system "git checkout #{mod_config["branch"]}"
system "git merge origin/#{mod_config["branch"]}"
else
system "git merge origin/#{mod_config["branch"]}"
end
end
if mod_config.keys.include?("commit")
system "git reset #{mod_config['commit']}"
end
Dir.chdir exec_dir
end
end
def setup_openproject
puts $output_prefix + "Installing Gems via Bundler"
unless system("bundle install --without rmagick " + parse_argv("--without").to_s)
return false
end
if check_for_db_yaml
puts $output_prefix + "Creating database"
if parse_argv("--force")
puts $output_prefix + "Drop all databases"
return false unless system("rake db:drop:all")
end
return false unless system("rake db:create:all") and migrate_core and migrate_plugins
else
return false
end
puts $output_prefix + "Generate Session Store"
system("rake generate_session_store")
end
def migrate_plugins
puts $output_prefix + "Migrate Plugins"
return system("rake db:migrate:plugins")
end
def migrate_core
puts $output_prefix + "Migrate Core"
return system("rake db:migrate")
end
def install
puts $output_prefix + 'Installing OpenProject...'
check_ruby_version
if not check_bundler or not check_git # check for dependencies
return abort_installation!
end
unless checkout_default_plugins # clone plugins
return abort_installation!
end
Dir.chdir ROOT
return abort_installation! unless setup_openproject # Start installation
puts $output_prefix + "Installation Succeeded"
end
ROOT = Dir.pwd
install