[2/2] utils: Optionally run utilities as root
diff mbox series

Message ID 20190530052525.5598-2-sam@mendozajonas.com
State Accepted
Headers show
Series
  • [1/2] utils: Quote plugin name and vendor variables
Related show

Commit Message

Samuel Mendoza-Jonas May 30, 2019, 5:25 a.m. UTC
In particular this fixes running pb-plugin executables from the UI since
the wrapper requires root to set up the environment.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
---
 utils/pb-exec | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/utils/pb-exec b/utils/pb-exec
index bfe13f6b..f1d22e6c 100755
--- a/utils/pb-exec
+++ b/utils/pb-exec
@@ -1,7 +1,17 @@ 
 #!/bin/sh
 
+PREFIX=""
+
+# Check if root required
+if [[ "$(id -u)" != "0" ]]; then
+	read -n 1 -r -p "Running as user $(id -un), run as root? (y/N)" key
+	if [ "$key" == "y" ]; then
+		PREFIX="sudo"
+	fi
+fi
+
 # Run a program specified by Petitboot.
-$@
+$PREFIX $@
 echo "$0 ran '$@'"
 
 # Wait for the user to exit back to Petitboot.