From e8c314d05a9f18faec20ddcc4289bb7e068571fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Egelund-M=C3=BCller?= Date: Mon, 16 Mar 2026 16:19:01 +0000 Subject: [PATCH 1/2] Handle passwordless sudo in install script --- scripts/install.sh | 48 ++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index afecfb16bb0c..847f74c506cf 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -131,15 +131,15 @@ checkConflictingInstallation() { fi } -# Install the binary and ask for elevated permissions if needed +# Install the binary, using sudo if the directory is not directly writable installBinary() { - if [ "$INSTALL_DIR" = "/usr/local/bin" ]; then + if { [ -d "$INSTALL_DIR" ] && [ -w "$INSTALL_DIR" ]; } || { [ ! -d "$INSTALL_DIR" ] && [ -w "$(dirname "$INSTALL_DIR")" ]; }; then + install -d "$INSTALL_DIR" + install rill "$INSTALL_DIR" + else printf "\nElevated permissions required to install the Rill binary to: %s/rill\n" "$INSTALL_DIR" sudo install -d "$INSTALL_DIR" sudo install rill "$INSTALL_DIR" - else - install -d "$INSTALL_DIR" - install rill "$INSTALL_DIR" fi cd - > /dev/null } @@ -225,13 +225,17 @@ removePathConfigEntries() { done } -# Check if the install directory (or its parent, if it doesn't exist yet) is writable +# Check if we can install to INSTALL_DIR installDirIsWritable() { - if [ -d "$INSTALL_DIR" ]; then - [ -w "$INSTALL_DIR" ] - else - [ -w "$(dirname "$INSTALL_DIR")" ] + # Check if it is directly writable + if [ -d "$INSTALL_DIR" ] && [ -w "$INSTALL_DIR" ]; then + return 0 + elif [ ! -d "$INSTALL_DIR" ] && [ -w "$(dirname "$INSTALL_DIR")" ]; then + return 0 fi + + # Check if we have passwordless sudo + sudo -n true 2>/dev/null } # Resolve the install directory @@ -248,21 +252,23 @@ resolveInstallDir() { # Handle non-interactive scenarios where prompt or sudo are not possible if [ "$NON_INTERACTIVE" = "true" ]; then - # If the install directory was explicitly set and requires sudo, we error - if [ -n "$INSTALL_DIR" ] && [ "$INSTALL_DIR_EXPLICIT" = "true" ] && ! installDirIsWritable; then - printf "Install directory '%s' requires elevated permissions, which are not available in non-interactive mode.\n" "$INSTALL_DIR" - exit 1 + # Default to /usr/local/bin if not set. + if [ -z "$INSTALL_DIR" ]; then + INSTALL_DIR="/usr/local/bin" fi - # If the install directory is not set, or the previous installation path requires sudo, we default to installing in the current directory - if [ -z "$INSTALL_DIR" ]; then - printf "Non-interactive shell detected; defaulting to install in current directory.\n" - INSTALL_DIR=$(pwd) - elif ! installDirIsWritable; then - printf "Non-interactive shell detected; previous installation at '%s' requires elevated permissions; defaulting to install in current directory.\n" "$INSTALL_DIR" + # Handle if the install directory is not writable and we can't prompt due to non-interactive mode. + if ! installDirIsWritable; then + # Error if the install directory was set explicitly. + if [ "$INSTALL_DIR_EXPLICIT" = "true" ]; then + printf "Install directory '%s' requires elevated permissions, which are not available in non-interactive mode.\n" "$INSTALL_DIR" + exit 1 + fi + + # Fall back to the current directory otherwise (which we assume is writable). INSTALL_DIR=$(pwd) fi - + return fi From 053a3da57c8ab663ce4741ff9c21f655772e8da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Egelund-M=C3=BCller?= Date: Mon, 16 Mar 2026 16:22:56 +0000 Subject: [PATCH 2/2] nits --- scripts/install.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 847f74c506cf..6a69398bbc46 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -230,11 +230,12 @@ installDirIsWritable() { # Check if it is directly writable if [ -d "$INSTALL_DIR" ] && [ -w "$INSTALL_DIR" ]; then return 0 + # If it doesn't exist yet, check if the parent directory is writable elif [ ! -d "$INSTALL_DIR" ] && [ -w "$(dirname "$INSTALL_DIR")" ]; then return 0 fi - # Check if we have passwordless sudo + # Lastly, we also consider it writable if we have passwordless sudo (since then we don't need to prompt/error due to lack of permissions) sudo -n true 2>/dev/null } @@ -268,7 +269,7 @@ resolveInstallDir() { # Fall back to the current directory otherwise (which we assume is writable). INSTALL_DIR=$(pwd) fi - + return fi