Module: Aws::Cfn::Stacker::Prerequisites
- Defined in:
- lib/aws/cfn/stacker/mixins/prerequisites.rb
Instance Attribute Summary collapse
-
#checkRuby ⇒ Object
readonly
—————————————————————————–.
Instance Method Summary collapse
-
#askForChefRuby(must_chef = true) ⇒ Object
—————————————————————————–.
-
#checkOS ⇒ Object
—————————————————————————–.
-
#findChefRuby ⇒ Object
—————————————————————————–.
-
#getChefPath(logger) ⇒ Object
—————————————————————————–.
- #getTmpDir ⇒ Object
-
#installChef ⇒ Object
—————————————————————————–.
-
#yieldChefRuby(&block) ⇒ Object
—————————————————————————–.
Instance Attribute Details
#checkRuby ⇒ Object (readonly)
74 75 76 |
# File 'lib/aws/cfn/stacker/mixins/prerequisites.rb', line 74 def checkRuby @checkRuby end |
Instance Method Details
#askForChefRuby(must_chef = true) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/aws/cfn/stacker/mixins/prerequisites.rb', line 41 def askForChefRuby(must_chef=true) return unless must_chef = File.(getChefPath(false)+"/../embedded/bin") puts "Please reissue the command as follows: " aCmd = ["#{}/ruby", $0] aCmd << ARGV.dup aCmd.flatten! puts aCmd.join(' ') exit -1 end |
#checkOS ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/aws/cfn/stacker/mixins/prerequisites.rb', line 18 def checkOS() require 'rbconfig' #OS.mac? unless RbConfig::CONFIG['host_os'] =~ %r/darwin/ raise ::Aws::Cfn::Stacker::Errors::SetupError.new("Sorry! Your OS platform (#{RUBY_PLATFORM}) is not yet supported (as of 2014/06/16)!") end end |
#findChefRuby ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/aws/cfn/stacker/mixins/prerequisites.rb', line 53 def findChefRuby() = File.(getChefPath(false)+"/../embedded/bin") = "#{}/ruby" if File.executable?() ruby_version = "\x1b[$38;5;1m"+%x(#{} -v 2>/dev/null)+"\x1b[0m" # .gsub(%r/\s+/, '') puts "You have a Chef embedded Ruby ... #{ruby_version} ...\n\nYou should place it on the PATH (export PATH=#{}#{File::PATH_SEPARATOR}$PATH) or use it directly." return 0 end 1 end |
#getChefPath(logger) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/aws/cfn/stacker/mixins/prerequisites.rb', line 27 def getChefPath(logger) chef = %x(which chef-solo 2>/dev/null).gsub(%r/\s+/, '') unless chef == '' logger.debug "Found chef-solo: '#{chef}'" if logger if File.symlink?(chef) chef = File.readlink(chef) end stat = File.stat(chef) chef = File.dirname(chef) end chef end |
#getTmpDir ⇒ Object
10 11 12 13 14 15 |
# File 'lib/aws/cfn/stacker/mixins/prerequisites.rb', line 10 def getTmpDir unless @TMPDIR @TMPDIR = ENV.key?('TMPDIR') ? ENV['TMPDIR'] : '/tmp/' end @TMPDIR end |
#installChef ⇒ Object
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 |
# File 'lib/aws/cfn/stacker/mixins/prerequisites.rb', line 118 def installChef() STDOUT.sync = true STDERR.sync = true #logger = getLogger(ARGV.hash) chef_installer = 'chef-11.6.0_1.mac_os_x.10.7.2.sh' tmp = getTmpDir() url = "https://opscode-omnibus-packages.s3.amazonaws.com/mac_os_x/10.7/x86_64/#{chef_installer}" puts "Installing Chef 11.6.0_1 from #{url}" aCmd = [ 'curl', '--silent', '-o', "#{tmp}/#{chef_installer}", "-L", url ] puts aCmd.join(' ') #rc = executeTask( aCmd, { :rc => 0, :msg => 'Success' }, [] ) cond = { :logit => true, :rc => 0, :msg => 'Success', } pid = fork do ret = system(aCmd.join(' ')) #logger.debug "[child] system(): #{ret}" exit ret === true ? 0 : -1 end pid,status = Process.waitpid2(pid) rc = status.exitstatus if rc != 0 cond[:msg] = "The uninstaller did not complete or did not succeed possibly because administrative privileges were not authorized." end raise ::Aws::Cfn::Stacker::Errors::SetupError.new("Sorry, cannot download Chef installer") unless rc == 0 puts "\nI am going to execute a sudo command now: 'sudo #{tmp}/#{chef_installer}'\nPlease type your sudo password when prompted!\n" aCmd = [ 'sudo', 'bash', "#{tmp}/#{chef_installer}" ] puts aCmd.join(' ') ENV.delete('GEM_PATH') ENV.delete('GEM_HOME') #rc = executeTask( aCmd, { :rc => 0, :msg => 'Success' }, [] ) cond = { :logit => true, :rc => 0, :msg => 'Success', } pid = fork do ret = system(aCmd.join(' ')) #logger.debug "[child] system(): #{ret}" exit ret === true ? 0 : -1 end pid,status = Process.waitpid2(pid) rc = status.exitstatus if rc != 0 cond[:msg] = "The uninstaller did not complete or did not succeed possibly because administrative privileges were not authorized." end raise ::Aws::Cfn::Stacker::Errors::SetupError.new("Sorry, cannot install Chef") unless rc == 0 # Get control back of this new installation puts "We use sudo and may ask you for your password ..." puts %x(sudo chown -R #{ENV['USER']} /opt/chef) puts %x(sudo chmod -R u+w /opt/chef) rc end |
#yieldChefRuby(&block) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/aws/cfn/stacker/mixins/prerequisites.rb', line 65 def yieldChefRuby(&block) if 0 == findChefRuby() askForChefRuby(false) else yield end end |