summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>2019-05-30 13:19:35 +1000
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2019-06-07 13:12:35 +1000
commit3cf30cfa4f232d9a307c7983c40d0b1b2ca2e827 (patch)
treec33f34fdfb8821534b9e289a9e7dbfe576aefacd
parentaa596b2c10344e0664e0c98cd6db43af3e20fdb9 (diff)
downloadtalos-petitboot-3cf30cfa4f232d9a307c7983c40d0b1b2ca2e827.tar.gz
talos-petitboot-3cf30cfa4f232d9a307c7983c40d0b1b2ca2e827.zip
utils: Optionally run utilities as root
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>
-rwxr-xr-xutils/pb-exec13
1 files changed, 12 insertions, 1 deletions
diff --git a/utils/pb-exec b/utils/pb-exec
index bfe13f6..d672ec1 100755
--- a/utils/pb-exec
+++ b/utils/pb-exec
@@ -1,7 +1,18 @@
#!/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
+ printf "\n"
+fi
+
# Run a program specified by Petitboot.
-$@
+$PREFIX $@
echo "$0 ran '$@'"
# Wait for the user to exit back to Petitboot.
OpenPOWER on IntegriCloud