Sha256: ce1e298bb9015665e582f63830736359ed42cd4f998d1635c27c5bfc3cf9807d

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

#!/usr/bin/env ruby
require "rubygems"
require 'optparse'
require 'fileutils'

# Cross-platform way of finding an executable in the $PATH. (stolen from hub)
#
#   which('ruby') #=> /usr/bin/ruby
def which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each { |ext|
      exe = "#{path}/#{cmd}#{ext}"
      return exe if File.executable? exe
    }
  end
  return nil
end

def install_chef
  puts "You don't seem to have chef, installing it for you"
  script_name = "install.sh"
  command = [
    "curl -L -o /tmp/#{script_name} https://www.opscode.com/chef/#{script_name}",
    "sudo bash /tmp/#{script_name} -v 10.24.0"
  ]
  system command.join(" && ")
  which('chef-solo')
end

opt_parser = OptionParser.new do |opt|
  opt.banner = "Usage: megalodon {-h} [install|update_vhosts]"
  opt.on("-h","--help","help") do
    puts opt_parser
    exit
  end
end

# Parse the command line.
opt_parser.parse!

case ARGV[0]
  when 'update_vhosts'
    runlist = 'run_vhosts.json'
  when 'install', nil
    runlist = 'run_list.json'
  else
    puts opt_parser
    exit
end

# Create the databag directory here since it appears that the chef-solo run
# will fail if it doesn't already exist. Wish there was a better way to do this…
directory_name = "#{ENV['HOME']}/.megalodon/data_bags/vhosts"
FileUtils.mkdir_p(directory_name) unless FileTest::directory?(directory_name)

megalodon_path = File.expand_path("../../", __FILE__)

chef_solo = which('chef-solo') || install_chef

unless chef_solo
  raise "Cannot find chef-solo!}"
end

puts "Copying custom forumulas"
system("cp #{megalodon_path}/formulas/* /usr/local/Library/Formula/")
puts "Starting chef-solo run"
system("#{chef_solo} -j #{megalodon_path}/config/#{runlist} -c #{megalodon_path}/config/solo.rb")

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
megalodon-0.1.1 bin/megalodon
megalodon-0.1.0 bin/megalodon