diff options
author | Graham Christensen <graham@grahamc.com> | 2022-08-08 15:45:23 -0400 |
---|---|---|
committer | Graham Christensen <graham@grahamc.com> | 2022-08-10 09:36:45 -0400 |
commit | 64c3adbe1ad14e043b772c3e981d511922cb06e5 (patch) | |
tree | f4971a748d7a7363d19097e908051768d8e9dbe4 /scripts | |
parent | 6cb41288ac8df00328865f4c66c324452e5a961c (diff) |
install-multi-user: abstract is_root, is_os_linux, is_os_darwin
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/install-multi-user.sh | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/scripts/install-multi-user.sh b/scripts/install-multi-user.sh index 9a18280ef..472d25842 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 "" @@ -423,7 +447,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,12 +889,13 @@ 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 + if is_root; then failure <<EOF Please do not run this script with root privileges. I will call sudo when I need to. @@ -879,10 +904,10 @@ EOF 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 |