From a3b5ef08fa5264db1fb701e774fb9ace265b70c2 Mon Sep 17 00:00:00 2001 From: Kate Date: Fri, 2 Feb 2024 17:15:44 +0000 Subject: [PATCH] shell/install.sh: Add support for doas as an alternative to sudo --- master_changes.md | 3 +++ shell/install.sh | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/master_changes.md b/master_changes.md index 0c538e1516f..ed9cef22184 100644 --- a/master_changes.md +++ b/master_changes.md @@ -76,6 +76,9 @@ users) ## Release scripts +## Install script + * Add support for doas as an alternative to sudo [#5820 @kit-ty-kate - fix #5792] + ## Admin ## Opam installer diff --git a/shell/install.sh b/shell/install.sh index 5dafa4f4ffd..f1266229245 100755 --- a/shell/install.sh +++ b/shell/install.sh @@ -390,12 +390,21 @@ xsudo() { local DSTDIR=$(dirname "$DST") if [ ! -w "$DSTDIR" ]; then - echo "Write access to $DSTDIR required, using 'sudo'." + if command -v sudo > /dev/null ; then + SUDO=sudo + elif command -v doas > /dev/null ; then + SUDO=doas + else + echo "Write access to '$DSTDIR' required, but neither sudo or doas is installed." + echo "Aborting..." + exit 1 + fi + echo "Write access to '$DSTDIR' required, using '$SUDO'." echo "Command: $CMD $@" if [ "$CMD" = "install" ]; then - sudo "$CMD" -g 0 -o root "$@" + "$SUDO" "$CMD" -g 0 -o root "$@" else - sudo "$CMD" "$@" + "$SUDO" "$CMD" "$@" fi else "$CMD" "$@"