commit a5dc38aa88ab696fd5314f14f71549d42308acd2
parent 6c00cd38204c430b86d123d0100fc87ba9a8e085
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Thu, 1 Oct 2020 10:27:01 +0200
asuser: automatically choose doas(1) or sudo(1)
Diffstat:
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/.local/bin/asuser b/.local/bin/asuser
@@ -29,6 +29,12 @@ show_version() {
echo "https://src.adamsgaard.dk/dotfiles"
}
+if command -v doas >/dev/null 2>&1; then
+ doas=doas
+else
+ doas=sudo
+fi
+
if [ $# -lt 1 ]; then
die 'error: no USER specified'
exit 1
@@ -90,7 +96,7 @@ run_as_user() {
if [ -n "$ssh" ]; then
ssh "$ssh" $u@localhost "$*"
else
- doas -u "$u" sh -c "cd '$d' && \
+ $doas -u "$u" sh -c "cd '$d' && \
PATH=/home/'$u'/.local/bin:/home/'$u'/bin:\$PATH && \
$*"
fi