Skip to content

Control a real USB-connected iPhone from Linux (no Mac, no paid developer account) and expose it to AI agents as MCP tools

2.4 KB
Raw Blame
#!/bin/sh
# Prints the Homebrew formula for one release:
#   packaging/homebrew/formula.sh v0.2.1 <sha256 macos-arm64> <sha256 macos-x86_64> <sha256 linux-x86_64> \
#     <sha256 linux-aarch64>
# The formula installs the prebuilt binary from the GitHub release; `brew services start iphone-control` runs the
# daemon (launchd on macOS, systemd on Linux) with the settings in ~/.config/iphone-control/env.
set -eu
[ $# -eq 5 ] || { echo "usage: $0 vX.Y.Z SHA_MACOS_ARM64 SHA_MACOS_X86_64 SHA_LINUX_X86_64 SHA_LINUX_AARCH64" >&2; exit 2; }
tag="$1"
repo="${ICTL_UPDATE_PUBLISHER:?set the release publisher as owner/repo}"
base="https://github.com/$repo/releases/download/$tag/iphone-control-$tag"
cat <<EOF
# Generated by packaging/homebrew/formula.sh in $repo for $tag; don't edit by hand.
class IphoneControl < Formula
  desc "Let AI agents operate a real iPhone or iPad over USB (MCP server and daemon)"
  homepage "https://github.com/$repo"
  license "MIT"

  on_macos do
    depends_on macos: :big_sur
    on_arm do
      url "$base-macos-arm64.tar.gz"
      sha256 "$2"
    end
    on_intel do
      url "$base-macos-x86_64.tar.gz"
      sha256 "$3"
    end
  end

  on_linux do
    on_intel do
      url "$base-linux-x86_64.tar.gz"
      sha256 "$4"
    end
    on_arm do
      url "$base-linux-aarch64.tar.gz"
      sha256 "$5"
    end
  end

  def install
    bin.install "iphone-control"
    pkgshare.install "env.example"
  end

  # Settings come from ~/.config/iphone-control/env, as for the systemd service and install.sh
  service do
    run ["/bin/sh", "-c",
         "set -a; f=\"\$HOME/.config/iphone-control/env\"; [ -f \"\$f\" ] && . \"\$f\"; set +a; " \\
         "exec \"#{opt_bin}/iphone-control\" daemon"]
    keep_alive successful_exit: false
    log_path var/"log/iphone-control.log"
    error_log_path var/"log/iphone-control.log"
  end

  def caveats
    <<~EOS
      Run the daemon in the background (it also starts when you log in):
        brew services start iphone-control
      Then connect the iPhone with a cable and run
        iphone-control
      It walks you through setup (pairing, Developer Mode, Apple ID, WebDriverAgent, MCP registration).
      Settings: ~/.config/iphone-control/env (example: #{opt_pkgshare}/env.example).
      On Linux, the daemon also needs the system's usbmuxd (sudo apt install usbmuxd).
    EOS
  end

  test do
    assert_match version.to_s, shell_output("#{bin}/iphone-control --version")
  end
end
EOF