]> git.ozlabs.org Git - petitboot/commitdiff
utils: Optionally run utilities as root
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Thu, 30 May 2019 03:19:35 +0000 (13:19 +1000)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Fri, 7 Jun 2019 03:12:35 +0000 (13:12 +1000)
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

index bfe13f6b871dbbdab3e7aedbb96f82bfcc25e729..d672ec11683779f7dd37d6246ebbff80db7f0ada 100755 (executable)
@@ -1,7 +1,18 @@
 #!/bin/sh
 
 #!/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.
 # Run a program specified by Petitboot.
-$@
+$PREFIX $@
 echo "$0 ran '$@'"
 
 # Wait for the user to exit back to Petitboot.
 echo "$0 ran '$@'"
 
 # Wait for the user to exit back to Petitboot.