Require root privileges only when neccessary

This commit is contained in:
T. R. Bernstein
2024-06-27 10:34:50 +02:00
committed by T. R. Bernstein
parent 5d8efcf238
commit 10b9b857b1
2 changed files with 4 additions and 5 deletions

View File

@@ -77,7 +77,6 @@ function main() {
local traps=() local traps=()
local -A colors=() errColors=() local -A colors=() errColors=()
defineColors defineColors
id -Gn | grep admin >&! /dev/null || { printError 'This script requires root access. Please run as an admin user.'; return 10 }
configureTerminal configureTerminal
local tmpdir="`mktemp -d -t 'macos-system'`" local tmpdir="`mktemp -d -t 'macos-system'`"
@@ -94,7 +93,7 @@ function main() {
local -A colors=() errColors=() local -A colors=() errColors=()
[ -t 1 ] && tput cnorm [ -t 1 ] && tput cnorm
isDebug && export MACOS_SYSTEM_DEBUG=true isDebug && export MACOS_SYSTEM_DEBUG=true
sudo --preserve-env=HOMEBREW_BREW_GIT_REMOTE,HOMEBREW_BREW_CORE_GIT_REMOTE,HOMEBREW_BREW_CASK_GIT_REMOTE,HOMEBREW_BREW_CASK_FONTS_GIT_REMOTE,MACOS_SYSTEM_DEBUG "${tmpdir}/install.sh" "$@" "${tmpdir}/install.sh" "$@"
[ -t 1 ] && tput civis [ -t 1 ] && tput civis
popd -q popd -q
} }

View File

@@ -78,7 +78,6 @@ function isPlistBuddyInstalled() {
function checkPrerequisites() { function checkPrerequisites() {
isMacOS || { lop -- -e 'This setup is only for macOS 10.13 and up.'; return 10 } isMacOS || { lop -- -e 'This setup is only for macOS 10.13 and up.'; return 10 }
isPlistBuddyInstalled || { lop -- -e 'This setup requires PlistBuddy to be either at /usr/libexec or in any of the PATH directories.'; return 11 } isPlistBuddyInstalled || { lop -- -e 'This setup requires PlistBuddy to be either at /usr/libexec or in any of the PATH directories.'; return 11 }
test "`id -u`" -eq 0 || { lop -- -e 'This module requires root access. Please run as root.'; return 11 }
} }
function configureTerminal() { function configureTerminal() {
@@ -135,6 +134,7 @@ function main() {
askNecessaryQuestions askNecessaryQuestions
[ -z "${config_only}" ] || return 0 [ -z "${config_only}" ] || return 0
requireRootPrivileges
installModules installModules
} }