osx_ruby_dev_install 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,226 @@
1
+ require 'osx_ruby_dev_install/generic_installer'
2
+
3
+ class OsxInstaller < GenericInstaller
4
+ USER_LOCAL_BIN = "/usr/local/bin"
5
+
6
+ def prepare
7
+ env['password'] = ask_password("Enter password for #{env[:node][:user]}: ")
8
+
9
+ run(server_info.merge(capture_output: false, sudo: true), "prepare", env)
10
+ end
11
+
12
+ def homebrew_install
13
+ installed = package_installed("#{USER_LOCAL_BIN}/brew")
14
+
15
+ if installed
16
+ puts "homebrew already installed."
17
+ else
18
+ run(server_info, "brew", env)
19
+ end
20
+ end
21
+
22
+ def rvm_install
23
+ installed = package_installed "#{ENV['HOME']}/.rvm/bin/rvm"
24
+
25
+ if installed
26
+ puts "rvm already installed."
27
+ else
28
+ run(server_info, "rvm", env)
29
+ end
30
+ end
31
+
32
+ def npm_install
33
+ installed = package_installed "#{USER_LOCAL_BIN}/npm"
34
+
35
+ if installed
36
+ puts "npm already installed."
37
+ else
38
+ run(server_info, "npm", env)
39
+ end
40
+ end
41
+
42
+ def qt_install
43
+ installed = package_installed "#{USER_LOCAL_BIN}/qmake"
44
+
45
+ if installed
46
+ puts "qt already installed."
47
+ else
48
+ run(server_info, "qt", env)
49
+ end
50
+ end
51
+
52
+ def init_launch_agent
53
+ run(server_info, "init_launch_agent", env)
54
+ end
55
+
56
+ def mysql_install
57
+ installed = package_installed "#{USER_LOCAL_BIN}/mysql"
58
+
59
+ if installed
60
+ puts "mysql already installed."
61
+ else
62
+ run(server_info, "mysql", env)
63
+ end
64
+ end
65
+
66
+ def mysql_restart
67
+ started = service_started("homebrew.mxcl.mysql")
68
+
69
+ run(server_info, "mysql_restart", env.merge({started: started}))
70
+ end
71
+
72
+ def postgres_install
73
+ installed = package_installed "#{USER_LOCAL_BIN}/postgres"
74
+
75
+ if installed
76
+ puts "postgres already installed."
77
+ else
78
+ run(server_info, "postgres", env)
79
+ end
80
+ end
81
+
82
+ def postgres_restart
83
+ started = service_started("homebrew.mxcl.postgres")
84
+
85
+ run(server_info, "postgres_restart", env.merge({started: started}))
86
+ end
87
+
88
+ def postgres_stop
89
+ run server_info, "postgres_stop", env
90
+ end
91
+
92
+ def postgres_start
93
+ run server_info, "postgres_start", env
94
+ end
95
+
96
+ def ruby_install
97
+ installed = package_installed "#{ENV['HOME']}/.rvm/rubies/ruby-1.9.3-p429/bin/ruby"
98
+
99
+ if installed
100
+ puts "ruby already installed."
101
+ else
102
+ run(server_info, "ruby", env)
103
+ end
104
+ end
105
+
106
+ def jenkins_install
107
+ installed = package_installed "/usr/local/opt/jenkins/libexec/jenkins.war"
108
+
109
+ if installed
110
+ puts "jenkins already installed."
111
+ else
112
+ run(server_info, "jenkins", env)
113
+ end
114
+ end
115
+
116
+ def jenkins_restart
117
+ started = service_started("homebrew.mxcl.jenkins")
118
+
119
+ run(server_info, "jenkins_restart", env.merge({started: started}))
120
+ end
121
+
122
+ def selenium_install
123
+ installed = package_installed "/usr/local/opt/selenium-server-standalone/selenium-server-standalone*.jar"
124
+
125
+ if installed
126
+ puts "selenium already installed."
127
+ else
128
+ run(server_info, "selenium", env)
129
+ end
130
+ end
131
+
132
+ def selenium_restart
133
+ started = service_started("homebrew.mxcl.selenium-server-standalone")
134
+
135
+ run(server_info, "selenium_restart", env.merge({started: started}))
136
+ end
137
+
138
+ def postgres_create user, schemas
139
+ create_postgres_user user, schemas.first
140
+
141
+ schemas.each do |schema|
142
+ create_postgres_schema user, schema
143
+ end
144
+ end
145
+
146
+ def postgres_drop user, schemas
147
+ schemas.each do |schema|
148
+ drop_postgres_schema schema
149
+ end
150
+
151
+ drop_postgres_user user, schemas.first
152
+ end
153
+
154
+ def postgres_test schema
155
+ result = get_postgres_schemas schema
156
+
157
+ puts result
158
+ end
159
+
160
+ private
161
+
162
+ def service_started name
163
+ result = run server_info.merge(:suppress_output => true, :capture_output => true),
164
+ "service_started", env.merge({name: name})
165
+
166
+ result.chomp.size > 0
167
+ end
168
+
169
+ def create_mysql_user app_user
170
+ run(server_info, "create_mysql_user", env.merge({app_user: app_user}))
171
+ end
172
+
173
+ def create_mysql_schema schema
174
+ schema_exists = mysql_schema_exist?(config[:mysql][:hostname], config[:mysql][:user], config[:mysql][:password], schema)
175
+
176
+ run(server_info, "create_mysql_schema", env) unless schema_exists
177
+ end
178
+
179
+ def mysql_schema_exist?(hostname, user, password, schema)
180
+ get_mysql_schemas(hostname, user, password, schema).include?(schema)
181
+ end
182
+
183
+ def get_mysql_schemas hostname, user, password, schema
184
+ command = "#{USER_LOCAL_BIN}/mysql -h #{hostname} -u #{user} -p\"#{password}\" -e \"SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA;\""
185
+
186
+ run_command server_info.merge(:suppress_output => true, :capture_output => true), command
187
+ end
188
+
189
+ def postgres_schema_exist?(schema)
190
+ get_postgres_schemas(schema).include?(schema)
191
+ end
192
+
193
+ def get_postgres_schemas schema
194
+ command = "#{USER_LOCAL_BIN}/psql -d #{schema} -c '\\l'"
195
+
196
+ run_command server_info.merge(:suppress_output => true, :capture_output => true), command
197
+ end
198
+
199
+ def create_postgres_user app_user, schema
200
+ run(server_info, "create_postgres_user", env.merge({app_user: app_user, schema: schema}))
201
+ end
202
+
203
+ def drop_postgres_user app_user, schema
204
+ command = "#{USER_LOCAL_BIN}/dropuser #{app_user}"
205
+
206
+ run_command server_info, command
207
+ end
208
+
209
+ def create_postgres_schema app_user, schema
210
+ run(server_info, "create_postgres_schema", env.merge({app_user: app_user, schema: schema}))
211
+ end
212
+
213
+ def drop_postgres_schema schema
214
+ command = "#{USER_LOCAL_BIN}/dropdb #{schema}"
215
+
216
+ run_command server_info, command
217
+ end
218
+
219
+ def package_installed package_path
220
+ result = run server_info.merge(:suppress_output => true, :capture_output => true),
221
+ "package_installed", env.merge({package_path: package_path})
222
+
223
+ result.chomp == package_path
224
+ end
225
+
226
+ end
@@ -0,0 +1,249 @@
1
+ #!/bin/sh
2
+
3
+ #######################################
4
+ [prepare]
5
+
6
+ xcodebuild -license
7
+
8
+
9
+ #######################################
10
+ [brew]
11
+
12
+ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
13
+
14
+ brew update
15
+ brew doctor
16
+
17
+ brew tap homebrew/dupes
18
+ brew tap homebrew/versions
19
+
20
+
21
+ #######################################
22
+ [rvm]
23
+
24
+ PATH=$PATH:/usr/local/bin
25
+ USER_HOME="#{home}"
26
+
27
+ curl -L https://get.rvm.io | bash
28
+
29
+ source $USER_HOME/.rvm/scripts/rvm
30
+
31
+
32
+ #######################################
33
+ [git]
34
+
35
+ brew install git
36
+
37
+
38
+ #######################################
39
+ [qt]
40
+
41
+ PATH=$PATH:/usr/local/bin
42
+
43
+ brew install qt
44
+
45
+
46
+ #######################################
47
+ [init_launch_agent]
48
+
49
+ mkdir #{home}/Library/LaunchAgents/
50
+
51
+
52
+ #######################################
53
+ [mysql]
54
+
55
+ PATH=$PATH:/usr/local/bin
56
+ USER_HOME="#{home}"
57
+
58
+ brew install mysql
59
+
60
+ mkdir -p $USER_HOME/Library/LaunchAgents
61
+
62
+ ln -sfv /usr/local/opt/mysql/*.plist $USER_HOME/Library/LaunchAgents
63
+
64
+ mysqladmin -u root password 'root'
65
+
66
+
67
+ #######################################
68
+ [mysql_restart]
69
+
70
+ STARTED="[#{started}]"
71
+ USER_HOME="#{home}"
72
+
73
+ if [ "$STARTED" = "[true]" ] ; then
74
+ launchctl unload $USER_HOME/Library/LaunchAgents/homebrew.mxcl.mysql.plist
75
+ fi
76
+
77
+ launchctl load $USER_HOME/Library/LaunchAgents/homebrew.mxcl.mysql.plist
78
+
79
+
80
+ #######################################
81
+ [create_mysql_user]
82
+
83
+ PATH=$PATH:/usr/local/bin
84
+
85
+ APP_USER='#{app_user}'
86
+ HOST_NAME='#{mysql[:hostname]}'
87
+ USER='#{mysql[:user]}'
88
+ PASSWORD='#{mysql][:password]}'
89
+
90
+ mysql -h $HOST_NAME -u root -p"root" -e "DROP USER '$APP_USER'@'$HOST_NAME';"
91
+ mysql -h $HOST_NAME -u root -p"root" -e "CREATE USER '$APP_USER'@'$HOST_NAME' IDENTIFIED BY '$APP_USER';"
92
+
93
+ mysql -h $HOST_NAME -u root -p"root" -e "grant all privileges on *.* to '$APP_USER'@'$HOST_NAME' identified by '$APP_USER' with grant option;"
94
+ mysql -h $HOST_NAME -u root -p"root" -e "grant all privileges on *.* to '$APP_USER'@'%' identified by '$APP_USER' with grant option;"
95
+
96
+
97
+ #######################################
98
+ [create_mysql_schema]
99
+
100
+ PATH=$PATH:/usr/local/bin
101
+
102
+ SCHEMA='#{schema}'
103
+ HOST_NAME='#{mysql[:hostname]}'
104
+ USER='#{mysql[:user]}'
105
+ PASSWORD='#{mysql[:password]}'
106
+
107
+ mysql -h $HOST_NAME -u root -p"root" -e "create database $SCHEMA;"
108
+
109
+
110
+ #######################################
111
+ [postgres]
112
+
113
+ PATH=$PATH:/usr/local/bin
114
+ USER_HOME="#{node.home}"
115
+
116
+ brew install postgres
117
+
118
+ ln -sfv /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist $USER_HOME/Library/LaunchAgents
119
+
120
+ initdb /usr/local/var/postgres -E utf8
121
+
122
+
123
+ #######################################
124
+ [postgres_stop]
125
+
126
+ USER_HOME="#{node.home}"
127
+
128
+ launchctl unload -w $USER_HOME/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
129
+
130
+
131
+ #######################################
132
+ [postgres_start]
133
+
134
+ USER_HOME="#{node.home}"
135
+
136
+ launchctl load -w $USER_HOME/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
137
+
138
+
139
+ #######################################
140
+ [postgres_restart]
141
+
142
+ STARTED="[#{started}]"
143
+ USER_HOME="#{node.home}"
144
+
145
+ if [ "$STARTED" = "[true]" ] ; then
146
+ launchctl unload -w $USER_HOME/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
147
+ fi
148
+
149
+ launchctl load -w $USER_HOME/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
150
+
151
+
152
+ #######################################
153
+ [create_postgres_user]
154
+
155
+ PATH=$PATH:/usr/local/bin
156
+
157
+ APP_USER='#{app_user}'
158
+
159
+ createuser -s -d -r $APP_USER
160
+
161
+
162
+ #######################################
163
+ [create_postgres_schema]
164
+
165
+ PATH=$PATH:/usr/local/bin
166
+
167
+ APP_USER='#{app_user}'
168
+ SCHEMA='#{schema}'
169
+
170
+ createdb -U $APP_USER $SCHEMA
171
+
172
+
173
+ #######################################
174
+ [ruby]
175
+
176
+ PATH=$PATH:/usr/local/bin
177
+
178
+ rvm install 1.9.3
179
+
180
+
181
+ #######################################
182
+ [jenkins]
183
+
184
+ PATH=$PATH:/usr/local/bin
185
+ USER_HOME="#{node.home}"
186
+
187
+ brew install jenkins
188
+
189
+ ln -sfv /usr/local/opt/jenkins/homebrew.mxcl.jenkins.plist $USER_HOME/Library/LaunchAgents
190
+
191
+
192
+ #######################################
193
+ [jenkins_restart]
194
+
195
+ STARTED="[#{started}]"
196
+ USER_HOME="#{node.home}"
197
+
198
+ if [ "$STARTED" = "[true]" ] ; then
199
+ launchctl unload $USER_HOME/Library/LaunchAgents/homebrew.mxcl.jenkins.plist
200
+ fi
201
+
202
+ launchctl load $USER_HOME/Library/LaunchAgents/homebrew.mxcl.jenkins.plist
203
+
204
+
205
+ #######################################
206
+ [selenium]
207
+
208
+ PATH=$PATH:/usr/local/bin
209
+ USER_HOME="#{node.home}"
210
+
211
+ brew install selenium-server-standalone
212
+
213
+ ln -sfv /usr/local/opt/selenium-server-standalone/*.plist $USER_HOME/Library/LaunchAgents
214
+
215
+
216
+ #######################################
217
+ [selenium_restart]
218
+
219
+ STARTED="[#{started}]"
220
+ USER_HOME="#{node.home}"
221
+
222
+ if [ "$STARTED" = "true" ] ; then
223
+ launchctl unload $USER_HOME/Library/LaunchAgents/homebrew.mxcl.selenium-server-standalone.plist
224
+ fi
225
+
226
+ launchctl load $USER_HOME/Library/LaunchAgents/homebrew.mxcl.selenium-server-standalone.plist
227
+
228
+
229
+ #######################################
230
+ [npm]
231
+
232
+ brew install node
233
+
234
+
235
+ #######################################
236
+ [package_installed]
237
+
238
+ ls #{package_path}
239
+
240
+
241
+ #######################################
242
+ [service_started]
243
+
244
+ NAME="#{name%}"
245
+
246
+ TEMPFILE="$(mktemp XXXXXXXX)"
247
+ launchctl list | grep $NAME > $TEMPFILE
248
+ cat $TEMPFILE
249
+ rm $TEMPFILE
@@ -0,0 +1,3 @@
1
+ class OsxRubyDevInstall
2
+ VERSION = "0.9.0"
3
+ end
@@ -0,0 +1 @@
1
+ require 'osx_ruby_dev_install/osx_installer'
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/lib/osx_ruby_dev_install/version')
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "osx_ruby_dev_install"
7
+ spec.summary = %q{Library for building Mac OSX provisioning}
8
+ spec.description = %q{Library for building Mac OSX computer provisioning}
9
+ spec.email = "alexander.shvets@gmail.com"
10
+ spec.authors = ["Alexander Shvets"]
11
+ spec.homepage = "http://github.com/shvets/osx_ruby_dev_install"
12
+
13
+ spec.files = `git ls-files`.split($\)
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+ spec.version = OsxRubyDevInstall::VERSION
17
+
18
+
19
+ <%= project_dependencies %>
20
+ end
21
+
@@ -0,0 +1,25 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ require 'osx_ruby_dev_install/osx_installer'
4
+
5
+ describe OsxInstaller do
6
+ subject { OsxInstaller.new ".osx_install.json", "osx_scripts.sh"}
7
+
8
+ describe "#init_launch_agent" do
9
+ it "calls prepare method" do
10
+ subject.jenkins_install
11
+ end
12
+ end
13
+
14
+ describe "#init_launch_agent" do
15
+ it "calls init_launch_agent method" do
16
+ subject.init_launch_agent
17
+ end
18
+ end
19
+
20
+ describe "#homebrew_install" do
21
+ it "calls homebrew_install method" do
22
+ subject.homebrew_install
23
+ end
24
+ end
25
+ end
@@ -0,0 +1 @@
1
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
@@ -0,0 +1,145 @@
1
+ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
2
+
3
+ require 'osx_ruby_dev_install/osx_installer'
4
+
5
+ class OsxInstall < Thor
6
+ attr_reader :installer
7
+
8
+ def initialize *params
9
+ @installer = OsxInstaller.new ".osx_install.json", "osx_scripts.sh"
10
+
11
+ super *params
12
+ end
13
+
14
+ desc "all", "Installs all required packages"
15
+ def all
16
+ invoke :brew
17
+ invoke :rvm
18
+ invoke :qt
19
+
20
+ invoke :mysql
21
+ invoke :mysql_restart
22
+
23
+ invoke :init_launch_agent
24
+
25
+ invoke :postgres
26
+ invoke :postgres_restart
27
+
28
+ invoke :jenkins
29
+ invoke :jenkins_restart
30
+
31
+ invoke :selenium
32
+
33
+ invoke :ruby
34
+
35
+ invoke :postgres_create
36
+ end
37
+
38
+ desc "prepare", "prepare"
39
+ def prepare
40
+ installer.prepare
41
+ end
42
+
43
+ desc "brew", "Installs homebrew"
44
+ def brew
45
+ installer.homebrew_install
46
+ end
47
+
48
+ desc "rvm", "Installs rvm"
49
+ def rvm
50
+ installer.rvm_install
51
+ end
52
+
53
+ desc "npm", "Installs npm"
54
+ def npm
55
+ installer.npm_install
56
+ end
57
+
58
+ desc "qt", "Installs qt"
59
+ def qt
60
+ installer.qt_install
61
+ end
62
+
63
+ desc "init_launch_agent", "Inits launch agent"
64
+ def init_launch_agent
65
+ installer.init_launch_agent
66
+ end
67
+
68
+ desc "mysql", "Installs mysql server"
69
+ def mysql
70
+ installer.mysql_install
71
+ end
72
+
73
+ # brew uninstall mysql
74
+
75
+ desc "mysql_restart", "Restarts mysql server"
76
+ def mysql_restart
77
+ installer.mysql_restart
78
+ end
79
+
80
+ desc "postgres", "Installs postgres server"
81
+ def postgres
82
+ installer.postgres_install
83
+ end
84
+
85
+ desc "postgres_restart", "Restarts postgres server"
86
+ def postgres_restart
87
+ installer.postgres_restart
88
+ end
89
+
90
+ desc "postgres_stop", "Stop postgres server"
91
+ def postgres_stop
92
+ installer.postgres_stop
93
+ end
94
+
95
+ desc "postgres_start", "Start postgres server"
96
+ def postgres_start
97
+ installer.postgres_start
98
+ end
99
+
100
+ desc "ruby", "Installs ruby"
101
+ def ruby
102
+ installer.ruby_install
103
+ end
104
+
105
+ desc "jenkins", "Installs jenkins server"
106
+ def jenkins
107
+ installer.jenkins_install
108
+ end
109
+
110
+ desc "jenkins_restart", "Restart jenkins server"
111
+ def jenkins_restart
112
+ installer.jenkins_restart
113
+ end
114
+
115
+ desc "selenium", "Installs selenium server"
116
+ def selenium
117
+ installer.selenium_install
118
+ end
119
+
120
+ desc "selenium_restart", "Restarts selenium server"
121
+ def selenium_restart
122
+ installer.selenium_restart
123
+ end
124
+
125
+ desc "postgres_create", "Initializes postgres project schemas"
126
+ def postgres_create
127
+ installer.postgres_create env["app_user"], env["app_schemas"]
128
+ end
129
+
130
+ desc "postgres_drop", "Drops postgres project schemas"
131
+ def postgres_drop
132
+ installer.postgres_drop env["app_user"], env["app_schemas"]
133
+ end
134
+
135
+ desc "postgres_test", "Test postgres schemas"
136
+ def postgres_test
137
+ installer.postgres_test env["app_user"]
138
+ end
139
+
140
+ desc "test", "test"
141
+ def test
142
+ puts "test"
143
+ end
144
+
145
+ end