salted-rails 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/README.md +7 -0
  2. data/lib/salted-rails/config.rb +71 -55
  3. data/lib/salted-rails/helper_base.rb +15 -0
  4. data/lib/salted-rails/vagrant_helper.rb +15 -9
  5. data/lib/salted-rails/version.rb +1 -1
  6. data/pillar/capistrano/top.sls +1 -1
  7. data/pillar/common.sls +1 -8
  8. data/pillar/vagrant/top.sls +1 -1
  9. data/salt/apt/load_packages.sls +5 -0
  10. data/salt/apt/update_packages.sls +5 -0
  11. data/salt/bin/change_mirror.sh +10 -6
  12. data/salt/bin/misc_fixes.sh +26 -0
  13. data/salt/bin/provision +40 -3
  14. data/salt/ci/cruisecontrolrb.sls +17 -11
  15. data/salt/ci/teamcity/etc/init.d/teamcity +4 -4
  16. data/salt/ci/teamcity/init.sls +18 -18
  17. data/salt/crons/init.sls +2 -2
  18. data/salt/databases/init.sls +45 -14
  19. data/salt/databases/mysql/client.sls +1 -1
  20. data/salt/databases/mysql/common.sls +3 -3
  21. data/salt/databases/mysql/server.sls +1 -1
  22. data/salt/databases/packages.sls +47 -0
  23. data/salt/databases/phpmyadmin/etc/nginx/admin.d/phpmyadmin.conf +10 -7
  24. data/salt/databases/postgresql/client.sls +5 -0
  25. data/salt/databases/postgresql/init.sls +10 -0
  26. data/salt/databases/sqlite3.sls +6 -0
  27. data/salt/databases/sqlitebrowser.sls +4 -0
  28. data/salt/editors/gvim.sls +5 -1
  29. data/salt/editors/rubymine.sls +16 -16
  30. data/salt/editors/vim/init.sls +71 -2
  31. data/salt/editors/vim/vimrc +8 -1
  32. data/salt/gui/desktop.sls +9 -0
  33. data/salt/gui/x2go.sls +5 -0
  34. data/salt/lang/jenv.sls +64 -0
  35. data/salt/lang/php/etc/php5/fpm/pool.d/www.conf +2 -2
  36. data/salt/lang/phpenv.sls +82 -0
  37. data/salt/lang/rbenv.sls +115 -0
  38. data/salt/lang/ruby.sls +24 -37
  39. data/salt/munin/nginx.sls +3 -1
  40. data/salt/munin/node.sls +2 -1
  41. data/salt/munin/php5-fpm.sls +3 -1
  42. data/salt/net/hosts.sls +9 -0
  43. data/salt/net/ntp.sls +6 -0
  44. data/salt/net/ufw.sls +8 -0
  45. data/salt/railsapp/gems.sls +5 -3
  46. data/salt/railsapp/init.sls +6 -2
  47. data/salt/scm/bazaar.sls +10 -0
  48. data/salt/scm/git/gitconfig +42 -0
  49. data/salt/scm/git/init.sls +21 -0
  50. data/salt/scm/init.sls +5 -0
  51. data/salt/scm/mercurial.sls +10 -0
  52. data/salt/scm/subversion.sls +6 -0
  53. data/salt/{vagrant/top.sls → top.sls} +24 -9
  54. data/salt/utils/file.sls +19 -0
  55. data/salt/utils/html.sls +5 -0
  56. data/salt/utils/init.sls +6 -0
  57. data/salt/{sysutils → utils}/net.sls +4 -0
  58. data/salt/{sysutils → utils}/status.sls +0 -0
  59. data/salt/utils/tmux/home/tmux-dev +7 -0
  60. data/salt/utils/tmux/home/tmux.conf +89 -0
  61. data/salt/utils/tmux/init.sls +32 -0
  62. data/salt/vagrant/minion.sls +1 -1
  63. data/salt/www/chromium.sls +5 -0
  64. data/salt/www/nginx/etc/nginx/admin.d/doc.conf +7 -0
  65. data/salt/www/nginx/etc/nginx/admin.d/nginx_status.conf +7 -0
  66. data/salt/www/nginx/etc/nginx/sites-available/.gitignore +3 -0
  67. data/salt/www/nginx/etc/nginx/sites-available/admin.conf +47 -0
  68. data/salt/www/nginx/init.sls +102 -16
  69. data/salt/www/nginx/srv/www/admin/favicon.ico +0 -0
  70. data/salt/www/nginx/srv/www/admin/favicon.png +0 -0
  71. data/salt/www/nginx/srv/www/admin/index.php +67 -0
  72. data/salt/www/nginx/srv/www/admin/phpinfo.php +3 -0
  73. data/salt/www/nginx/srv/www/admin/robots.txt +2 -0
  74. data/salt/www/users.sls +0 -9
  75. metadata +41 -20
  76. data/salt/bin/fix_hostname.sh +0 -6
  77. data/salt/capistrano/deploy_requirements.sls +0 -5
  78. data/salt/capistrano/top.sls +0 -4
  79. data/salt/databases/client.sls +0 -18
  80. data/salt/databases/server.sls +0 -19
  81. data/salt/gui/init.sls +0 -3
  82. data/salt/lang/ruby.sls.bak +0 -106
  83. data/salt/lang/system_ruby.sls +0 -43
  84. data/salt/sysutils/file.sls +0 -8
  85. data/salt/sysutils/init.sls +0 -5
  86. data/salt/sysutils/tmux.sls +0 -3
  87. data/salt/www/admin/etc/nginx/nginx.conf +0 -53
  88. data/salt/www/admin/etc/nginx/sites-available/.gitignore +0 -3
  89. data/salt/www/admin/etc/nginx/sites-available/phpmyadmin.conf +0 -7
  90. data/salt/www/admin/init.sls +0 -31
data/README.md CHANGED
@@ -79,6 +79,10 @@ Or for a more complicated example:
79
79
  # override default domain
80
80
  salted_config.domain = 'mydomain.com'
81
81
 
82
+ # load packages specified in a file (eg generated from your production system)
83
+ # use `dpkg --get-selections "*" > my_packages-datestamp` to generate the list
84
+ #salted_config.packages = 'config/my_packages-datestamp'
85
+
82
86
  # Define a machine dev
83
87
  salted_config.define('dev') do |machine_config|
84
88
  end
@@ -101,6 +105,9 @@ Or for a more complicated example:
101
105
 
102
106
  # gui also configures virtualbox for standard rather than headless mode
103
107
  machine_config.roles <<= 'gui'
108
+
109
+ # Disable the syncing to /vagrant in digital_ocean (useful for development that is independent of local machine)
110
+ machine_config.sync_vagrant = false
104
111
  end
105
112
 
106
113
  salted_config.configure_vagrant(config)
@@ -7,29 +7,32 @@ require 'log4r'
7
7
  module SaltedRails
8
8
  class Config
9
9
 
10
- attr_accessor :private_key_path
11
- attr_accessor :machine
12
- attr_accessor :hostname
10
+ attr_accessor :box
11
+ attr_accessor :ca_path
12
+ attr_accessor :copy_from_home
13
+ attr_accessor :admin_password
14
+ attr_accessor :web_password
15
+ attr_accessor :databases
13
16
  attr_accessor :domain
14
- attr_accessor :rails_root
15
- attr_accessor :salt_root
16
- attr_accessor :mirror
17
+ attr_accessor :files
18
+ attr_accessor :forward_agent
19
+ attr_accessor :gems
20
+ attr_accessor :hostname
17
21
  attr_accessor :logger
22
+ attr_accessor :machine
23
+ attr_accessor :machines
18
24
  attr_accessor :memory
25
+ attr_accessor :mirror
26
+ attr_accessor :packages
19
27
  attr_accessor :ports
20
- attr_accessor :disable_vagrant_sync
21
- attr_accessor :ca_path
28
+ attr_accessor :mapped_ports
29
+ attr_accessor :private_key_path
30
+ attr_accessor :rails_root
22
31
  attr_accessor :region
23
- attr_accessor :forward_agent
24
- attr_accessor :files
25
- attr_accessor :databases
26
32
  attr_accessor :roles
27
- attr_accessor :gems
28
- attr_accessor :ruby_version
29
- attr_accessor :java_version
30
- attr_accessor :php_version
31
- attr_accessor :machines
32
- attr_accessor :copy_from_home
33
+ attr_accessor :salt_root
34
+ attr_accessor :sync_vagrant
35
+ attr_accessor :versions
33
36
 
34
37
  def sanitize_dns_name(name)
35
38
  dns_name = name.downcase.gsub(/[^-0-9a-z]+/,'-').sub(/^-+/, '').sub(/-+$/, '')
@@ -45,15 +48,20 @@ module SaltedRails
45
48
  # see salt/vagrant/top.sls for other roles
46
49
  @roles = %w{ app web db }
47
50
  @domain = nil
51
+ @admin_password = nil
52
+ @web_password = nil
48
53
  @private_key_path = nil
49
54
  @mirror = nil
50
55
  @memory = nil
51
56
  @ports = [ 80, 443, 880, 3000 ]
52
- @disable_vagrant_sync = true
57
+ @mapped_ports = { }
58
+ @sync_vagrant = nil
59
+ @box = nil
53
60
  @ca_path = nil
54
61
  @region = nil
55
62
  @forward_agent = true
56
- @files = [ '.ruby-version', '.java-version', '.php-version', '.rvmrc', 'config/database.yml', 'Gemfile', 'Gemfile.lock' ].select{ |f| File.exist?(@rails_root + f) }
63
+ @files = [ '.ruby-version', '.java-version', '.php-version', 'config/database.yml', 'Gemfile', 'Gemfile.lock' ].select{ |f| File.exist?(@rails_root + f) }
64
+ @packages = nil
57
65
  @copy_from_home = [ ]
58
66
 
59
67
  ENV['REMOTE_MACHINE'] = 'true'
@@ -73,12 +81,12 @@ module SaltedRails
73
81
  end
74
82
  end
75
83
  @databases.each do |key, details|
76
- @gems[details['adapter']] = true
84
+ @gems[details['adapter']] ||= true
77
85
  end
78
86
 
79
- @ruby_version = nil
80
- @java_version = nil
81
- @php_version = nil
87
+ @roles << 'mysql' if @gems.include?('mysql') or @gems.include?('mysql2')
88
+
89
+ @versions= { }
82
90
 
83
91
  @machines = [ ]
84
92
  @hostname = nil
@@ -89,7 +97,26 @@ module SaltedRails
89
97
  end
90
98
 
91
99
  def normalize
92
- unless @memory
100
+ @versions['mysql'] ||= '5.5' if @roles.include?('mysql')
101
+ @versions['teamcity'] ||= '8.0.4' if @roles.include?('teamcity')
102
+ @versions['rubymine'] ||= '5.4.3' if @roles.include?('rubymine')
103
+ @roles << 'gui' if @roles.include?('rubymine') and not @roles.include?('gui')
104
+
105
+ %w{ ruby php java }.each do |lang|
106
+ version = File.open(@rails_root + ".#{lang}-version", 'r') do |f_in|
107
+ f_in.gets.gsub(/\s/,'')
108
+ end rescue nil
109
+ @versions[lang] ||= version if version
110
+ end
111
+ unless @versions.include?('ruby')
112
+ File.open(@rails_root + '.rvmrc', 'r') do |f_in|
113
+ while (line = f_in.gets) and not @versions.include('ruby')
114
+ @versions['ruby'] = $1 if line =~ /^\s*environment_id=['"]([^"'@]+)/
115
+ end
116
+ end rescue nil
117
+ end
118
+
119
+ if @memory.nil?
93
120
  @memory = 512
94
121
  {
95
122
  'gui' => 1536,
@@ -99,7 +126,8 @@ module SaltedRails
99
126
  @memory += extra if @roles.include?(role)
100
127
  end
101
128
  end
102
- unless @domain
129
+
130
+ if @domain.nil?
103
131
  if @hostname
104
132
  @domain = @hostname.sub(/^[^.]*\.?/, '')
105
133
  else
@@ -107,6 +135,7 @@ module SaltedRails
107
135
  @domain = 'railsapp.test' if @domain == '.test'
108
136
  end
109
137
  end
138
+
110
139
  if @hostname.nil? or @hostname == ''
111
140
  if @machine == 'default'
112
141
  @hostname = @domain
@@ -119,33 +148,15 @@ module SaltedRails
119
148
  end
120
149
  end
121
150
  end
122
- @ruby_version ||= File.open(@rails_root + '.ruby-version', 'r') do |f_in|
123
- f_in.gets.gsub(/\s/,'')
124
- end rescue nil
125
- @ruby_version ||= File.open(@rails_root + '.rvmrc', 'r') do |f_in|
126
- while !ruby_version && (line = f_in.gets)
127
- ruby_version = $1 if line =~ /^\s*environment_id=['"]([^"'@]+)/
128
- end
129
- end rescue nil
130
- @ruby_version ||= '1.9.3'
131
-
132
- @java_version ||= File.open(@rails_root + '.java-version', 'r') do |f_in|
133
- f_in.gets.gsub(/\s/,'')
134
- end rescue nil
135
-
136
- @php_version ||= File.open(@rails_root + '.php-version', 'r') do |f_in|
137
- f_in.gets.gsub(/\s/,'')
138
- end rescue nil
139
151
 
140
152
  @private_key_path ||= '~/.ssh/id_rsa'
141
153
  @mirror ||= 'auto'
142
154
  @salt_root ||= File.dirname(__FILE__) + '/../../'
143
155
  @ca_path ||= '/etc/ssl/certs/ca-certificates.crt'
156
+ @box ||= 'preciseCloud32'
144
157
  @ca_path = nil unless File.exist?(@ca_path)
145
158
  @region ||= 'San Francisco 1'
146
159
 
147
- @machines.each {|m| m.normalize}
148
-
149
160
  {
150
161
  'teamcity' => 8111,
151
162
  'cruisecontrolrb' => 3333
@@ -153,6 +164,9 @@ module SaltedRails
153
164
  @ports << port if @roles.include?(role) and not @ports.include?(port)
154
165
  end
155
166
 
167
+ @sync_vagrant = true if @sync_vagrant.nil?
168
+
169
+ @machines.each {|m| m.normalize}
156
170
  end
157
171
 
158
172
  def define(machine, &block)
@@ -178,21 +192,23 @@ module SaltedRails
178
192
 
179
193
  def to_hash
180
194
  {
195
+ 'admin_password' => @admin_password,
196
+ 'databases' => @databases,
197
+ 'disable_vagrant_sync' => @disable_vagrant_sync,
181
198
  'domain' => @domain,
182
- 'mirror' => @mirror,
183
- 'machine' => @machine,
199
+ 'files' => @files,
200
+ 'forward_agent' => @forward_agent,
201
+ 'gems' => @gems,
184
202
  'hostname' => @hostname,
203
+ 'machine' => @machine,
204
+ 'mapped_ports' => @mapped_ports,
185
205
  'memory' => @memory,
186
- 'disable_vagrant_sync' => @disable_vagrant_sync,
206
+ 'mirror' => @mirror,
207
+ 'ports' => @ports,
187
208
  'region' => @region,
188
- 'forward_agent' => @forward_agent,
189
- 'files' => @files,
190
- 'databases' => @databases,
191
- 'gems' => @gems,
192
- 'ruby_version' => @ruby_version,
193
- 'java_version' => @java_version,
194
- 'php_version' => @php_version,
195
- 'roles' => @roles
209
+ 'roles' => @roles,
210
+ 'user_password' => @user_password,
211
+ 'versions' => @versions
196
212
  }
197
213
  end
198
214
 
@@ -59,6 +59,21 @@ module SaltedRails
59
59
  end
60
60
  FileUtils.cp(@config.rails_root + f, dest)
61
61
  end
62
+ dest = salt_dir + 'packages.txt'
63
+ if @config.packages
64
+ src = @config.packages
65
+ src = @config.rails_root + src unless src =~ /^\//
66
+ dir = File.dirname(dest)
67
+ unless File.directory? dir
68
+ FileUtils.mkdir_p dir
69
+ end
70
+ if !File.exist?(dest) or (File.mtime(src) > File.mtime(dest))
71
+ @config.logger.info "SaltedRails: Copying #{src} to #{dest}"
72
+ FileUtils.cp(src, dest)
73
+ end
74
+ else
75
+ FileUtils.rm_f dest
76
+ end
62
77
  @config.copy_from_home.each do |f|
63
78
  dest = salt_dir + "home/" + f
64
79
  dir = File.dirname(dest)
@@ -35,9 +35,9 @@ module SaltedRails
35
35
  end
36
36
  end
37
37
  # create_empty_custom_files
38
- pillarize_application_configuration
39
- fix_hostname(vagrant_config)
38
+ misc_fixes(vagrant_config)
40
39
  configure_salt(vagrant_config)
40
+ pillarize_application_configuration
41
41
  end
42
42
 
43
43
  def configure_ubuntu_mirror(vagrant_config, config = @config)
@@ -53,9 +53,9 @@ module SaltedRails
53
53
  vagrant_config.vm.hostname = config.hostname
54
54
  end
55
55
 
56
- def fix_hostname(vagrant_config, config = @config)
56
+ def misc_fixes(vagrant_config, config = @config)
57
57
  vagrant_config.vm.provision "shell" do |s|
58
- s.path = config.salt_root + 'salt/bin/fix_hostname.sh'
58
+ s.path = config.salt_root + 'salt/bin/misc_fixes.sh'
59
59
  end
60
60
  end
61
61
 
@@ -64,7 +64,7 @@ module SaltedRails
64
64
  require 'vagrant-vbguest'
65
65
  require 'salted-rails/cloud_vbguest_installer'
66
66
  vagrant_config.vbguest.installer = SaltedRails::CloudVbguestInstaller
67
- vagrant_config.vbguest.auto_update = false
67
+ #vagrant_config.vbguest.auto_update = false
68
68
  config.logger.info 'Configured vbguest installer'
69
69
  rescue LoadError
70
70
  config.logger.info 'Skipping vbguest (plugin not available)'
@@ -73,9 +73,13 @@ module SaltedRails
73
73
 
74
74
 
75
75
  def configure_virtualbox(vagrant_config, config = @config)
76
- config.logger.info 'Configuring virtualbox box (UbuntuCloud_12.04_32bit)'
77
- vagrant_config.vm.box = 'UbuntuCloud_12.04_32bit'
78
- vagrant_config.vm.box_url = 'http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-i386-disk1.box'
76
+ config.logger.info "Configuring virtualbox box (#{config.box})"
77
+ vagrant_config.vm.box = config.box
78
+ if config.box == 'preciseCloud32'
79
+ vagrant_config.vm.box_url = 'http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-i386-disk1.box'
80
+ elsif config.box == 'precise32'
81
+ vagrant_config.vm.box_url = 'http://files.vagrantup.com/precise32.box'
82
+ end
79
83
  end
80
84
 
81
85
  def configure_digital_ocean(vagrant_config, config = @config)
@@ -87,7 +91,7 @@ module SaltedRails
87
91
  provider.image = 'Ubuntu 12.04 x32'
88
92
  provider.region = config.region
89
93
  provider.ca_path = config.ca_path if config.ca_path
90
- override.vm.synced_folder '.', '/vagrant', :disabled => true if config.disable_vagrant_sync
94
+ override.vm.synced_folder '.', '/vagrant', :disabled => true unless config.sync_vagrant
91
95
  if config.private_key_path
92
96
  override.ssh.private_key_path = config.private_key_path
93
97
  private_key_name = 'Vagrant ' + config.private_key_path.sub(/~\//, '').sub(/\.ssh\//, '').sub(/^id_/, '').gsub(/\W+/, ' ')
@@ -129,8 +133,10 @@ module SaltedRails
129
133
  end
130
134
 
131
135
  def configure_ports(vagrant_config, port_offset=0, config = @config)
136
+ config.mapped_ports = { }
132
137
  config.ports.each do |port|
133
138
  host_port = port_offset + port + (port < 3000 ? 3000 : 0)
139
+ config.mapped_ports[port] = host_port
134
140
  vagrant_config.vm.network :forwarded_port, :guest => port, :host => host_port, auto_correct: true
135
141
  end
136
142
  end
@@ -1,3 +1,3 @@
1
1
  module SaltedRails
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  base:
2
2
  '*':
3
- - common
4
3
  - railsapp
5
4
  - capistrano
5
+ - common
@@ -10,11 +10,4 @@ logs_dir: /var/log/
10
10
 
11
11
  www_dir: /srv/www/
12
12
 
13
- mysql-version: 5.5
14
-
15
- teamcity-version: 8.0.4
16
-
17
- rubymine-version: 5.4.3
18
-
19
-
20
- # vim: filetype=sls
13
+ # vim: filetype=sls:
@@ -1,5 +1,5 @@
1
1
  base:
2
2
  '*':
3
- - common
4
3
  - railsapp
5
4
  - vagrant
5
+ - common
@@ -0,0 +1,5 @@
1
+ load_packages:
2
+ cmd.run:
3
+ - name: dpkg --set-selections < /srv/salt/generated/packages.txt && env DEBIAN_FRONTEND=noninteractive apt-get -y -u dselect-upgrade
4
+ - onlyif: test -s /srv/salt/generated/packages.txt
5
+
@@ -0,0 +1,5 @@
1
+ load_packages:
2
+ cmd.run:
3
+ - name: dpkg --set-selections < /srv/salt/generated/packages.txt && apt-get -u dselect-upgrade
4
+ - /srv/salt/generated/packages.txt
5
+
@@ -7,23 +7,27 @@ case "$1" in
7
7
  exec echo "usage: $0 country|mirror|auto|internode|url"
8
8
  ;;
9
9
  esac
10
- if grep 'http://archive.ubuntu.com/ubuntu' /etc/apt/sources.list > /dev/null; then
10
+ if grep 'http://[a-z.]*archive.ubuntu.com/ubuntu' /etc/apt/sources.list > /dev/null; then
11
11
  case "$1" in
12
12
  [a-z][a-z]|usa)
13
13
  echo "Configuring mirror for region: $1"
14
- exec sed -i.original -e 's#http://[archivesecurity]*.ubuntu.com/ubuntu#http://'"$1"'.archive.ubuntu.com/ubuntu/#' /etc/apt/sources.list
14
+ exec sed -i.original -e 's#http://[a-z.]*[archivesecurity]*.ubuntu.com/ubuntu#http://'"$1"'.archive.ubuntu.com/ubuntu/#' /etc/apt/sources.list
15
15
  ;;
16
16
  mirror|auto)
17
17
  echo "Configuring automatic selection of mirror"
18
- exec sed -i.original -e 's#http://[archivesecurity]*.ubuntu.com/ubuntu#mirror://mirrors.ubuntu.com/mirrors.txt#' /etc/apt/sources.list
18
+ exec sed -i.original -e 's#http://[a-z.]*[archivesecurity]*.ubuntu.com/ubuntu#mirror://mirrors.ubuntu.com/mirrors.txt#' /etc/apt/sources.list
19
+ ;;
20
+ sfo1)
21
+ echo "Configuring mirror for DIGITAL OCEAN: $1"
22
+ exec sed -i.original -e 's#http://[a-z.]*[archivesecurity]*.ubuntu.com/ubuntu#http://mirrors.sfo1.digitalocean.com/ubuntu/#' /etc/apt/sources.list
19
23
  ;;
20
24
  internode)
21
25
  echo "Configuring mirror for ISP: $1"
22
- exec sed -i.original -e 's#http://[archivesecurity]*.ubuntu.com/ubuntu#http://mirror.internode.on.net/pub/ubuntu/ubuntu/#' /etc/apt/sources.list
26
+ exec sed -i.original -e 's#http://[a-z.]*[archivesecurity]*.ubuntu.com/ubuntu#http://mirror.internode.on.net/pub/ubuntu/ubuntu/#' /etc/apt/sources.list
23
27
  ;;
24
28
  [hmf]*://*ubuntu*)
25
29
  echo "Configuring mirror for $1"
26
- exec sed -i.original -e 's#http://[archivesecurity]*.ubuntu.com/ubuntu#'"$1"'#' /etc/apt/sources.list
30
+ exec sed -i.original -e 's#http://[a-z.]*[archivesecurity]*.ubuntu.com/ubuntu#'"$1"'#' /etc/apt/sources.list
27
31
  ;;
28
32
  *)
29
33
  echo "Invalid mirror ($1) ignored!" >&2
@@ -31,6 +35,6 @@ if grep 'http://archive.ubuntu.com/ubuntu' /etc/apt/sources.list > /dev/null; th
31
35
  ;;
32
36
  esac
33
37
  else
34
- echo "/etc/apt/sources.list has already been changed (leaving as is)"
38
+ echo "/etc/apt/sources.list has already been changed to non ubuntu.com mirror (leaving as is)"
35
39
  fi
36
40
  exit 0
@@ -0,0 +1,26 @@
1
+ #!/bin/bash
2
+ #
3
+
4
+ old=`cat /etc/hostname`
5
+ case "$old" in
6
+ *.*)
7
+ echo "Removing domain from /etc/hostname (was $old)"
8
+ sed -i "s@\..*\$@@" /etc/hostname
9
+ hostname -F /etc/hostname
10
+ new=`cat /etc/hostname`
11
+ echo "(now $new)"
12
+ if [ -z "`grep "$old" /etc/hosts`" ]; then
13
+ echo "Adding '127.0.1.1 $old $new' entry to /etc/hosts"
14
+ echo "127.0.1.1 $old $new" >> /etc/hosts
15
+ fi
16
+ ;;
17
+ esac
18
+
19
+ for f in bootstrap-salt.log bootstrap_salt.sh
20
+ do
21
+ rm -f /tmp/$f.old
22
+ if [ -f /tmp/$f ]; then
23
+ echo Renaming /tmp/$f as /tmp/$f.old
24
+ mv /tmp/$f /tmp/$f.old
25
+ fi
26
+ done
@@ -1,8 +1,14 @@
1
1
  #!/bin/bash
2
2
 
3
+ no_check=false
3
4
  case "$1" in
4
- run)
5
- shift
5
+ --no-check)
6
+ no_check=true
7
+ shift
8
+ ;;
9
+ esac
10
+ runit()
11
+ {
6
12
  case "$#" in
7
13
  0)
8
14
  echo "Running all states ..."
@@ -16,6 +22,33 @@ run)
16
22
  done
17
23
  ;;
18
24
  esac
25
+ }
26
+ case "$1" in
27
+ run)
28
+ shift
29
+ if $no_check; then
30
+ # Color is used when there is no checking (piped output)
31
+ runit "$@"
32
+ exit
33
+ fi
34
+ runit "$@" 2>&1 | tee /tmp/t$$
35
+ echo
36
+ echo Checking results log:
37
+ ret=
38
+ if egrep '^\[ERROR *\]' /tmp/t$$; then
39
+ echo ERROR: `egrep '^\[ERROR *\]' /tmp/t$$ | wc -l` ERRORS FOUND IN LOG
40
+ ret=1
41
+ fi
42
+ if egrep '^ *Result: *False' /tmp/t$$ > /dev/null; then
43
+ echo 'WARNING (' `egrep '^ *Result: *False' /tmp/t$$ | wc -l` 'Results where False in log)'
44
+ ret=${ret:-2}
45
+ fi
46
+ if [ -z "$ret" ] ; then
47
+ echo SUCCESS
48
+ fi
49
+ rm -f /tmp/t$$
50
+ exit $ret
51
+
19
52
  ;;
20
53
  grains)
21
54
  sudo salt-call grains.items
@@ -26,11 +59,15 @@ pillar)
26
59
  packages)
27
60
  dpkg --get-selections | sed -n 's/\s\s*install//p'
28
61
  ;;
62
+ search)
63
+ aptitude search "$@"
64
+ #apt-cache search "$@"
65
+ ;;
29
66
  install|remove|purge|update|upgrade|clean|autoremove)
30
67
  sudo apt-get "$@"
31
68
  ;;
32
69
  *)
33
- echo "usage: $0 grains|pillar|run [state]|packages|install package|remove package|purge package|autoclean|autoremove\n"
70
+ echo "usage: $0 grains|pillar|run [state]|packages|search|install package|remove package|purge package|autoclean|autoremove\n"
34
71
  ;;
35
72
  esac
36
73