class Exploitdb < Formula
  desc "Database of public exploits and corresponding vulnerable software"
  homepage "https://www.exploit-db.com/"
  url "https://github.com/offensive-security/exploitdb.git",
      tag:      "2022-05-18",
      revision: "cbee98ca482d81e3f88311a561cce55fba9fa72d"
  version "2022-05-18"
  license "GPL-2.0-or-later"
  head "https://github.com/offensive-security/exploitdb.git", branch: "master"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_monterey: "838f926a90ea3ebe08feb6bcdce8d8b41a3bdd33dc53aea3d5790a358362f52e"
    sha256 cellar: :any_skip_relocation, arm64_big_sur:  "777018427285e3d02f9a36dc553700f207a40353fca29e9d64acfa187236469a"
    sha256 cellar: :any_skip_relocation, monterey:       "bd9a6eba220ffc93165000ff8b2000a324f8487e6421f7e0d1a5a53cc990887f"
    sha256 cellar: :any_skip_relocation, big_sur:        "66501ca6cd9103979ed738dd6af25b91453763501d31988eb10cbed49a9532eb"
    sha256 cellar: :any_skip_relocation, catalina:       "e95e02b03817c4b809d7c1428cfd057681e348aa0b04ccda84f2a529b91437e6"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "f21077b02df92d436261d75c8dba2c829534d4731b989da163113b02a9876295"
  end

  def install
    inreplace "searchsploit",
              "rc_file=\"\"", "rc_file=\"#{etc}/searchsploit_rc\""

    optpath = opt_share/"exploitdb"
    inreplace ".searchsploit_rc" do |s|
      s.gsub! "\"/opt/exploitdb\"", optpath
      s.gsub! "\"/opt/exploitdb-papers\"", "#{optpath}-papers"
    end

    bin.install "searchsploit"
    etc.install ".searchsploit_rc" => "searchsploit_rc"

    pkgshare.install %w[.git exploits files_exploits.csv files_shellcodes.csv
                        shellcodes]
  end

  test do
    system "#{bin}/searchsploit", "sendpage"
  end
end
