#!/usr/bin/env ruby # # Author: Waldemar Hummer (hummer@infosys.tuwien.ac.at) # # some global/constant variables REQUIRED_CONFIGS = {"db.host" => "Database host"} ROOT_DIR = File.join(File.dirname(File.expand_path(__FILE__)), "..") # call bundler require "rubygems" require "bundler/setup" # bug fix for ruby 1.9+ require 'dl/import' DL::Importable = DL::Importer Bundler.require(:default) # requires $LOAD_PATH << File.join(ROOT_DIR, "lib") require "toaster/api.rb" # 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