Skip to content

Commit 56b34f2

Browse files
authored
Skip permission updates for Homebrew folders when NOROOT is set (#963)
1 parent dea7d62 commit 56b34f2

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

tools/setup-buildtools-apple.sh

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,45 @@
55
# control of the brew dirs. That causes the brew update to fail.
66
# Temporarily allow the user to take over control of brew files.
77

8-
echo ***
9-
echo *** You may need to enter your admin password to update the brew files:
10-
echo ***
11-
12-
sudo chown -R $(whoami) /usr/local/Cellar
13-
sudo chown -R $(whoami) /usr/local/Homebrew
14-
sudo chown -R $(whoami) /usr/local/var/homebrew
15-
sudo chown -R $(whoami) /usr/local/etc/bash_completion.d /usr/local/include /usr/local/lib/pkgconfig /usr/local/share/aclocal /usr/local/share/locale /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew/locks
8+
if [ -z "$NOROOT" ]; then
9+
echo "***"
10+
echo "*** You may need to enter your admin password to update the brew files:"
11+
echo "***"
12+
fi
13+
14+
ensure_ownership () {
15+
for PATH_TO_CHECK in "$@"; do
16+
if [ ! -e "$PATH_TO_CHECK" ]; then
17+
echo "ensure_ownership: $PATH_TO_CHECK doesn't exist, Homebrew may not be installed properly"
18+
continue
19+
fi
20+
21+
if [ -O "$PATH_TO_CHECK" ]; then
22+
continue
23+
fi
24+
25+
if [ -z "$NOROOT" ]; then
26+
sudo chown -R $(whoami) "$PATH_TO_CHECK"
27+
continue
28+
fi
29+
30+
echo "ensure_ownership (NOROOT): Path $PATH_TO_CHECK is not owned by current user, Homebrew may not work properly and fail the build"
31+
echo "ensure_ownership (NOROOT): Fix the ownership of required paths or run the build without NOROOT flag"
32+
done
33+
}
34+
35+
ensure_ownership \
36+
/usr/local/Cellar \
37+
/usr/local/Homebrew \
38+
/usr/local/var/homebrew \
39+
/usr/local/etc/bash_completion.d \
40+
/usr/local/include \
41+
/usr/local/lib/pkgconfig \
42+
/usr/local/share/aclocal \
43+
/usr/local/share/locale \
44+
/usr/local/share/zsh \
45+
/usr/local/share/zsh/site-functions \
46+
/usr/local/var/homebrew/locks
1647

1748
brew install cmake
1849
brew install wget

0 commit comments

Comments
 (0)