Skip to content

Commit

Permalink
cask(salt): Improve PATH config
Browse files Browse the repository at this point in the history
  • Loading branch information
cdalvaro committed Aug 25, 2023
1 parent 91fd6d9 commit 016bdfc
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions Casks/salt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

livecheck do
url "https://repo.saltproject.io/salt/py3/macos/latest"
regex(%r{salt-(\d+(?:\.\d+)?(?:-\d+)?)-py3-#{arch}\.pkg})
regex(/salt-(\d+(?:\.\d+)?(?:-\d+)?)-py3-#{arch}\.pkg/)
end

conflicts_with formula: "salt"
Expand All @@ -21,6 +21,7 @@
pkg "salt-#{version}-py3-#{arch}.pkg"

postflight do
random_str = (0...8).map { rand(65..90).chr }.join
%w[api master minion syndic].each do |daemon|
plist_file = "/Library/LaunchDaemons/com.saltstack.salt.#{daemon}.plist"
xml, = system_command! "plutil",
Expand All @@ -29,16 +30,13 @@
xml = Plist.parse_xml(xml)

xml["EnvironmentVariables"] = {} unless xml.key?("EnvironmentVariables")

xml["EnvironmentVariables"]["PATH"] = if xml["EnvironmentVariables"].key?("PATH")
"#{HOMEBREW_PREFIX}/bin:#{xml["EnvironmentVariables"]["PATH"]}"
else
"#{HOMEBREW_PREFIX}/bin"
end

xml["EnvironmentVariables"]["HOMEBREW_PREFIX"] = HOMEBREW_PREFIX.to_s

new_plist_file = "/tmp/#{File.basename(plist_file)}"
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

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]
Expand All @@ -47,7 +45,7 @@
args: [new_plist_file, plist_file],
sudo: true
system_command! "chown",
args: ["root:wheel", "plist_file"],
args: ["root:wheel", plist_file],
sudo: true
end
end
Expand Down

0 comments on commit 016bdfc

Please sign in to comment.