From 1a2796a7d056223e99f2ce0f21b2bbd9c5315b70 Mon Sep 17 00:00:00 2001 From: Nick Pezza Date: Mon, 18 Sep 2023 20:28:57 -0400 Subject: [PATCH] Loosen superuser check to match docker-installs script check --- lib/kamal/commands/docker.rb | 2 +- test/cli/server_test.rb | 4 ++-- test/commands/docker_test.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/kamal/commands/docker.rb b/lib/kamal/commands/docker.rb index 77070672a..942c58c08 100644 --- a/lib/kamal/commands/docker.rb +++ b/lib/kamal/commands/docker.rb @@ -16,6 +16,6 @@ def running? # Do we have superuser access to install Docker and start system services? def superuser? - [ '[ "${EUID:-$(id -u)}" -eq 0 ]' ] + [ '[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null' ] end end diff --git a/test/cli/server_test.rb b/test/cli/server_test.rb index 5742d5445..1c8a2607d 100644 --- a/test/cli/server_test.rb +++ b/test/cli/server_test.rb @@ -10,7 +10,7 @@ class CliServerTest < CliTestCase test "bootstrap install as non-root user" do SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(false).at_least_once - SSHKit::Backend::Abstract.any_instance.expects(:execute).with('[ "${EUID:-$(id -u)}" -eq 0 ]', raise_on_non_zero_exit: false).returns(false).at_least_once + SSHKit::Backend::Abstract.any_instance.expects(:execute).with('[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null', raise_on_non_zero_exit: false).returns(false).at_least_once SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal").returns("").at_least_once assert_raise RuntimeError, "Docker is not installed on 1.1.1.1, 1.1.1.3, 1.1.1.4, 1.1.1.2 and can't be automatically installed without having root access and the `curl` command available. Install Docker manually: https://docs.docker.com/engine/install/" do @@ -20,7 +20,7 @@ class CliServerTest < CliTestCase test "bootstrap install as root user" do SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(false).at_least_once - SSHKit::Backend::Abstract.any_instance.expects(:execute).with('[ "${EUID:-$(id -u)}" -eq 0 ]', raise_on_non_zero_exit: false).returns(true).at_least_once + SSHKit::Backend::Abstract.any_instance.expects(:execute).with('[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null', raise_on_non_zero_exit: false).returns(true).at_least_once SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:curl, "-fsSL", "https://get.docker.com", "|", :sh).at_least_once SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal").returns("").at_least_once diff --git a/test/commands/docker_test.rb b/test/commands/docker_test.rb index 1433f32f7..098d41625 100644 --- a/test/commands/docker_test.rb +++ b/test/commands/docker_test.rb @@ -21,6 +21,6 @@ class CommandsDockerTest < ActiveSupport::TestCase end test "superuser?" do - assert_equal '[ "${EUID:-$(id -u)}" -eq 0 ]', @docker.superuser?.join(" ") + assert_equal '[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null', @docker.superuser?.join(" ") end end