[RFC,4/8] utils/pb-exec: Prepend sudo if normal user

Message ID 20181218041953.8960-5-sam@mendozajonas.com
State New
Headers show
Series
  • Introduce pb-plugin 'commands' & Rust PoC
Related show

Commit Message

Samuel Mendoza-Jonas Dec. 18, 2018, 4:19 a.m.
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
---
 utils/pb-exec | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Patch

diff --git a/utils/pb-exec b/utils/pb-exec
index bfe13f6b..c5cc8d10 100755
--- a/utils/pb-exec
+++ b/utils/pb-exec
@@ -1,7 +1,13 @@ 
 #!/bin/sh
 
+if [[ "$(id -u)" != "0" ]]; then
+	PREFIX="sudo"
+else
+	PREFIX=""
+fi
+
 # Run a program specified by Petitboot.
-$@
+$PREFIX $@
 echo "$0 ran '$@'"
 
 # Wait for the user to exit back to Petitboot.