Skip to content

Commit

Permalink
Only use sudo/doas if uid != 0
Browse files Browse the repository at this point in the history
  • Loading branch information
zdykstra committed Dec 3, 2020
1 parent e8ad56c commit 4af48c7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions fuzzypkg
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4af48c7

Please sign in to comment.