From 49aad7ddb3702a3357f20e889d7a637b25011b37 Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Thu, 18 Apr 2019 07:48:05 +0200 Subject: [PATCH] brew: remove sudo call only in docker context Follow up from #6018 --- Library/Homebrew/brew.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 364cb9a380..23d4a80802 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -17,16 +17,6 @@ end # Also define here so we can rescue regardless of location. class MissingEnvironmentVariables < RuntimeError; end -def create_tap(cmd, tap_name) - tap_commands = [] - if cmd == "services" - brew_uid = HOMEBREW_BREW_FILE.stat.uid - tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] if Process.uid.zero? && !brew_uid.zero? - end - tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{tap_name}] - safe_system(*tap_commands) -end - begin require_relative "global" rescue MissingEnvironmentVariables => e @@ -123,7 +113,14 @@ begin # Unset HOMEBREW_HELP to avoid confusing the tap ENV.delete("HOMEBREW_HELP") if help_flag - create_tap(cmd, possible_tap.name) + tap_commands = [] + cgroup = Utils.popen_read("cat", "/proc/1/cgroup") + unless cgroup.include?("azpl_job") || cgroup.include?("docker") + brew_uid = HOMEBREW_BREW_FILE.stat.uid + tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] if Process.uid.zero? && !brew_uid.zero? + end + tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap.name}] + safe_system(*tap_commands) ENV["HOMEBREW_HELP"] = "1" if help_flag exec HOMEBREW_BREW_FILE, cmd, *ARGV end