#!/usr/bin/env ruby
require 'rubygems'
require 'kafo'

# base the answer file name on the file calling the
# script.  This allows other programs to use their own
# files if named based on their executable
config_filename = File.basename($0) + ".yaml"

# where to find answer file
if File.exist?('config/' + config_filename)
  CONFIG_FILE = 'config/' + config_filename   
  else
    CONFIG_FILE = '/etc/foreman/' + config_filename
    end

# Run the install
result = Kafo::KafoConfigure.run

# handle exit code when help was invoked or installer ended with '2' (success in puppet)
if @result.nil? || (!@result.config.app[:detailed_exitcodes] && @result.exit_code == 2)
  exit(0)
else
  exit(@result.exit_code)
end
