linux_provision 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ require 'linux_provision/linux_provision'
@@ -0,0 +1,66 @@
1
+ require 'json'
2
+ require "highline"
3
+
4
+ require 'text_interpolator'
5
+ require 'script_executor/executable'
6
+ require 'script_executor/script_locator'
7
+
8
+ class GenericProvision
9
+ include Executable, ScriptLocator
10
+
11
+ attr_reader :interpolator, :env, :script_list, :server_info
12
+
13
+ def initialize config_file_name, scripts_file_name
14
+ @interpolator = TextInterpolator.new
15
+
16
+ @env = read_config(config_file_name)
17
+
18
+ @script_list = scripts(File.expand_path(scripts_file_name, File.dirname(__FILE__)))
19
+
20
+ # create_script_methods parent, self
21
+
22
+ @server_info = env[:node] ? env[:node] : {}
23
+ end
24
+
25
+ # def create_script_methods parent, current
26
+ # parent_metaclass = parent.singleton_class
27
+ # current_metaclass = current.singleton_class
28
+ #
29
+ # current.script_list.keys.each do |name|
30
+ # # create methods on parent, e.g. thor or rake file
31
+ # parent_metaclass.send(:define_method, name.to_sym) do |*args, &block|
32
+ # current.send(name, args, block)
33
+ # end
34
+ #
35
+ # # create methods on installer
36
+ # current_metaclass.send(:define_method, name.to_sym) do |_, _|
37
+ # current.send :run, current.server_info, name.to_s, current.env
38
+ # end
39
+ # end
40
+ # end
41
+
42
+ protected
43
+
44
+ def read_config config_file_name
45
+ hash = JSON.parse(File.read(config_file_name), :symbolize_names => true)
46
+
47
+ interpolator.interpolate hash
48
+ end
49
+
50
+ def terminal
51
+ @terminal ||= HighLine.new
52
+ end
53
+
54
+ def ask_password message
55
+ terminal.ask(message) { |q| q.echo = "*" }
56
+ end
57
+
58
+ def run server_info, script_name, params
59
+ execute(server_info) { evaluate_script_body(script_list[script_name], params, :string) }
60
+ end
61
+
62
+ def run_command server_info, command
63
+ execute(server_info.merge({script: command}))
64
+ end
65
+
66
+ end
@@ -0,0 +1,175 @@
1
+ require 'linux_provision/generic_provision'
2
+
3
+ class LinuxProvision < GenericProvision
4
+
5
+ USER_LOCAL_BIN = "/usr/local/bin"
6
+
7
+ def postgres_create_schemas
8
+ env[:postgres][:app_schemas].each do |schema|
9
+ run(server_info, "postgres_create_schema", env.merge(schema: schema))
10
+ end
11
+ end
12
+
13
+ def mysql_create_schemas
14
+ env[:mysql][:app_schemas].each do |schema|
15
+ run(server_info, "mysql_create_schema", env.merge(schema: schema))
16
+ end
17
+ end
18
+ private
19
+
20
+ def method_missing(method, *args, &block)
21
+ run(server_info, method.to_s, env)
22
+ end
23
+
24
+ # def test
25
+ # run(server_info, "test", env)
26
+ # end
27
+
28
+ # def prepare
29
+ # env['password'] = ask_password("Enter password for #{env[:node][:user]}: ")
30
+ #
31
+ # run(server_info.merge(capture_output: false), "prepare", env)
32
+ # end
33
+ #
34
+ # def rvm_install
35
+ # installed = package_installed '#{ENV[\'HOME\']}/.rvm/bin/rvm'
36
+ #
37
+ # if installed
38
+ # puts "rvm already installed."
39
+ # else
40
+ # run(server_info, "rvm", env)
41
+ # end
42
+ # end
43
+ #
44
+ # def npm_install
45
+ # installed = package_installed "#{USER_LOCAL_BIN}/npm"
46
+ #
47
+ # if installed
48
+ # puts "npm already installed."
49
+ # else
50
+ # run(server_info, "npm", env)
51
+ # end
52
+ # end
53
+
54
+ # def qt_install
55
+ # installed = package_installed "#{USER_LOCAL_BIN}/qmake"
56
+ #
57
+ # if installed
58
+ # puts "qt already installed."
59
+ # else
60
+ # run(server_info, "qt", env)
61
+ # end
62
+ # end
63
+ #
64
+ # def mysql_install
65
+ # installed = package_installed "#{USER_LOCAL_BIN}/mysql"
66
+ #
67
+ # if installed
68
+ # puts "mysql already installed."
69
+ # else
70
+ # run(server_info, "mysql", env)
71
+ # end
72
+ # end
73
+ #
74
+ # def mysql_restart
75
+ # started = service_started("homebrew.mxcl.mysql")
76
+ #
77
+ # run(server_info, "mysql_restart", env.merge({started: started}))
78
+ # end
79
+ #
80
+ # def postgres_install
81
+ # installed = package_installed "#{USER_LOCAL_BIN}/postgres"
82
+ #
83
+ # if installed
84
+ # puts "postgres already installed."
85
+ # else
86
+ # run(server_info, "postgres", env)
87
+ # end
88
+ # end
89
+ #
90
+ # def postgres_restart
91
+ # started = service_started("homebrew.mxcl.postgres")
92
+ #
93
+ # run(server_info, "postgres_restart", env.merge({started: started}))
94
+ # end
95
+ #
96
+ # def postgres_stop
97
+ # run server_info, "postgres_stop", env
98
+ # end
99
+ #
100
+ # def postgres_start
101
+ # run server_info, "postgres_start", env
102
+ # end
103
+ #
104
+ # def ruby_install
105
+ # installed = package_installed "#{ENV['HOME']}/.rvm/rubies/ruby-1.9.3-p429/bin/ruby"
106
+ #
107
+ # if installed
108
+ # puts "ruby already installed."
109
+ # else
110
+ # run(server_info, "ruby", env)
111
+ # end
112
+ # end
113
+ #
114
+ # def jenkins_install
115
+ # installed = package_installed "/usr/local/opt/jenkins/libexec/jenkins.war"
116
+ #
117
+ # if installed
118
+ # puts "jenkins already installed."
119
+ # else
120
+ # run(server_info, "jenkins", env)
121
+ # end
122
+ # end
123
+ #
124
+ # def jenkins_restart
125
+ # started = service_started("homebrew.mxcl.jenkins")
126
+ #
127
+ # run(server_info, "jenkins_restart", env.merge({started: started}))
128
+ # end
129
+ #
130
+ # def selenium_install
131
+ # installed = package_installed "/usr/local/opt/selenium-server-standalone/selenium-server-standalone*.jar"
132
+ #
133
+ # if installed
134
+ # puts "selenium already installed."
135
+ # else
136
+ # run(server_info, "selenium", env)
137
+ # end
138
+ # end
139
+ #
140
+ # def selenium_restart
141
+ # started = service_started("homebrew.mxcl.selenium-server-standalone")
142
+ #
143
+ # run(server_info, "selenium_restart", env.merge({started: started}))
144
+ # end
145
+ #
146
+ # def postgres_create user, schemas
147
+ # create_postgres_user user, schemas.first
148
+ #
149
+ # schemas.each do |schema|
150
+ # create_postgres_schema user, schema
151
+ # end
152
+ # end
153
+ #
154
+ # def postgres_drop user, schemas
155
+ # schemas.each do |schema|
156
+ # drop_postgres_schema schema
157
+ # end
158
+ #
159
+ # drop_postgres_user user, schemas.first
160
+ # end
161
+ #
162
+ # def postgres_test schema
163
+ # result = get_postgres_schemas schema
164
+ #
165
+ # puts result
166
+ # end
167
+ #
168
+ # def package_installed package_path
169
+ # result = run server_info.merge(:suppress_output => true, :capture_output => true),
170
+ # "package_installed", env.merge({package_path: package_path})
171
+ #
172
+ # result.chomp == package_path
173
+ # end
174
+
175
+ end
@@ -0,0 +1,172 @@
1
+ #!/bin/sh
2
+
3
+ [test]
4
+ # Test
5
+
6
+ echo "test"
7
+
8
+
9
+ ##############################
10
+ [prepare]
11
+
12
+ sudo apt-get update
13
+
14
+ sudo apt-get install -y curl
15
+ sudo apt-get install -y g++
16
+ sudo apt-get install -y subversion
17
+
18
+
19
+ ##############################
20
+ [rvm]
21
+ #PATH=$PATH:/usr/local/bin
22
+
23
+ USER_HOME="#{node.home}"
24
+
25
+ curl -L https://get.rvm.io | bash
26
+
27
+ sudo chown -R vagrant /opt/vagrant_ruby
28
+
29
+ source $USER_HOME/.rvm/scripts/rvm
30
+
31
+
32
+ ##############################
33
+ [ruby]
34
+
35
+ source $USER_HOME/.rvm/scripts/rvm
36
+
37
+ rvm install ruby-1.9.3
38
+
39
+
40
+ ##############################
41
+ [git]
42
+
43
+ sudo apt-get install -y git
44
+
45
+
46
+ ##############################
47
+ [node]
48
+
49
+ sudo apt-get install -y node
50
+
51
+
52
+ ##############################
53
+ [jenkins]
54
+ sudo apt-get install -y jenkins
55
+
56
+
57
+ ##############################
58
+ [postgres]
59
+
60
+ sudo apt-get install -y postgresql-client
61
+ sudo apt-get install -y libpq-dev
62
+ sudo apt-get install -y postgresql
63
+
64
+
65
+ ##############################
66
+ [mysql]
67
+
68
+ MYSQL_PASSWORD='#{mysql.password}'
69
+
70
+ MYSQL_SERVER_VERSION='5.5'
71
+
72
+ sudo apt-get install -y libmysqlclient-dev ruby-dev
73
+
74
+ sudo apt-get install debconf-utils
75
+ sudo apt-get install -y mysql-client
76
+
77
+ sudo debconf-set-selections <<< "mysql-server-$MYSQL_SERVER_VERSION mysql-server/root_password password $MYSQL_PASSWORD"
78
+ sudo debconf-set-selections <<< "mysql-server-$MYSQL_SERVER_VERSION mysql-server/root_password_again password $MYSQL_PASSWORD"
79
+
80
+ sudo apt-get -y install mysql-server
81
+
82
+
83
+ ##############################
84
+ [postgres_create_user]
85
+
86
+ PATH=$PATH:/usr/local/bin
87
+
88
+ APP_USER='#{postgres.app_user}'
89
+
90
+ sudo -u postgres psql -c "CREATE USER $APP_USER WITH PASSWORD '$APP_USER'"
91
+ #createuser -s -d -r $APP_USER
92
+
93
+ ##############################
94
+ [postgres_drop_user]
95
+
96
+ ##############################
97
+ [postgres_create_schema]
98
+
99
+ SCHEMA='#{schema}'
100
+
101
+ POSTGRES_USER='#{postgres.user}'
102
+ APP_USER='#{postgres.app_user}'
103
+
104
+ ENCODING_STRING="WITH ENCODING = 'UTF-8' LC_CTYPE = 'en_US.utf8' LC_COLLATE = 'en_US.utf8' OWNER $POSTGRES_USER TEMPLATE template0"
105
+
106
+ sudo -u postgres psql -c "CREATE DATABASE $SCHEMA $ENCODING_STRING"
107
+ sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $SCHEMA to $APP_USER"
108
+ #createdb -U $APP_USER $SCHEMA
109
+
110
+
111
+ ##############################
112
+ [postgres_drop_schema]
113
+
114
+
115
+ ##############################
116
+ [mysql_create_user]
117
+
118
+ APP_USER='#{mysql.app_user}'
119
+ HOST_NAME='#{mysql.hostname}'
120
+
121
+ MYSQL_USER='#{mysql.user}'
122
+ MYSQL_PASSWORD='#{mysql.password}'
123
+
124
+ 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;"
125
+ mysql -h localhost -u $MYSQL_USER -p"$MYSQL_PASSWORD" -e "grant all privileges on *.* to '$APP_USER'@'%' identified by '$APP_USER' with grant option;"
126
+ mysql -h localhost -u $MYSQL_USER -p"$MYSQL_PASSWORD" -e "CREATE USER '$APP_USER'@'localhost' IDENTIFIED BY '$APP_USER';"
127
+
128
+
129
+ ##############################
130
+ [mysql_drop_user]
131
+
132
+ APP_USER='#{mysql.app_user}'
133
+ HOST_NAME='#{mysql.hostname}'
134
+
135
+ MYSQL_USER='#{mysql.user}'
136
+ MYSQL_PASSWORD='#{mysql.password}'
137
+
138
+ mysql -h $HOST_NAME -u $MYSQL_USER -p"$MYSQL_PASSWORD" -e "DROP USER '$APP_USER'@'$HOST_NAME';"
139
+
140
+
141
+ ##############################
142
+ [mysql_create_schema]
143
+
144
+ SCHEMA='#{schema}'
145
+
146
+ HOST_NAME='#{mysql.hostname}'
147
+
148
+ MYSQL_USER='#{mysql.user}'
149
+ MYSQL_PASSWORD='#{mysql.password}'
150
+
151
+ mysql -h $HOST_NAME -u $MYSQL_USER -p"$MYSQL_PASSWORD" -e "create database $SCHEMA;"
152
+
153
+
154
+ ##############################
155
+ [mysql_drop_schema]
156
+
157
+
158
+ ##############################
159
+ [project]
160
+
161
+ APP_HOME='$USER_HOME/linux_provision'
162
+
163
+ cd $APP_HOME
164
+
165
+ source $USER_HOME/.rvm/scripts/rvm
166
+
167
+ rvm use 1.9.3@linux_provision
168
+
169
+ bundle install --without=production
170
+
171
+ # rake db:migrate
172
+ # rails s
@@ -0,0 +1,3 @@
1
+ class LinuxProvision
2
+ VERSION = "0.9.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/lib/linux_provision/version')
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "linux_provision"
7
+ spec.summary = %q{Library for building Linux computer provisioning}
8
+ spec.description = %q{Library for building Linux computer provisioning}
9
+ spec.email = "alexander.shvets@gmail.com"
10
+ spec.authors = ["Alexander Shvets"]
11
+ spec.homepage = "http://github.com/shvets/linux_provision"
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 = LinuxProvision::VERSION
17
+
18
+
19
+ <%= project_dependencies %>
20
+ end
21
+
@@ -0,0 +1,15 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ require 'thor'
4
+ load 'thor/linux_install.thor'
5
+
6
+ # rdebug-ide --port 1234 --dispatcher-port 26162 -- ~/.rvm/gems/ruby-1.9.3-p545@linux_ruby_dev_install/bin/rdebug-ide ~/.rvm/gems/ruby-1.9.3-p545@linux_ruby_dev_install/bin/thor linux_install:test
7
+
8
+ describe LinuxInstall do
9
+
10
+ describe "#test" do
11
+ it "calls test method" do
12
+ subject.test
13
+ end
14
+ end
15
+ end