Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(salt): Use the helper Utils module for plist patching #96

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions Casks/salt.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
module Utils
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

cask "salt" do
arch arm: "arm64", intel: "x86_64"

Expand All @@ -20,34 +51,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",
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

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
%w[api master minion syndic].each { |daemon| Utils.patch_plist(daemon) }
end

uninstall launchctl: [
Expand Down
Loading