From d41d63ee8c5220913c892df3671468f29cf701c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20A=CC=81lvaro?= Date: Fri, 2 Feb 2024 12:42:48 +0100 Subject: [PATCH] Revert "ref: Move Utils module to the end of file" This reverts commit 2c5cc40883e05bc335c5a05573c2fa71ba8bcbd2. --- Casks/salt.rb | 62 +++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/Casks/salt.rb b/Casks/salt.rb index a3dcf47..099b964 100644 --- a/Casks/salt.rb +++ b/Casks/salt.rb @@ -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" @@ -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