rconf 0.6.23 → 0.6.24

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rconf/command.rb CHANGED
@@ -44,6 +44,19 @@ module RightConf
44
44
  res
45
45
  end
46
46
 
47
+ # Execute given command with given arguments using 'sudo'
48
+ #
49
+ # === Parameters
50
+ # command(String):: Command to run
51
+ # args(Array):: Command arguments
52
+ #
53
+ # === Return
54
+ # result(CommandResult):: Result of execution (output and exit status)
55
+ def sudo(*args)
56
+ args = args.unshift('/usr/bin/sudo')
57
+ Command.execute(*args)
58
+ end
59
+
47
60
  # Execute given command on *nix systems
48
61
  #
49
62
  # === Parameters
@@ -202,4 +202,5 @@ module RightConf
202
202
  end
203
203
 
204
204
  # Load all configurators
205
+ Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each { |c| require c }
205
206
  Dir[File.join(File.dirname(__FILE__), 'configurators', '*.rb')].each { |c| require c }
@@ -0,0 +1,97 @@
1
+ # Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide.
2
+ #
3
+ # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
4
+ # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use,
5
+ # reproduction, modification, or disclosure of this program is
6
+ # strictly prohibited. Any use of this program by an authorized
7
+ # licensee is strictly subject to the terms and conditions,
8
+ # including confidentiality obligations, set forth in the applicable
9
+ # License Agreement between RightScale.com, Inc. and
10
+ # the licensee
11
+
12
+ module RightConf
13
+
14
+ class MercurialConfigurator
15
+
16
+ MAC_MERCURIAL_URL = 'http://mercurial.berkwood.com/binaries/Mercurial-1.8.1-py2.6-macosx10.6.zip'
17
+ MAC_MERCURIAL_FILE = 'mercurial-1.8.1_20110310-py2.6-macosx10.6'
18
+
19
+ include Configurator
20
+
21
+ register :mercurial
22
+
23
+ description 'Installs Mercurial'
24
+
25
+ settings :abort_on_failure => 'Whether to abort if Mercurial failed to install (false by default)'
26
+
27
+ # Install Linux Mercurial package
28
+ #
29
+ # === Return
30
+ # true:: Always return true
31
+ def run_linux
32
+ unless mercurial_installed
33
+ opts = { :report => true }.merge(abort_option('Failed to install Mercurial'))
34
+ PackageInstaller.install('mercurial', opts)
35
+ end
36
+ end
37
+
38
+ # Brew does not have a package for mercurial :(
39
+ #
40
+ # === Return
41
+ # true:: Always return true
42
+ def run_darwin
43
+ unless mercurial_installed
44
+ report_check('Installing Mercurial')
45
+ tempdir = File.join(ENV['HOME'], '.rconf', 'temp')
46
+ FileUtils.mkdir_p(tempdir)
47
+ Dir.chdir(tempdir) do
48
+ Command.execute('curl', '-O', '-f', MAC_MERCURIAL_URL,
49
+ abort_option('Failed to download Mercurial'))
50
+ Command.execute('unzip', File.basename(MAC_MERCURIAL_URL),
51
+ abort_option('Failed to unzip Mercurial'))
52
+ end
53
+ Dir.chdir(File.join(tempdir, MAC_MERCURIAL_FILE)) do
54
+ Command.sudo('installer', '-pkg', MAC_MERCURIAL_FILE.gsub('_', '+') + '.mpkg', '-target', '/',
55
+ abort_option('Failed to install Mercurial'))
56
+ end
57
+ report_success
58
+ end
59
+ end
60
+
61
+ # Install Windows software
62
+ #
63
+ # === Return
64
+ # true:: Always return true
65
+ def run_windows
66
+ # TBD
67
+ end
68
+
69
+ protected
70
+
71
+ # Check whether Mercurial is installed
72
+ #
73
+ # === Return
74
+ # true:: If Mercurial is installed
75
+ # false:: Otherwise
76
+ def mercurial_installed
77
+ report_check("Checking for Mercurial")
78
+ installed = Command.execute('hg', '--version').success?
79
+ report_result(installed)
80
+ installed
81
+ end
82
+
83
+ # Produce abort on failure option
84
+ #
85
+ # === Parameters
86
+ # message(String):: Abort message to be used in case abort option should be set
87
+ #
88
+ # === Return
89
+ # {}:: Empty hash if 'abort_on_failure' is notset
90
+ # opts(Hash):: Abort option with give message otherwise
91
+ def abort_option(message)
92
+ opts = abort_on_failure && { :abort_on_failure => message } || {}
93
+ end
94
+
95
+ end
96
+ end
97
+
@@ -22,51 +22,48 @@ module RightConf
22
22
  settings :debian => 'Packages to be installed on Debian based Linux',
23
23
  :centos => 'Packages to be installed on RedHat / Centos',
24
24
  :windows => 'Softwared to be downloaded and installed on Windows',
25
- :mac => 'Brew packages to be installed on Mac OS X (https://github.com/mxcl/homebrew)',
25
+ :darwin => 'Brew packages to be installed on Mac OS X (https://github.com/mxcl/homebrew)',
26
26
  :abort_on_failure => 'Whether to abort if packages failed to install (false by default)'
27
27
 
28
- # Install debian packages
28
+ # Install packages on debian based oses
29
29
  #
30
30
  # === Return
31
31
  # true:: Always return true
32
32
  def run_linux_ubuntu
33
- return if debian.nil?
34
- report_check("Installing the following packages:\n#{debian.join(' ')}\nThis could take a while")
35
- opts = debian.dup
36
- opts << { :abort_on_failure => 'Failed to install packages' } if abort_on_failure
37
- Command.execute('sudo', 'apt-get', 'install', '-y', *opts)
38
- report_success
33
+ PackageInstaller.install(debian, options)
34
+ true
39
35
  end
40
36
  alias :run_linux_debian :run_linux_ubuntu
41
37
 
42
- # Install yum packages
38
+ # Install packages on centos based oses
43
39
  #
44
40
  # === Return
45
41
  # true:: Always return true
46
42
  def run_linux_centos
47
- return if centos.nil?
48
- report_check("Installing the following packages:\n#{centos.join(' ')}\nThis could take a while")
49
- opts = centos.dup
50
- opts << { :abort_on_failure => 'Failed to install packages' } if abort_on_failure
51
- Command.execute('sudo', 'yum', 'install', '-y', *opts)
52
- report_success
43
+ PackageInstaller.install(centos, options)
44
+ true
53
45
  end
54
46
  alias :run_linux_redhat :run_linux_centos
55
47
 
56
- # Install Windows software
48
+ # Install packages on macs
57
49
  #
58
50
  # === Return
59
51
  # true:: Always return true
60
- def run_windows
61
- # TBD
52
+ def run_darwin
53
+ PackageInstaller.install(darwin, options)
54
+ true
62
55
  end
63
56
 
64
- # Use brew on Mac OS X
57
+ protected
58
+
59
+ # Calculate options to be given to installer
65
60
  #
66
61
  # === Return
67
- # true:: Always return true
68
- def run_darwin
69
- # TBD, check brew is installed then use
62
+ # opts(Hash):: Hash of options to be given to installer
63
+ def options
64
+ opts = { :report => true }
65
+ opts.merge!({ :abort_on_failure => 'Failed to install packages' }) if abort_on_failure
66
+ opts
70
67
  end
71
68
 
72
69
  end
@@ -162,7 +162,7 @@ module RightConf
162
162
  if ruby =~ /^ree-|^ruby-/
163
163
  packages = %w(build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev)
164
164
  end # TBD Define packages needed for other rubies
165
- Command.execute('sudo', 'apt-get', 'install', '-y', *packages)
165
+ Command.sudo('apt-get', 'install', '-y', *packages)
166
166
  report_success
167
167
  end
168
168
 
@@ -177,7 +177,7 @@ module RightConf
177
177
  if ruby =~ /^ree-|^ruby-/
178
178
  packages = %w(gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel iconv-devel)
179
179
  end # TBD Define packages needed for other rubies
180
- Command.execute('sudo', 'yum', 'install', '-y', *packages)
180
+ Command.sudo('yum', 'install', '-y', *packages)
181
181
  report_success
182
182
  end
183
183
  alias :install_ruby_prerequesites_linux_redhat :install_ruby_prerequesites_linux_centos
@@ -0,0 +1,62 @@
1
+ # Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide.
2
+ #
3
+ # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
4
+ # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use,
5
+ # reproduction, modification, or disclosure of this program is
6
+ # strictly prohibited. Any use of this program by an authorized
7
+ # licensee is strictly subject to the terms and conditions,
8
+ # including confidentiality obligations, set forth in the applicable
9
+ # License Agreement between RightScale.com, Inc. and
10
+ # the licensee
11
+
12
+ module RightConf
13
+
14
+ class BrewInstaller
15
+
16
+ include ProgressReporter
17
+
18
+ def self.check_and_install
19
+ return true if File.directory?('/usr/local/.git')
20
+ report_check('Installing Homebrew')
21
+
22
+ chmods = %w( . bin etc include lib lib/pkgconfig Library sbin share var share/locale share/man
23
+ share/man/man1 share/man/man2 share/man/man3 share/man/man4
24
+ share/man/man5 share/man/man6 share/man/man7 share/man/man8
25
+ share/info share/doc share/aclocal ).
26
+ map{ |d| "/usr/local/#{d}" }.
27
+ select{ |d| File.directory? d and not File.writable? d }
28
+ chgrps = chmods.reject{ |d| File.stat(d).grpowned? }
29
+
30
+ if File.directory?('/usr/local')
31
+ Command.sudo('/bin/chmod', 'g+w', *chmods) unless chmods.empty?
32
+ # all admin users are in staff
33
+ Command.sudo('/usr/bin/chgrp', 'staff', *chgrps) unless chgrps.empty?
34
+ else
35
+ Command.sudo('/bin/mkdir', '/usr/local')
36
+ Command.sudo('/bin/chmod', 'g+w', '/usr/local')
37
+ # the group is set to wheel by default for some reason
38
+ Command.sudo('/usr/bin/chgrp', 'staff', '/usr/local')
39
+ end
40
+
41
+ Dir.chdir('/usr/local') do
42
+ # -m to stop tar erroring out if it can't modify the mtime for root owned directories
43
+ # pipefail to cause the exit status from curl to propogate if it fails
44
+ system("/bin/bash -o pipefail -c '/usr/bin/curl -sSfL https://github.com/mxcl/homebrew/tarball/master | /usr/bin/tar xz -m --strip 1'")
45
+ end
46
+
47
+ report_success
48
+
49
+ unless chmods.empty?
50
+ report("The following directories had to be made group writable: #{chmods.join(', ')}")
51
+ end
52
+ unless chgrps.empty?
53
+ report("The following directories had their group set to staff: #{chgrps.join(', ')}")
54
+ end
55
+ unless ENV['PATH'].split(':').include? '/usr/local/bin'
56
+ report('/usr/local/bin is not in your PATH.')
57
+ end
58
+ end
59
+
60
+ end
61
+ end
62
+
@@ -0,0 +1,87 @@
1
+ # Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide.
2
+ #
3
+ # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
4
+ # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use,
5
+ # reproduction, modification, or disclosure of this program is
6
+ # strictly prohibited. Any use of this program by an authorized
7
+ # licensee is strictly subject to the terms and conditions,
8
+ # including confidentiality obligations, set forth in the applicable
9
+ # License Agreement between RightScale.com, Inc. and
10
+ # the licensee
11
+
12
+ module RightConf
13
+
14
+ class PackageInstaller
15
+
16
+ include Singleton
17
+ include ProgressReporter
18
+
19
+ # Install given packages
20
+ #
21
+ # === Parameters
22
+ # packages(String|Array):: Package name or Packages list
23
+ # opts[:abort_on_failure](String):: Optional, abort configuration
24
+ # and display given error message if install fails when set
25
+ # opts[:report](TrueClass|FalseClass):: Whether to report installation
26
+ #
27
+ # === Return
28
+ # true:: Always return true
29
+ def install(packages, opts=nil)
30
+ packages = [ packages ].flatten
31
+ report = opts && opts.delete(:report)
32
+ report_check("Installing the following packages:\n#{packages.join(' ')}\nThis could take a while") if report
33
+ Platform.dispatch(packages, opts) { :install }
34
+ report_success if report
35
+ end
36
+
37
+ protected
38
+
39
+ # Install debian packages
40
+ #
41
+ # === Return
42
+ # true:: Always return true
43
+ def install_linux_ubuntu(packages, opts)
44
+ return if packages.nil?
45
+ args = packages.dup
46
+ args << opts if opts
47
+ Command.sudo('apt-get', 'install', '-y', *args)
48
+ end
49
+ alias :install_linux_debian :install_linux_ubuntu
50
+
51
+ # Install yum packages
52
+ #
53
+ # === Return
54
+ # true:: Always return true
55
+ def install_linux_centos(packages, opts)
56
+ return if packages.nil?
57
+ args = packages.dup
58
+ args << opts if opts
59
+ Command.sudo('yum', 'install', '-y', *args)
60
+ end
61
+ alias :install_linux_redhat :install_linux_centos
62
+
63
+ # Use brew on Mac OS X
64
+ #
65
+ # === Return
66
+ # true:: Always return true
67
+ def install_darwin(packages, opts)
68
+ return if packages.nil?
69
+ BrewInstaller.check_and_install
70
+ packages.each do |p|
71
+ args = [ p ]
72
+ args << opts if opts
73
+ Command.execute('brew', 'install', *args)
74
+ end
75
+ end
76
+
77
+ # Install Windows software
78
+ #
79
+ # === Return
80
+ # true:: Always return true
81
+ def install_windows(packages, opts)
82
+ # TBD
83
+ end
84
+
85
+ end
86
+ end
87
+
data/lib/rconf/version.rb CHANGED
@@ -13,7 +13,7 @@ module RightConf
13
13
 
14
14
  MAJOR = 0
15
15
  MINOR = 6
16
- BUILD = 23
16
+ BUILD = 24
17
17
 
18
18
  VERSION = [MAJOR, MINOR, BUILD].map(&:to_s).join('.')
19
19
 
@@ -18,7 +18,7 @@ describe RightConf::PackagesConfigurator do
18
18
  end
19
19
 
20
20
  before(:each) do
21
- lang = RightConf::Language.parse('packages { debian %w(deb1 deb2); centos %w(cent1 cent2) }')
21
+ lang = RightConf::Language.parse('packages { debian %w(deb1 deb2); centos %w(cent1 cent2); darwin %w(mac1 mac2) }')
22
22
  @configurator = lang.configurators.first
23
23
  [:report_check, :report_result, :report_fatal, :report_success].each do |meth|
24
24
  flexmock(@configurator).should_receive(meth)
@@ -26,16 +26,19 @@ describe RightConf::PackagesConfigurator do
26
26
  end
27
27
 
28
28
  it 'should install packages on Ubuntu' do
29
- flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
30
- 'sudo', 'apt-get', 'install', '-y', 'deb1', 'deb2').and_return(success_result)
29
+ flexmock(RightConf::PackageInstaller.instance).should_receive(:install).once.with(%w(deb1 deb2), { :report => true })
31
30
  @configurator.run_linux_ubuntu
32
31
  end
33
32
 
34
33
  it 'should install packages on Centos' do
35
- flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
36
- 'sudo', 'yum', 'install', '-y', 'cent1', 'cent2').and_return(success_result)
34
+ flexmock(RightConf::PackageInstaller.instance).should_receive(:install).once.with(%w(cent1 cent2), { :report => true })
37
35
  @configurator.run_linux_centos
38
36
  end
39
37
 
38
+ it 'should install packages on Darwin' do
39
+ flexmock(RightConf::PackageInstaller.instance).should_receive(:install).once.with(%w(mac1 mac2), { :report => true })
40
+ @configurator.run_darwin
41
+ end
42
+
40
43
  end
41
44
 
@@ -0,0 +1,52 @@
1
+ # Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide.
2
+ #
3
+ # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
4
+ # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use,
5
+ # reproduction, modification, or disclosure of this program is
6
+ # strictly prohibited. Any use of this program by an authorized
7
+ # licensee is strictly subject to the terms and conditions,
8
+ # including confidentiality obligations, set forth in the applicable
9
+ # License Agreement between RightScale.com, Inc. and
10
+ # the licensee
11
+
12
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
13
+
14
+ describe RightConf::PackageInstaller do
15
+
16
+ def success_result(output=nil)
17
+ flexmock('res', :success? => true, :output => output)
18
+ end
19
+
20
+ before(:each) do
21
+ [:report_check, :report_result, :report_fatal, :report_success].each do |meth|
22
+ flexmock(RightConf::PackageInstaller.instance).should_receive(meth)
23
+ end
24
+ end
25
+
26
+ it 'should install packages on Ubuntu' do
27
+ flexmock(RightConf::Platform.instance).should_receive(:family).and_return(:linux)
28
+ flexmock(RightConf::Platform.instance).should_receive(:flavor).and_return('ubuntu')
29
+ flexmock(RightConf::Command.instance).should_receive(:sudo).once.with(
30
+ 'apt-get', 'install', '-y', 'deb1', 'deb2').and_return(success_result)
31
+ RightConf::PackageInstaller.install(['deb1', 'deb2'])
32
+ end
33
+
34
+ it 'should install packages on Centos' do
35
+ flexmock(RightConf::Platform.instance).should_receive(:family).and_return(:linux)
36
+ flexmock(RightConf::Platform.instance).should_receive(:flavor).and_return('centos')
37
+ flexmock(RightConf::Command.instance).should_receive(:sudo).once.with(
38
+ 'yum', 'install', '-y', 'cent1', 'cent2').and_return(success_result)
39
+ RightConf::PackageInstaller.install(['cent1', 'cent2'])
40
+ end
41
+
42
+ it 'should install packages on Darwin' do
43
+ flexmock(RightConf::Platform.instance).should_receive(:family).and_return(:darwin)
44
+ flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
45
+ 'brew', 'install', 'mac1').and_return(success_result)
46
+ flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
47
+ 'brew', 'install', 'mac2').and_return(success_result)
48
+ RightConf::PackageInstaller.install(['mac1', 'mac2'])
49
+ end
50
+
51
+ end
52
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rconf
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.23
5
+ version: 0.6.24
6
6
  platform: ruby
7
7
  authors:
8
8
  - Raphael Simon
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-15 00:00:00 -07:00
13
+ date: 2011-03-20 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -75,6 +75,7 @@ files:
75
75
  - lib/rconf/configurator.rb
76
76
  - lib/rconf/configurator_registry.rb
77
77
  - lib/rconf/configurators/bundler_configurator.rb
78
+ - lib/rconf/configurators/mercurial_configurator.rb
78
79
  - lib/rconf/configurators/packages_configurator.rb
79
80
  - lib/rconf/configurators/passenger_configurator.rb
80
81
  - lib/rconf/configurators/ruby_configurator.rb
@@ -89,6 +90,8 @@ files:
89
90
  - lib/rconf/progress_reporters/file_reporter.rb
90
91
  - lib/rconf/progress_reporters/stdout_reporter.rb
91
92
  - lib/rconf/ruby_extensions.rb
93
+ - lib/rconf/support/brew_installer.rb
94
+ - lib/rconf/support/package_installer.rb
92
95
  - lib/rconf/trollop.rb
93
96
  - lib/rconf/version.rb
94
97
  - rconf.gemspec
@@ -107,6 +110,7 @@ files:
107
110
  - spec/progress_reporters/stdout_reporter_spec.rb
108
111
  - spec/ruby_extensions_spec.rb
109
112
  - spec/spec_helper.rb
113
+ - spec/support/package_installer_spec.rb
110
114
  has_rdoc: true
111
115
  homepage: http://rubygems.org/gems/rconf
112
116
  licenses: []
@@ -150,3 +154,4 @@ test_files:
150
154
  - spec/progress_reporters/stdout_reporter_spec.rb
151
155
  - spec/ruby_extensions_spec.rb
152
156
  - spec/spec_helper.rb
157
+ - spec/support/package_installer_spec.rb