Sha256: bb3a525357204c05569a08644779f8cf000f4b22746ccf613539ba3591897cfe

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 KB

Contents

#!/usr/bin/env ruby

#
# Author: Waldemar Hummer (hummer@infosys.tuwien.ac.at)
# 

# some global/constant variables
ROOT_DIR = File.join(File.dirname(File.expand_path(__FILE__)), "..")
REQUIRED_CONFIGS = {
  #"db.host" => "Database host"
}
$LOAD_PATH << File.join(ROOT_DIR, "lib")

# load dependencies using Bundler
require "toaster/util/load_bundler"

# requires
require "toaster/api"

# util functions
def install_chef()
  existing = `which chef-solo 2> /dev/null`
  existing = existing.strip
  if existing == ""
    puts "INFO: Installing required gem 'chef'"
    system("gem install chef --no-ri --no-rdoc")
  end
end
def init_config_file()
  require 'json'
  require 'toaster/util/config'
  included = false
  config_file = "#{Dir.home}/.toaster"
  if !File.exist?(config_file)
    require 'toaster/util/util'
    included = true
    Toaster::Util.write(config_file, "{}")
  end
  configs = JSON.parse(File.read(config_file))
  REQUIRED_CONFIGS.each do |conf_key,conf_text|
    val = Toaster::Config.get(conf_key, configs)
    if !val
      if !included
        require 'toaster/util/util'
      end
      print "Enter '#{conf_key}' (#{conf_text}): "
      $stdout.flush
      input = $stdin.gets().strip() # read config from stdin
      Toaster::Config.set(conf_key, input, configs)
      Toaster::Config.set(conf_key, input)
      Toaster::Util.write(config_file, JSON.pretty_generate(configs), true)
    else
      if ARGV.include?("-v")
        puts "DEBUG: Using config value '#{conf_key}' = '#{val}'"
      end
    end
  end
  return configs
end
def create_chef_config()
  solo_file = Toaster::ToasterApp::CHEF_TMP_SOLO_FILE
  if !File.exist?(solo_file)
    require "toaster/chef/chef_util"
    Toaster::ChefUtil.create_chef_config(solo_file)
  end
end

# make sure config values are present
init_config_file()

# make sure chef is installed
install_chef()

# create Chef config file
create_chef_config()

# run main app
Toaster::ToasterApp.start

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cloud-toaster-1.1.6 bin/toaster
cloud-toaster-1.1.5 bin/toaster