Commit 940e772900
Verified · cmc
Layout: unified · split
Formula/ambient-companions.rb added +70
| @@ -0,0 +1,70 @@ | ||
| 1 | class AmbientCompanions < Formula | |
| 2 | desc "Ambient system companions over one privacy-preserving signal daemon" | |
| 3 | homepage "https://gitbay.org/krz/ambient-companions" | |
| 4 | url "https://gitbay.org/krz/ambient-companions.git", | |
| 5 | tag: "v0.6.1", | |
| 6 | revision: "e8edd54d8ff674b8d3c12b2d6e8aba5e2b477067" | |
| 7 | license "0BSD" | |
| 8 | head "https://gitbay.org/krz/ambient-companions.git", branch: "main" | |
| 9 | ||
| 10 | depends_on "rust" => :build | |
| 11 | # macos-collector is a SwiftPM package; swift-tools-version 5.9 needs Xcode 15. | |
| 12 | depends_on xcode: ["15.0", :build] | |
| 13 | depends_on :macos | |
| 14 | ||
| 15 | def install | |
| 16 | system "cargo", "install", *std_cargo_args(path: "crates/signald") | |
| 17 | system "cargo", "install", *std_cargo_args(path: "crates/terminal-garden") | |
| 18 | ||
| 19 | # The IOKit collector runs out of process as a child of signald. | |
| 20 | # --disable-sandbox: SwiftPM sandboxes its own manifest compile, and that | |
| 21 | # sandbox_apply fails inside Homebrew's build sandbox. Homebrew's is still | |
| 22 | # in force around the whole build. | |
| 23 | system "swift", "build", "-c", "release", "--disable-sandbox", | |
| 24 | "--package-path", "macos-collector", | |
| 25 | "--scratch-path", buildpath/"swift-build" | |
| 26 | bin.install buildpath/"swift-build/release/macos-collector" | |
| 27 | ||
| 28 | # Sourced from the user's .zshrc; see the README install section. | |
| 29 | pkgshare.install "shell-hooks/signald-hooks.zsh" | |
| 30 | # The launchd template, for a manual install. `brew services` uses the | |
| 31 | # service block below instead. | |
| 32 | pkgshare.install "packaging/net.krz.signald.plist" | |
| 33 | end | |
| 34 | ||
| 35 | service do | |
| 36 | # Repositories to watch come from ~/.config/signald/repos — launchd starts | |
| 37 | # an agent in /, so there is no useful working directory to fall back on. | |
| 38 | run [opt_bin/"signald", "--collector", opt_bin/"macos-collector"] | |
| 39 | keep_alive true | |
| 40 | run_type :immediate | |
| 41 | log_path var/"log/signald.log" | |
| 42 | error_log_path var/"log/signald.err.log" | |
| 43 | end | |
| 44 | ||
| 45 | def caveats | |
| 46 | <<~EOS | |
| 47 | Name the repositories to watch, one path per line: | |
| 48 | mkdir -p ~/.config/signald | |
| 49 | echo ~/git/some-repo > ~/.config/signald/repos | |
| 50 | brew services restart ambient-companions | |
| 51 | ||
| 52 | Then source the terminal collector hooks from your .zshrc: | |
| 53 | source "#{opt_pkgshare}/signald-hooks.zsh" | |
| 54 | EOS | |
| 55 | end | |
| 56 | ||
| 57 | test do | |
| 58 | assert_match version.to_s, shell_output("#{bin}/signald --version") | |
| 59 | assert_match version.to_s, shell_output("#{bin}/terminal-garden --version") | |
| 60 | # Unknown options exit 2 rather than being taken for a repository path. | |
| 61 | shell_output("#{bin}/signald --nonexistent-option 2>&1", 2) | |
| 62 | # One real IOKit read, no root. --once writes raw wire frames to stdout and | |
| 63 | # the human summary to stderr, so capture stderr alone: folding the binary | |
| 64 | # in with 2>&1 hands Ruby a string that is not valid UTF-8. | |
| 65 | assert_match "cpu_load", shell_output("#{bin}/macos-collector --once 2>&1 >/dev/null") | |
| 66 | # --hex is the same tick as ASCII: v4 frames, 25 bytes each. | |
| 67 | hex = shell_output("#{bin}/macos-collector --once --hex 2>/dev/null") | |
| 68 | assert_match(/^1500000004[0-9a-f]{40}$/, hex.lines.first.chomp) | |
| 69 | end | |
| 70 | end | |