Page 1 of 1

Run programs as root - p-PROGRAMNAME

Posted: 31 Jul 2011, 18:58
by Rava
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:

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
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?

Re: Run programs as root - p-PROGRAMNAME

Posted: 31 Jul 2011, 22:10
by brokenman
I would like to see a GUI for entering root password. I started working this into 32bit but dropped it due to time restriction and not being able to get lxde to play nice. Ideally the script would check for DISPLAY, and show GUI if user is in X.

I have also written a library similar to /usr/lib/macroport which has a bunch of functions to make scripting much easier. Colors are included in this. To get color in a console you will only need: yellow "This is yellow text" The next version of PPM relies heavily on this library, so it may as well be added as a universal library. If you have any useful functions you want to add i can certainly house them there.

Re: Run programs as root - p-PROGRAMNAME

Posted: 11 Aug 2011, 21:50
by Rava
brokenman, good to know.

I will look into the library and give you my thoughts on it, and possible ideas for expanding.

Sounds good so far, even without looking into it, and yes, when X runs the password should be asked by an X window thingy.

Re: Run programs as root - p-PROGRAMNAME

Posted: 24 Feb 2012, 23:32
by Rava
brokenman, is that library now finished and available for 64 bit as well?

Re: Run programs as root - p-PROGRAMNAME

Posted: 28 Feb 2012, 08:27
by Hamza
Yes, this one is available but right now out-dated for someones..It's time to move to GTKDialog! 8)

Re: Run programs as root - p-PROGRAMNAME

Posted: 28 Feb 2012, 20:23
by Ahau
Porteus 1.1 and 1.2 (RC1) shipped with the ktsuss GUI application for entering root password. In 32-bits, ktsuss doesn't play nicely with Trinity, but we're working through it...

In any other DE, you can open a program as root by running 'ktsuss /path/to/program'; in Trinity, you can run 'kdesu /path/to/program' -- in 1.2, they are renaming functions for trinity, so you can use 'tdesu /path/to/program'.

Re: Run programs as root - p-PROGRAMNAME

Posted: 01 Mar 2012, 21:59
by Rava
^
I will check out the code and see what I can copy / use for programs needed to run as root. E.g. truecrypt.