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

Improve use of whoami #16059

Merged
merged 1 commit into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ EOS
${HOMEBREW_REPOSITORY} is not writable. You should change the
ownership and permissions of ${HOMEBREW_REPOSITORY} back to your
user account:
sudo chown -R \$(whoami) ${HOMEBREW_REPOSITORY}
sudo chown -R ${USER-\$(whoami)} ${HOMEBREW_REPOSITORY}
EOS
fi

Expand Down
10 changes: 7 additions & 3 deletions Library/Homebrew/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def check_exist_directories

You should create these directories and change their ownership to your user.
sudo mkdir -p #{not_exist_dirs.join(" ")}
sudo chown -R $(whoami) #{not_exist_dirs.join(" ")}
sudo chown -R #{current_user} #{not_exist_dirs.join(" ")}
EOS
end

Expand All @@ -367,7 +367,7 @@ def check_access_directories
#{not_writable_dirs.join("\n")}

You should change the ownership of these directories to your user.
sudo chown -R $(whoami) #{not_writable_dirs.join(" ")}
sudo chown -R #{current_user} #{not_writable_dirs.join(" ")}

And make sure that your user has write permission.
chmod u+w #{not_writable_dirs.join(" ")}
Expand Down Expand Up @@ -916,7 +916,7 @@ def check_cask_staging_location
<<~EOS
The staging path #{user_tilde(path.to_s)} is not writable by the current user.
To fix, run:
sudo chown -R $(whoami):staff #{user_tilde(path.to_s)}
sudo chown -R #{current_user} #{user_tilde(path.to_s)}
EOS
end

Expand Down Expand Up @@ -1027,6 +1027,10 @@ def all
def cask_checks
all.grep(/^check_cask_/)
end

def current_user
ENV.fetch("USER", "$(whoami)")
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/reinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def backup(keg)
rescue Errno::EACCES, Errno::ENOTEMPTY
odie <<~EOS
Could not rename #{keg.name} keg! Check/fix its permissions:
sudo chown -R $(whoami) #{keg}
sudo chown -R #{ENV.fetch("USER", "$(whoami)")} #{keg}
EOS
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/utils/lock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lock() {
odie <<EOS
Can't create ${name} lock in ${lock_dir}!
Fix permissions by running:
sudo chown -R \$(whoami) ${HOMEBREW_PREFIX}/var/homebrew
sudo chown -R ${USER-\$(whoami)} ${HOMEBREW_PREFIX}/var/homebrew
EOS
fi
# 200 is the file descriptor used in the lock.
Expand Down