From 651f52d7a168833ad4b9acc6d51aeba2309a5fea Mon Sep 17 00:00:00 2001 From: Hippolyte Chauvin Date: Wed, 29 Nov 2023 14:48:24 +0100 Subject: [PATCH] =?UTF-8?q?qemush=20:=20finalement=20la=20fonction=20exec?= =?UTF-8?q?=5Fas=20=C3=A9tait=20utile=20oups?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/qemush | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/bin/qemush b/bin/qemush index cd360c1..754eee4 100755 --- a/bin/qemush +++ b/bin/qemush @@ -1,10 +1,18 @@ #!/bin/bash -if [ "$(whoami)" != root ]; then - exec sudo -u qemu "$0" "$@" -else - cd || exit -fi +exec_as() { + local user + user="$1" + shift + + if [ "$(whoami)" != "$user" ]; then + exec sudo -u "$user" "$0" "$@" + else + cd || exit + fi +} + +exec_as qemu "$@" bin=bin images=images