Class: IpfixerClient::Installer
- Inherits:
-
Object
- Object
- IpfixerClient::Installer
- Includes:
- Win32
- Defined in:
- lib/ipfixer_client/installer.rb
Instance Method Summary collapse
-
#construct_service_execution_string(ruby, gem_path) ⇒ Object
this string is the argument for the service Example: ‘c:Rubybinruby.exe -C c:temp ruby_example_service.rb’.
- #create_installation_files(target_folder, config = nil) ⇒ Object
-
#get_ipfixer_bin_path ⇒ Object
This is how I get the path of the ipfixer script in the bin/ folder.
- #get_root_of_gem ⇒ Object
-
#get_ruby_interpreter_path ⇒ Object
The finds out where the ruby interpretr is on the system.
- #get_target_folder ⇒ Object
-
#initialize ⇒ Installer
constructor
A new instance of Installer.
- #install(service_name = SERVICE_NAME, target_folder = 'c:\it\ipfixer') ⇒ Object
- #prompt_for_ddns_url ⇒ Object
-
#prompt_for_information ⇒ Object
this method prompts the user for a few pieces of information.
- #prompt_for_installation_folder ⇒ Object
- #prompt_for_port(default_port = "80") ⇒ Object
- #prompt_for_security_token ⇒ Object
- #prompt_for_target_server ⇒ Object
- #service_installed?(service_name) ⇒ Boolean
- #service_marked_for_deletion?(service_name) ⇒ Boolean
- #service_started?(service_name) ⇒ Boolean
- #start(service_name = SERVICE_NAME) ⇒ Object
- #stop(service_name = SERVICE_NAME) ⇒ Object
- #uninstall(service_name = SERVICE_NAME) ⇒ Object
-
#update_yml_file(target_folder, config) ⇒ Object
writes a new yaml file out of the data entered, unless there was no data entered, in which case it will leave that yaml file untouched and with full comments.…
Constructor Details
#initialize ⇒ Installer
Returns a new instance of Installer.
12 13 |
# File 'lib/ipfixer_client/installer.rb', line 12 def initialize end |
Instance Method Details
#construct_service_execution_string(ruby, gem_path) ⇒ Object
this string is the argument for the service Example: ‘c:Rubybinruby.exe -C c:temp ruby_example_service.rb’
95 96 97 |
# File 'lib/ipfixer_client/installer.rb', line 95 def construct_service_execution_string(ruby, gem_path) "#{ruby} -C #{gem_path} ipfixer client_svc" end |
#create_installation_files(target_folder, config = nil) ⇒ Object
69 70 71 72 73 |
# File 'lib/ipfixer_client/installer.rb', line 69 def create_installation_files(target_folder, config = nil) FileUtils.mkdir_p "#{target_folder}/conf" FileUtils.cp "#{get_root_of_gem}/conf/config.yml", "#{target_folder}/conf/config.yml" update_yml_file(target_folder, config) end |
#get_ipfixer_bin_path ⇒ Object
This is how I get the path of the ipfixer script in the bin/ folder
89 90 91 |
# File 'lib/ipfixer_client/installer.rb', line 89 def get_ipfixer_bin_path Gem.bin_path('ipfixer_client', 'ipfixer').gsub(/.ipfixer$/,'') end |
#get_root_of_gem ⇒ Object
75 76 77 78 |
# File 'lib/ipfixer_client/installer.rb', line 75 def get_root_of_gem dir_name = File.dirname(__FILE__) File. Dir.new("#{dir_name}/../..").path end |
#get_ruby_interpreter_path ⇒ Object
The finds out where the ruby interpretr is on the system.
84 85 86 |
# File 'lib/ipfixer_client/installer.rb', line 84 def get_ruby_interpreter_path File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"]) end |
#get_target_folder ⇒ Object
48 49 50 |
# File 'lib/ipfixer_client/installer.rb', line 48 def get_target_folder return "" # FIXME: logic end |
#install(service_name = SERVICE_NAME, target_folder = 'c:\it\ipfixer') ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ipfixer_client/installer.rb', line 15 def install(service_name = SERVICE_NAME, target_folder = 'c:\it\ipfixer') uninstall(service_name) # uninstalls service if it's already installed ruby = get_ruby_interpreter_path gem_path = get_ipfixer_bin_path service_command_line = construct_service_execution_string(ruby, gem_path) config = prompt_for_information create_installation_files(target_folder, config) if WINDOWS # Create a new service Service.create({ :service_name => service_name, :service_type => Service::WIN32_OWN_PROCESS, :description => SERVICE_DESC, :start_type => Service::AUTO_START, :error_control => Service::ERROR_NORMAL, :binary_path_name => service_command_line, :load_order_group => 'Network', :dependencies => ['W32Time','Schedule', 'RpcSs'], :display_name => service_name }) elsif LINUX # FIXME: Add a linux routine end #`sc start ipfixer_svc` end |
#prompt_for_ddns_url ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/ipfixer_client/installer.rb', line 148 def prompt_for_ddns_url puts "If you have a ddns direct URL to set your IP address, you may specify that now, else hit enter" puts "ex: www.example.com/ipsetter.php?lkajsdflkjsdf" input = STDIN.gets.chomp if input == "" return nil else return input end end |
#prompt_for_information ⇒ Object
this method prompts the user for a few pieces of information
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ipfixer_client/installer.rb', line 100 def prompt_for_information target_server = prompt_for_target_server port = prompt_for_port((target_server =~ /^https:\/\//).nil? ? "80" : "443") ddns_update_url = prompt_for_ddns_url security_token = prompt_for_security_token config = {'target_server' => target_server, 'port' => port, 'ddns_update_url' => ddns_update_url, 'security_token' => security_token } return config end |
#prompt_for_installation_folder ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/ipfixer_client/installer.rb', line 113 def prompt_for_installation_folder puts "Please specify an installation directory, or hit enter for default 'c:\\it\\ipfixer'" input = STDIN.gets.chomp if input == "" return 'c:\it\ipfixer' else return input end end |
#prompt_for_port(default_port = "80") ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ipfixer_client/installer.rb', line 136 def prompt_for_port(default_port = "80") puts "Please specify a port" puts "[#{default_port}]" input = STDIN.gets.chomp if input == "" return default_port else return input.to_i end end |
#prompt_for_security_token ⇒ Object
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/ipfixer_client/installer.rb', line 160 def prompt_for_security_token puts "If you'd like, you can specify a security token that ipfixer will use to authenticate with the ipfixes server" puts "ex: 'secret pass'" input = STDIN.gets.chomp if input == "" "secret pass" else input end end |
#prompt_for_target_server ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ipfixer_client/installer.rb', line 124 def prompt_for_target_server puts "Please specify a target server name" puts "[192.168.0.11]" input = STDIN.gets.chomp if input == "" return nil else return input end end |
#service_installed?(service_name) ⇒ Boolean
171 172 173 174 175 176 177 178 179 |
# File 'lib/ipfixer_client/installer.rb', line 171 def service_installed?(service_name) if WINDOWS return `sc query #{service_name}` =~ /FAILED 1060/i ? false : true end if LINUX # FIXME: write logic return true end end |
#service_marked_for_deletion?(service_name) ⇒ Boolean
186 187 188 189 |
# File 'lib/ipfixer_client/installer.rb', line 186 def service_marked_for_deletion?(service_name) return `sc query #{service_name} | grep STATE` =~ /STOPPED/i ? false : true if WINDOWS return true if LINUX # FIXME: write logic end |
#service_started?(service_name) ⇒ Boolean
181 182 183 184 |
# File 'lib/ipfixer_client/installer.rb', line 181 def service_started?(service_name) return `sc query #{service_name} | grep STATE` =~ /STOPPED/i ? false : true if WINDOWS return true if LINUX # FIXME: write logic end |
#start(service_name = SERVICE_NAME) ⇒ Object
61 62 63 |
# File 'lib/ipfixer_client/installer.rb', line 61 def start(service_name = SERVICE_NAME) Service.start(service_name) end |
#stop(service_name = SERVICE_NAME) ⇒ Object
65 66 67 |
# File 'lib/ipfixer_client/installer.rb', line 65 def stop(service_name = SERVICE_NAME) Service.stop(service_name) end |
#uninstall(service_name = SERVICE_NAME) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/ipfixer_client/installer.rb', line 52 def uninstall(service_name = SERVICE_NAME) # stop the service if it's started # stop if service_started? service_name # if the service is marked for deletion, do nothing here #return if service_marked_for_deletion? service_name Service.delete(service_name) if service_installed? service_name if WINDOWS # FIXME: write linux logic end |
#update_yml_file(target_folder, config) ⇒ Object
writes a new yaml file out of the data entered, unless there was no data entered, in which case it will leave that yaml file untouched and with full comments.…
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/ipfixer_client/installer.rb', line 193 def update_yml_file(target_folder, config) return if config.nil? target_server = config['target_server'] port = config['port'] ddns_update_url = config['ddns_update_url'] #require 'pry';binding.pry config = YAML.load_file(target_folder + '/conf/config.yml') # "C:\\it\\ipfixer\\conf\\config.yml" config['target_server'] = target_server unless target_server.nil? config['port'] = port unless port.nil? config['ddns_update_url'] = ddns_update_url unless ddns_update_url.nil? File.open(target_folder + '/conf/config.yml', "w") {|f| f.write(config.to_yaml) } end |