Run programs as root - p-PROGRAMNAME
Posted: 31 Jul 2011, 18:58
Hi folks, this is so far my approach of how to run programs as root in porteus.
The script is always called "p-*" whereas * is the program name itself that should be run, and p-* just does the sanity check and asks for the root password if needed:
I use my own kind of strings for the colour initialisation... and that should be changed the most convenient way for all scripts to be written for Porteus...
What do you folks think?
The script is always called "p-*" whereas * is the program name itself that should be run, and p-* just does the sanity check and asks for the root password if needed:
Code: Select all
#!/bin/sh
VERSION="0.1"
MYNAME=$(basename $0)
PATH=/usr/bin/
echo -n "starting $MYNAME - "
echo -n "path is $PATH - "
PROGGIE=$(basename $0|cut -b 3-99)
echo "program name is $PROGGIE"
echo "Full name is $PATH$PROGGIE"
if ! test -x $PATH$PROGGIE ; then
echo -e $bld$red"$PATH$PROGGIE not found or not executable! Abort!"$off
exit 1
else
echo -e ${bld}Sanity check on Program okay...$off
fi
# Switch to root
if [ `whoami` != "root" ]; then
if [ "$DISPLAY" ]; then
xterm -T "Please enter root's password below" -e su - -c "$PATH$PROGGIE $@ && sleep 2"
exit 0
else
echo "Please enter root's password below"
su - -c "$PATH$PROGGIE $@"
exit 0
fi
fi
# now we can just run the program since it is run by root ^-^;
if [ "$DISPLAY" ]; then
echo Waiting 4 Seconds for changing the Desktop...
sleep 4
fi
$PATH$PROGGIE $@
exit 0
What do you folks think?