Skip to content

Commit c374cff

Browse files
authored
Merge pull request Homebrew#222388 from IngmarStein/teslamate
teslamate 2.0.0 (new formula)
2 parents aa76491 + 1bdbb5b commit c374cff

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

Formula/t/teslamate.rb

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
class Teslamate < Formula
2+
desc "Self-hosted data logger for your Tesla"
3+
homepage "https://docs.teslamate.org"
4+
url "https://github.com/teslamate-org/teslamate/archive/refs/tags/v2.0.0.tar.gz"
5+
sha256 "fe29dab0dd0b96bafe003b063a7f6f95338d64b26c7187a68bacd2023e423f82"
6+
license "MIT"
7+
8+
bottle do
9+
sha256 cellar: :any, arm64_sequoia: "c27f488a2c39853a4e5e76ac53155facc220eef3b46ea90851bf6304e1ae22d7"
10+
sha256 cellar: :any, arm64_sonoma: "fa6dc5547defabbdfa7bd9eb256b0c98348db96dd889f9f21648898324837e7b"
11+
sha256 cellar: :any, arm64_ventura: "536d6c5b491e86f425b2aac448950b3ee2a2e417d5d33c4b5c683bb22ec5d6ba"
12+
sha256 cellar: :any, sonoma: "3b067615e1568eb81c987aca9908f6efe54332fa8beeae340e985c3aa5a9cec7"
13+
sha256 cellar: :any, ventura: "be0e4f2e27c76e6630b5019b7b702c4323235937f7db265b814bad0b2bb5bfc4"
14+
sha256 cellar: :any_skip_relocation, x86_64_linux: "9efdec2111348468a8e92f7abd3ca5a0f765ae98de1333a18cfae30961c56f8a"
15+
end
16+
17+
depends_on "node" => :build
18+
depends_on "postgresql@17" => :test
19+
depends_on "elixir"
20+
depends_on "erlang"
21+
depends_on "openssl@3"
22+
23+
uses_from_macos "ncurses"
24+
uses_from_macos "zlib"
25+
26+
def install
27+
# See https://docs.teslamate.org/docs/installation/debian/
28+
system "mix", "local.hex", "--force"
29+
system "mix", "local.rebar", "--force"
30+
system "mix", "deps.get", "--only", "prod"
31+
system "npm", "install", "--prefix", "./assets", *std_npm_args(prefix: false)
32+
system "npm", "run", "deploy", "--prefix", "./assets"
33+
34+
with_env("MIX_ENV" => "prod") do
35+
system "mix", "do", "phx.digest,", "release", "--overwrite"
36+
end
37+
38+
touch buildpath/"teslamate.env"
39+
etc.install "teslamate.env"
40+
libexec.install Dir["_build/prod/rel/teslamate/*"]
41+
bin.install_symlink Dir["#{libexec}/bin/teslamate"]
42+
43+
# Corresponds to https://github.com/teslamate-org/teslamate/blob/main/entrypoint.sh
44+
(bin/"teslamate_brew_services").write <<~EOS
45+
#!/bin/bash
46+
set -e
47+
source #{etc}/teslamate.env
48+
#{bin}/teslamate eval "TeslaMate.Release.migrate"
49+
exec #{bin}/teslamate start
50+
EOS
51+
end
52+
53+
service do
54+
run opt_bin/"teslamate_brew_services"
55+
keep_alive true
56+
log_path var/"log/teslamate.log"
57+
error_log_path var/"log/teslamate.log"
58+
working_dir var
59+
end
60+
61+
test do
62+
ENV["LC_ALL"] = "C"
63+
64+
pg_port = free_port
65+
pg_bin = Formula["postgresql@17"].opt_bin
66+
pg_ctl = pg_bin/"pg_ctl"
67+
datadir = testpath/"postgres"
68+
system pg_ctl, "init", "-D", datadir
69+
70+
(datadir/"postgresql.conf").write <<~EOS, mode: "a+"
71+
port = #{pg_port}
72+
unix_socket_directories = '#{datadir}'
73+
EOS
74+
75+
system pg_ctl, "start", "-D", datadir, "-l", testpath/"postgres.log"
76+
begin
77+
system pg_bin/"createdb", "-h", datadir, "-p", pg_port.to_s, "teslamate"
78+
system pg_bin/"createuser", "-h", datadir, "-p", pg_port.to_s, "-s", "teslamate"
79+
80+
# Run Teslamate with the test database
81+
ENV["DATABASE_USER"] = "teslamate"
82+
ENV["DATABASE_PASS"] = ""
83+
ENV["DATABASE_NAME"] = "teslamate"
84+
ENV["DATABASE_HOST"] = "127.0.0.1"
85+
ENV["DATABASE_PORT"] = pg_port.to_s
86+
ENV["DISABLE_MQTT"] = "true"
87+
log_file = testpath/"teslamate_test.log"
88+
File.open(log_file, "w") do |file|
89+
pid = spawn(opt_bin/"teslamate_brew_services", out: file, err: file)
90+
sleep 20
91+
system opt_bin/"teslamate", "stop"
92+
Process.kill("KILL", pid)
93+
Process.wait(pid)
94+
end
95+
output = log_file.read
96+
assert_match "Access TeslaMateWeb.Endpoint at http://localhost", output
97+
ensure
98+
system pg_ctl, "stop", "-D", datadir
99+
end
100+
end
101+
end

0 commit comments

Comments
 (0)