Skip to content

Commit

Permalink
Revert "ref: Move Utils module to the end of file"
Browse files Browse the repository at this point in the history
This reverts commit 2c5cc40.
  • Loading branch information
cdalvaro committed Feb 2, 2024
1 parent 2c5cc40 commit d41d63e
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 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 Down Expand Up @@ -44,34 +75,3 @@ def caveats
CAVEATS
end
end

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

0 comments on commit d41d63e

Please sign in to comment.