From 4af48c752e8656afa957114a0ff41e1fb0842471 Mon Sep 17 00:00:00 2001 From: Zach Dykstra Date: Wed, 2 Dec 2020 22:46:48 -0600 Subject: [PATCH] Only use sudo/doas if uid != 0 --- fuzzypkg | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/fuzzypkg b/fuzzypkg index b2c3271..d3866dd 100755 --- a/fuzzypkg +++ b/fuzzypkg @@ -86,24 +86,26 @@ main() { INSTALL_CMD="xbps-install -S ${INSTALL[*]}" PRIV="" - if command -v doas > /dev/null 2>&1; then - PRIV="doas " - elif command -v sudo > /dev/null 2>&1; then - PRIV="sudo " + if [ "$(id -u)" -ne 0 ]; then + if command -v doas > /dev/null 2>&1; then + PRIV="doas " + elif command -v sudo > /dev/null 2>&1; then + PRIV="sudo " + fi fi # reset our position in the terminal - echo -ne "" + echo "" if [ -n "${UNINSTALL[*]}" ]; then - echo "Executing ${UNINSTALL_CMD}" + echo "Executing ${PRIV}${UNINSTALL_CMD}" #shellcheck disable=SC2086 ${PRIV}${UNINSTALL_CMD} fi if [ -n "${INSTALL[*]}" ]; then - echo "Executing ${INSTALL_CMD}" + echo "Executing ${PRIV}${INSTALL_CMD}" #shellcheck disable=SC2086 - ${PRIV} ${INSTALL_CMD} + ${PRIV}${INSTALL_CMD} fi }