Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable non-admin and non-sudo
bootstrap.sh
usage
The `bootstrap.sh` script in this repo previously required both admin and sudo permissions. A plausible use case could exist in which an admin runs `bootstrap.sh` to configure the system initially, then a non-admin runs `bootstrap.sh` to configure their own account. In this use case, the non-admin user should not need admin or sudo privileges, because all the pertinent setup (FileVault disk encryption, XCode developer tools, Homebrew, etc) is already complete. This commit will update `bootstrap.sh` so that it can run successfully without admin or sudo. This means `bootstrap.sh` needs to detect both admin and sudo and adjust accordingly. The command `groups | grep -qE "\b(admin)\b"` will be used to detect admin. The method for detecting sudo will vary based on how the script is running. When running in non-interactive mode (`[ "$STRAP_INTERACTIVE" -eq 0 ]`), `sudo -n -l mkdir &>/dev/null` will be used as a simple check for sudo. When running interactively, the script will allow activation of sudo by TouchID or password entry. The variables `STRAP_ADMIN` and `STRAP_SUDO` will track the outcome of these admin and sudo checks. Any commands requiring admin will be guarded under `[ "$STRAP_ADMIN" -gt 0 ]`, and any commands requiring sudo will be guarded under `[ "$STRAP_SUDO" -gt 0 ]`. Many of the print/logging commands required sudo unnecessarily. This commit will overhaul the logging functions, adding separate non-sudo versions, and only using the sudo commands when sudo is needed. Homebrew installation will be updated to require sudo but not admin. Initial setup of Homebrew itself does not require an admin user account, but does require sudo (https://docs.brew.sh/Installation). After Homebrew setup, use of sudo with `brew` commands is discouraged (https://docs.brew.sh/FAQ#why-does-homebrew-say-sudo-is-bad). Permissions issues with Homebrew directories can sometimes occur. After Homebrew setup, commands such as `brew bundle install --global` should be run from the same user account used for setup. Attempts to run `brew` commands from another user account may result in errors, because directories that need to be updated are owned by the setup account. If access to the setup account is not routinely available, an alternative approach could be to change ownership of Homebrew directories to a group that includes the user account used for Homebrew setup as well as other users that need to run Homebrew commands. The effectiveness of this approach is not guaranteed and may depend on implementation details of how Homebrew detects directory permissions. GitHub Actions workflows will be updated to test `bootstrap.sh` on non-admin and non-sudo accounts.
- Loading branch information