diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-08-12 10:19:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-12 10:19:03 +0200 |
commit | af4e8b00fb986acf32d7e4cd4fff7218b38958df (patch) | |
tree | 69474a3936d7bf49b2c34407163e452743c2a565 /scripts | |
parent | 80a960940b53d8855a772a1b4088b848316023ea (diff) | |
parent | 7bb1e913b33499d3ce74929749977774bcc35aed (diff) |
Merge pull request #6882 from DeterminateSystems/allow-multi-user-as-root
Allow installing multi-user as root on macOS and Linux
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/install-multi-user.sh | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/scripts/install-multi-user.sh b/scripts/install-multi-user.sh index e6864eaaf..a9f3e74dc 100644 --- a/scripts/install-multi-user.sh +++ b/scripts/install-multi-user.sh @@ -59,6 +59,30 @@ headless() { fi } +is_root() { + if [ "$EUID" -eq 0 ]; then + return 0 + else + return 1 + fi +} + +is_os_linux() { + if [ "$(uname -s)" = "Linux" ]; then + return 0 + else + return 1 + fi +} + +is_os_darwin() { + if [ "$(uname -s)" = "Darwin" ]; then + return 0 + else + return 1 + fi +} + contact_us() { echo "You can open an issue at https://github.com/nixos/nix/issues" echo "" @@ -313,10 +337,15 @@ __sudo() { _sudo() { local expl="$1" shift - if ! headless; then + if ! headless || is_root; then __sudo "$expl" "$*" >&2 fi - sudo "$@" + + if is_root; then + env "$@" + else + sudo "$@" + fi } @@ -423,7 +452,7 @@ EOF fi done - if [ "$(uname -s)" = "Linux" ] && [ ! -e /run/systemd/system ]; then + if is_os_linux && [ ! -e /run/systemd/system ]; then warning <<EOF We did not detect systemd on your system. With a multi-user install without systemd you will have to manually configure your init system to @@ -865,24 +894,14 @@ EOF install -m 0664 "$SCRATCH/nix.conf" /etc/nix/nix.conf } -main() { - # TODO: I've moved this out of validate_starting_assumptions so we - # can fail faster in this case. Sourcing install-darwin... now runs - # `touch /` to detect Read-only root, but it could update times on - # pre-Catalina macOS if run as root user. - if [ "$EUID" -eq 0 ]; then - failure <<EOF -Please do not run this script with root privileges. I will call sudo -when I need to. -EOF - fi +main() { check_selinux - if [ "$(uname -s)" = "Darwin" ]; then + if is_os_darwin; then # shellcheck source=./install-darwin-multi-user.sh . "$EXTRACTED_NIX_PATH/install-darwin-multi-user.sh" - elif [ "$(uname -s)" = "Linux" ]; then + elif is_os_linux; then # shellcheck source=./install-systemd-multi-user.sh . "$EXTRACTED_NIX_PATH/install-systemd-multi-user.sh" # most of this works on non-systemd distros also else @@ -890,7 +909,10 @@ EOF fi welcome_to_nix - chat_about_sudo + + if ! is_root; then + chat_about_sudo + fi cure_artifacts # TODO: there's a tension between cure and validate. I moved the |