Skip to content

Commit ec13cf8

Browse files
committed
Run brew as regular user in place of root
1 parent 3c9b379 commit ec13cf8

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

include/functions

+17
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
# ReportManual Log manual actions to report file
9292
# ReportSuggestion Add a suggestion to report file
9393
# ReportWarning Add a warning and priority to report file
94+
# RunBrewCmd Run Homebrew commands as a normal user instead of root
9495
# SafeFile Security tests to perform on a file before using it
9596
# SafePerms Check if a file has safe permissions
9697
# SafeInput Test provided string to see if it contains unwanted characters
@@ -3036,6 +3037,22 @@
30363037
}
30373038

30383039

3040+
################################################################################
3041+
# Name : RunBrewCmd()
3042+
# Description : Run Homebrew commands as a normal user instead of root
3043+
#
3044+
# Parameters : $@ = Homebrew command arguments
3045+
# Returns : None (executes the command as the appropriate user)
3046+
################################################################################
3047+
3048+
RunBrewCmd() {
3049+
case "$(id -u)" in
3050+
0) sudo -u "$SUDO_USER" brew "$@" ;;
3051+
*) brew "$@"
3052+
esac
3053+
}
3054+
3055+
30393056
################################################################################
30403057
# Name : SafeInput()
30413058
# Description : Test provided string to see if it contains unwanted characters

include/tests_ports_packages

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
LogText "Test: Querying brew to get package list"
128128
Display --indent 4 --text "- Querying brew for installed packages"
129129
LogText "Output:"; LogText "-----"
130-
GPACKAGES=$(brew list --versions)
130+
GPACKAGES=$(RunBrewCmd list --versions)
131131
while IFS= read -r PKG; do
132132
PACKAGE_NAME=$(echo ${PKG} | ${CUTBINARY} -d ' ' -f1)
133133
PACKAGE_VERSION=$(echo ${PKG} | ${CUTBINARY} -d ' ' -f2)
@@ -183,7 +183,7 @@ EOF
183183
PACKAGE_VERSION=$(defaults read "$CS/Contents/Info" CFBundleShortVersionString 2>/dev/null || echo "N/A")
184184
LogText "Found CoreServices: ${PACKAGE_NAME} (version: ${PACKAGE_VERSION})"
185185
INSTALLED_PACKAGES="${INSTALLED_PACKAGES}|${PACKAGE_NAME},${PACKAGE_VERSION}"
186-
done
186+
done
187187
fi
188188
#
189189
#################################################################################

0 commit comments

Comments
 (0)