<commit_before>require 'formula'

class Elasticsearch < Formula
  url 'https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.18.3.tar.gz'
  homepage 'http://www.elasticsearch.org'
  md5 '56a56fe47402de2c8e19d14d5f53efa4'

  def cluster_name
    "elasticsearch_#{ENV['USER']}"
  end

  def install
    # Remove Windows files
    rm_f Dir["bin/*.bat"]
    # Move JARs from lib to libexec according to homebrew conventions
    libexec.install Dir['lib/*.jar']
    (libexec+'sigar').install Dir['lib/sigar/*.jar']

    # Install everything directly into folder
    prefix.install Dir['*']

    # Set up ElasticSearch for local development:
    inreplace "#{prefix}/config/elasticsearch.yml" do |s|

      # 1. Give the cluster a unique name
      s.gsub! /#\s*cluster\.name\: elasticsearch/, "cluster.name: #{cluster_name}"

      # 2. Configure paths
      s.gsub! /#\s*path\.data\: [^\n]+/, "path.data: #{var}/elasticsearch/"
      s.gsub! /#\s*path\.logs\: [^\n]+/, "path.logs: #{var}/log/elasticsearch/"
    end

    inreplace "#{prefix}/bin/elasticsearch.in.sh" do |s|
      # Replace CLASSPATH paths to use libexec instead of lib
      s.gsub! /ES_HOME\/lib\//, "ES_HOME/libexec/"
    end

    inreplace "#{prefix}/bin/elasticsearch" do |s|
      # Set ES_HOME to prefix value
      s.gsub! /^ES_HOME=.*$/, "ES_HOME=#{prefix}"
    end

    # Write .plist file for `launchd`
    (prefix+'org.elasticsearch.plist').write startup_plist
    (prefix+'org.elasticsearch.plist').chmod 0644
  end

  def caveats
    <<-EOS.undent
    If this is your first install, automatically load ElasticSearch on login with:
        mkdir -p ~/Library/LaunchAgents
        ln -nfs #{prefix}/org.elasticsearch.plist ~/Library/LaunchAgents/
        launchctl load -wF ~/Library/LaunchAgents/org.elasticsearch.plist

    If this is an upgrade and you already have the org.elasticsearch.plist loaded:
        launchctl unload -w ~/Library/LaunchAgents/org.elasticsearch.plist
        ln -nfs #{prefix}/org.elasticsearch.plist ~/Library/LaunchAgents/
        launchctl load -wF ~/Library/LaunchAgents/org.elasticsearch.plist

    To stop the ElasticSearch daemon:
        launchctl unload -wF ~/Library/LaunchAgents/org.elasticsearch.plist

    To start ElasticSearch manually:
        elasticsearch -f -D es.config=#{prefix}/config/elasticsearch.yml

    See the 'elasticsearch.yml' file for configuration options.<commit_msg>elasticsearch: fix audit warning<commit_after>require 'formula'

class Elasticsearch < Formula
  url 'https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.18.3.tar.gz'
  homepage 'http://www.elasticsearch.org'
  md5 '56a56fe47402de2c8e19d14d5f53efa4'

  def cluster_name
    "elasticsearch_#{ENV['USER']}"
  end

  def install
    # Remove Windows files
    rm_f Dir["bin/*.bat"]
    # Move JARs from lib to libexec according to homebrew conventions
    libexec.install Dir['lib/*.jar']
    (libexec+'sigar').install Dir['lib/sigar/*.jar']

    # Install everything directly into folder
    prefix.install Dir['*']

    # Set up ElasticSearch for local development:
    inreplace "#{prefix}/config/elasticsearch.yml" do |s|

      # 1. Give the cluster a unique name
      s.gsub! /#\s*cluster\.name\: elasticsearch/, "cluster.name: #{cluster_name}"

      # 2. Configure paths
      s.gsub! /#\s*path\.data\: [^\n]+/, "path.data: #{var}/elasticsearch/"
      s.gsub! /#\s*path\.logs\: [^\n]+/, "path.logs: #{var}/log/elasticsearch/"
    end

    inreplace "#{bin}/elasticsearch.in.sh" do |s|
      # Replace CLASSPATH paths to use libexec instead of lib
      s.gsub! /ES_HOME\/lib\//, "ES_HOME/libexec/"
    end

    inreplace "#{bin}/elasticsearch" do |s|
      # Set ES_HOME to prefix value
      s.gsub! /^ES_HOME=.*$/, "ES_HOME=#{prefix}"
    end

    # Write .plist file for `launchd`
    (prefix+'org.elasticsearch.plist').write startup_plist
    (prefix+'org.elasticsearch.plist').chmod 0644
  end

  def caveats
    <<-EOS.undent
    If this is your first install, automatically load ElasticSearch on login with:
        mkdir -p ~/Library/LaunchAgents
        ln -nfs #{prefix}/org.elasticsearch.plist ~/Library/LaunchAgents/
        launchctl load -wF ~/Library/LaunchAgents/org.elasticsearch.plist

    If this is an upgrade and you already have the org.elasticsearch.plist loaded:
        launchctl unload -w ~/Library/LaunchAgents/org.elasticsearch.plist
        ln -nfs #{prefix}/org.elasticsearch.plist ~/Library/LaunchAgents/
        launchctl load -wF ~/Library/LaunchAgents/org.elasticsearch.plist

    To stop the ElasticSearch daemon:
        launchctl unload -wF ~/Library/LaunchAgents/org.elasticsearch.plist

    To start ElasticSearch manually:
        elasticsearch -f -D es.config=#{prefix}/config/elasticsearch.yml

    See the 'elasticsearch.yml' file for configuration options.
{'fraction_non_alphanumeric': 0.12966398680684396, 'fraction_numerical': 0.012368583797155226, 'mean_word_length': 3.1188455008488964, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3690840', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1556, 'n_words': 388}