Run programs as root - p-PROGRAMNAME

New features which should be implemented in Porteus; suggestions are welcome. All questions or problems with testing releases (alpha, beta, or rc) should go in their relevant thread here, rather than the Bug Reports section.
Post Reply
User avatar
Rava
Contributor
Contributor
Posts: 1319
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 3.1.0 x86-64 XFCe
Location: Germany

Run programs as root - p-PROGRAMNAME

Post#1 by Rava » 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:

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?
Cheers!
Yours Rava

User avatar
brokenman
Site Admin
Site Admin
Posts: 5460
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v3.2rcX all desktops
Location: Brazil
Contact:

Re: Run programs as root - p-PROGRAMNAME

Post#2 by brokenman » 31 Jul 2011, 22:10

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.
How do i become super user?
Wear your underpants on the outside and put on a cape.

User avatar
Rava
Contributor
Contributor
Posts: 1319
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 3.1.0 x86-64 XFCe
Location: Germany

Re: Run programs as root - p-PROGRAMNAME

Post#3 by Rava » 11 Aug 2011, 21:50

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.
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 1319
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 3.1.0 x86-64 XFCe
Location: Germany

Re: Run programs as root - p-PROGRAMNAME

Post#4 by Rava » 24 Feb 2012, 23:32

brokenman, is that library now finished and available for 64 bit as well?
Cheers!
Yours Rava

User avatar
Hamza
Warlord
Warlord
Posts: 1847
Joined: 28 Dec 2010, 07:41
Distribution: Porteus
Location: France

Re: Run programs as root - p-PROGRAMNAME

Post#5 by Hamza » 28 Feb 2012, 08:27

Yes, this one is available but right now out-dated for someones..It's time to move to GTKDialog! 8)
NjVFQzY2Rg==

User avatar
Ahau
King of Docs
King of Docs
Posts: 1331
Joined: 28 Dec 2010, 15:18
Distribution: LXDE & Xfce 32/64-bit
Location: USA

Re: Run programs as root - p-PROGRAMNAME

Post#6 by Ahau » 28 Feb 2012, 20:23

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'.
Please take a look at our online documentation, here. Suggestions are welcome!

User avatar
Rava
Contributor
Contributor
Posts: 1319
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 3.1.0 x86-64 XFCe
Location: Germany

Re: Run programs as root - p-PROGRAMNAME

Post#7 by Rava » 01 Mar 2012, 21:59

^
I will check out the code and see what I can copy / use for programs needed to run as root. E.g. truecrypt.
Cheers!
Yours Rava

Post Reply