# This recipe is only used by files/default/chef-client/localhost.json
# It is mapped copied into /etc/chef/nodes/localhost.json and
# invoked by chef-client

# Fetch snort rules from internal sources
internal_rules_url = node['snort']['internal_rules_url']
internal_emerging_rules_url = node['snort']['internal_emerging_rules_url']

# Force nginx to start/enable service
node.set['nginx']['service_actions'] = [:enable, :start]

# Do not call oinkmaster script at boot, as it takes a lot of time
# As a consequence, snort will not start (otherwise it will fail,
# since unable to resolve rules)
# To workaround it, we disable oinkmaster and snort run during run-chef-client,
# though salty-init (Cloudinit User Data) will invoke /usr/local/bin/reload-snort.sh
# after Alfresco has booted
node.set['snort']['oinkmaster']['download_rules'] = false
node.set['snort']['start_snort'] = false

# Override snort rules to define internal ones, if provided
if internal_rules_url && internal_emerging_rules_url
  node.set['snort']['oinkmaster']['rules'] = [
    {
      'path' => '/etc/snort/snortrules-snapshot-2970.tar.gz',
      'url' => internal_rules_url
    },
    {
      'path' => '/etc/snort/emerging.rules.tar.gz',
      'url' => internal_emerging_rules_url
    }
  ]
end

directory node['libreoffice']['command']['user_installation_path'] do
  recursive true
  action :delete
end

include_recipe 'img-trials::cloudwatch-logs-agent-conf'
include_recipe 'img-basic::cloudwatch-logs-agent'
include_recipe 'alfresco::redeploy'
include_recipe 'img-basic::configure-services'

# TODO: - this should be ALWAYS done at bootstrap, but never within the images
execute 'remove-centos-user' do
  command 'userdel -f centos && rm -rf /home/centos'
  only_if 'cat /etc/passwd | grep centos'
end
