Skip to content

Commit

Permalink
salt(cask): Use common plist patch
Browse files Browse the repository at this point in the history
  • Loading branch information
cdalvaro committed Nov 23, 2024
1 parent 13f96c7 commit 04b20b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 37 deletions.
42 changes: 6 additions & 36 deletions Casks/salt.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,4 @@
module Utils
extend SystemCommand::Mixin

def self.patch_plist(daemon)
plist_file = "/Library/LaunchDaemons/com.saltstack.salt.#{daemon}.plist"
xml, = system_command "plutil",
args: ["-convert", "xml1", "-o", "-", "--", plist_file],
sudo: true
xml = Plist.parse_xml(xml)

xml["EnvironmentVariables"] = {} unless xml.key?("EnvironmentVariables")
xml["EnvironmentVariables"]["HOMEBREW_PREFIX"] = HOMEBREW_PREFIX.to_s
xml["EnvironmentVariables"]["HOME"] ||= "/var/root"

path = xml["EnvironmentVariables"]["PATH"] || "/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
path = "#{HOMEBREW_PREFIX}/bin:#{path}" unless path.split(":").include?("#{HOMEBREW_PREFIX}/bin")
xml["EnvironmentVariables"]["PATH"] = path

random_str = (0...8).map { rand(65..90).chr }.join
new_plist_file = "/tmp/#{random_str}.#{File.basename(plist_file)}"
File.write(new_plist_file, xml.to_plist)
system_command "plutil",
args: ["-lint", new_plist_file]

system_command "mv",
args: [new_plist_file, plist_file],
sudo: true
system_command "chown",
args: ["root:wheel", plist_file],
sudo: true
end
end
require_relative "../lib/patches/salt"

cask "salt" do
arch arm: "arm64", intel: "x86_64"
Expand All @@ -40,21 +9,22 @@ def self.patch_plist(daemon)

url "https://packages.broadcom.com/artifactory/saltproject-generic/macos/#{version}/salt-#{version}-py3-#{arch}.pkg",
verified: "packages.broadcom.com/artifactory/saltproject-generic/"
name "Salt"
name "Salt #{version} STS"
desc "Automation and infrastructure management engine"
homepage "https://saltproject.io/"

livecheck do
url "https://docs.saltproject.io/en/latest/topics/releases/index.html"
regex(/href="[0-9.]+.html">Salt (\d+\.\d+) release notes/i)
url "https://packages.broadcom.com/artifactory/saltproject-generic/macos"
regex(%r{href="\d+\.\d+/">(\d+\.\d+)}i)
end

conflicts_with formula: "salt"
conflicts_with cask: "salt@3006"

pkg "salt-#{version}-py3-#{arch}.pkg"

postflight do
%w[api master minion syndic].each { |daemon| Utils.patch_plist(daemon) }
%w[api master minion syndic].each { |daemon| Patches::Salt.patch_plist(daemon) }
end

uninstall launchctl: [
Expand Down
3 changes: 2 additions & 1 deletion Casks/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

livecheck do
url "https://packages.broadcom.com/artifactory/saltproject-generic/macos"
regex(/href="3006\.\d+\/">(3006\.\d+)/i)
regex(%r{href="3006\.\d+/">(3006\.\d+)}i)
end

conflicts_with formula: "salt"
conflicts_with cask: "salt"

pkg "salt-#{version}-py3-#{arch}.pkg"

Expand Down

0 comments on commit 04b20b2

Please sign in to comment.