osquery_name = node['osquery']['rpm']['name']

remote_file "#{Chef::Config[:file_cache_path]}/#{osquery_name}" do
  action :create_if_missing
  retries node['osquery']['rpm']['retries']
  source node['osquery']['rpm']['link']
end

execute 'unpack_osquery' do
  command "rpm -ivh #{Chef::Config[:file_cache_path]}/#{osquery_name}"
  not_if 'rpm -qa | grep osquery'
end

package 'osquery' do
  not_if "yum list installed | grep osquery | grep #{node['osquery']['version']}"
  notifies :create, 'template[/etc/osquery/osquery.conf]', :immediately
end

template '/etc/osquery/osquery.conf' do
  source 'osquery/osquery.conf.erb'
  action :nothing
end

service 'osqueryd' do
  action [:enable, :start]
  supports 'status' => true
end
