Module: WarCorrespondent::Installer
- Defined in:
- lib/warcorrespondent/installer.rb
Constant Summary collapse
- TEXT_INTRO =
"warcorrespondent could not find your config file and will now guide you\nthrough the setup process.\n\nDo you want to install system-wide (1) or in your home directory(2)? [1]\n"- TEXT_TARGET =
"Where do you want warcorrespondent to report to?\nIf you want to report to warroom, just press enter [http://warroom.tliff.de/reports]\n"- TEXT_SECRET =
"What is the secret this warcorrespondent instance will\nuse to authenticate to warroom?\n"- TEXT_BASIC_SETUP =
"warcorrespondent can now set up basic reporting for this host.\nWould you like to have that set up for you(y/n)[y]?\n"- TEXT_TEMPLATE =
"WarCorrespondent::Reporters::CPU.new(:identifier => 'hosts:@@HOST@@:stats')\nWarCorrespondent::Reporters::LoadAvg.new(:identifier => 'hosts::@@HOST@@:stats')\nWarCorrespondent::Reporters::Memory.new(:identifier => 'hosts::@@HOST@@:stats')\nWarCorrespondent::Reporters::Net.new(:identifier => 'hosts::@@HOST@@:stats')\n"- TEXT_DONE =
"Setup is now complete.\n"
Class Method Summary collapse
Class Method Details
.install ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/warcorrespondent/installer.rb', line 38 def self.install puts TEXT_INTRO basepath = nil while (cmd = gets.strip) && !['1', '2', ''].member?(cmd) do end if cmd == '1' || cmd == '' then basepath = '/etc/warcorrespondent' elsif cmd == '2' basepath = File.('~/.warcorrespondent') end #create the directory if necessary if !File.exists?(basepath) then Dir.mkdir(basepath) end if !File.exists?(basepath+"/reporters") then Dir.mkdir(basepath+"/reporters") end config = {} puts TEXT_TARGET url = gets.strip config['url'] = url.empty? ? "http://warroom.tliff.de/reports" : url puts TEXT_SECRET while (config['secret'] = gets.strip) && config['secret'].empty? do end File.open( "#{basepath}/warcorrespondent.yml", 'w+' ) do |f| YAML.dump(config, f) end puts TEXT_BASIC_SETUP while (cmd = gets.strip) && !['y', 'n', ''].member?(cmd) do end if cmd == 'y' || cmd == '' then hostname = `hostname`.strip File.open("#{basepath}/reporters/basic.rb", "w+") do |f| f.write(TEXT_TEMPLATE.gsub(/@@HOST@@/, hostname)) end end puts TEXT_DONE end |