-
-
Notifications
You must be signed in to change notification settings - Fork 12.5k
/
batt.rb
55 lines (49 loc) · 2.17 KB
/
batt.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Batt < Formula
desc "Control and limit battery charging on Apple Silicon MacBooks"
homepage "https://github.com/charlie0129/batt"
url "https://github.com/charlie0129/batt.git",
tag: "v0.3.3",
revision: "18ce7dfbb6579b98c64d76c8be146f227c7d4be9"
license "GPL-2.0-only"
bottle do
sha256 cellar: :any_skip_relocation, arm64_sequoia: "b7a7a0cc5031183fa22ee855ce3d8af6aeb40cf0d692b3d2d2bb85a6362028c4"
sha256 cellar: :any_skip_relocation, arm64_sonoma: "035188a2bee6279e85f60b3a0a16ea593e667607792c5609914c5bf204a5a3cb"
sha256 cellar: :any_skip_relocation, arm64_ventura: "abde09f1389064095a6d994fb1ef8efda922de83a2683f35bffaaee97e0b3797"
end
depends_on "go" => :build
depends_on arch: :arm64
depends_on :macos
def install
# Point to the correct path for the binary
inreplace "hack/cc.chlc.batt.plist", "/path/to/batt", opt_bin/"batt"
# Limit config path to Homebrew prefix.
system "plutil", "-insert", "ProgramArguments",
"-string", "--config=#{etc}/batt.json", "-append",
"--", "hack/cc.chlc.batt.plist"
# Allow non-root access to the battery controller.
system "plutil", "-insert", "ProgramArguments",
"-string", "--always-allow-non-root-access", "-append",
"--", "hack/cc.chlc.batt.plist"
# Due to local changes version tag would show vx.x.x-dirty, override VERSION.
# GOTAGS is set to disable built-in install/uninstall commands when building for Homebrew.
system "make", "GOTAGS=brew", "VERSION=v#{version}"
bin.install "bin/batt"
prefix.install "hack/cc.chlc.batt.plist"
end
def caveats
<<~EOS
The batt service must be running before most of batt's commands will work.
EOS
end
service do
name macos: "cc.chlc.batt"
require_root true
end
test do
# NB: assumes first run of batt, with no previous config.
assert_match "config file #{etc}/batt.json does not exist, using default config",
shell_output("#{bin}/batt daemon --config=#{etc}/batt.json 2>&1", 1) # Non-root daemon exits with 1
assert_match "failed to connect to unix socket.",
shell_output("#{bin}/batt status 2>&1", 1) # Cannot connect to daemon
end
end