Homebrew Ruby 脚本

Homebrew 使用 Ruby 脚本(称为 Formula)来定义每个软件包的安装过程。一个 Formula 文件通常包含了软件包的名称、版本、来源、依赖关系以及安装方法等信息。

Formula

class Speedtest < Formula
  desc "Ookla Speedtest"
  homepage "https://speedtest.net/apps/cli"
  url "https://install.speedtest.net/app/cli/ookla-speedtest-1.2.0-macosx-universal.tgz"
  sha256 "c9f8192149ebc88f8699998cecab1ce144144045907ece6f53cf50877f4de66f"
  version "1.2.0"

  def install
    bin.install "./speedtest"
    man.mkpath
    man5.install "./speedtest.5"
  end

  test do
    assert_match /\b1\.2\.0\b/, shell_output("#{bin}/speedtest --version")
  end
end

Cask

# 定义一个 cask 包,名称为 "steam"
cask "steam" do
    version "4.0"     # 包版本为 4.0
    sha256 :no_check  # 不检查下载文件的 SHA-256 校验和

    # 指定包下载 URL,并验证来源域名
    url "https://cdn.cloudflare.steamstatic.com/client/installer/steam.dmg",
        verified: "cdn.cloudflare.steamstatic.com/"

    name "Steam"                                      # 包名称
    desc "Video game digital distribution service"    # 包描述
    homepage "https://store.steampowered.com/about/"  # 包主页链接

    # 定义包的更新检查策略
    livecheck do
    url :url                 # 使用下载 URL 检查更新
    strategy :extract_plist  # 从 Plist 文件中提取版本信息
    end

    auto_updates true  # 指定包支持自动更新

    app "Steam.app"    # 指定要安装的应用程序

    uninstall launchctl: [  # 定义卸载时要停止的服务
                "com.valvesoftware.steam.ipctool",
                "com.valvesoftware.steamclean",
            ],
            quit:      [  # 定义卸载时要退出的进程
                "com.valvesoftware.steam",
                "com.valvesoftware.steam.helper",
                "com.valvesoftware.steam.helper.EH",
            ],
            delete:    "~/Library/Application Support/Steam/Steam.AppBundle"  # 指定要删除的应用支持目录

    zap trash: [  # 定义清理时要删除的残留数据
    "~/Library/Application Support/Steam/",
    "~/Library/LaunchAgents/com.valvesoftware.steamclean.plist",
    "~/Library/Preferences/com.valvesoftware.steam.helper.plist",
    "~/Library/Saved Application State/com.valvesoftware.steam.savedState/",
    ]

    caveats do
    requires_rosetta  # 提示该应用需要 Rosetta 翻译环境
    end
end
posted @ 2025-01-07 02:16  Undefined443  阅读(32)  评论(0)    收藏  举报