tags:

views:

217

answers:

1

Hi all

I have a script containing lots of commands that need root rights. Instead of running all these command with sudo inside the script I prefer to run the whole script with sudo. This is also more comfortable to put it in the sudoers file.

sudo ./script.sh

However, I'd like to show the progress with a kdialog progress bar, which does not work. The message box containing the bar shows up but when trying to update the progress there is an error message "object not accessible".

dcopRef=`kdialog --progressbar "Initialising..." 5`  # works
dcop $dcopRef setProgress 1  # error object not accessible

I'm pretty sure it has to do with user rights, since the progress bar code works then calling the script without sudo, but I have no idea where to start. Does anyone know how to fix this and still calling the script with sudo?

I'm using openSUSE 10.3 with KDE 3.5.7

Thanks, Chris

A: 

Finally I found a way to solve my problem! It is not beautiful, but it works...

Inside the 'script.sh' file you access the progress bar as the original (not root) user with the help of sudo:

dcopRef=`sudo -H -u $SUDO_USER kdialog --progressbar "Initialising..." 5`
dcop sudo -H -u $SUDO_USER $dcopRef setProgress 1

You must explicitly allow root to use call 'kdialog' and 'dcop' as user (although this seems a bit weird) by adding this to your sudoers file first:

root  ALL = (ALL)  NOPASSWD: /opt/kde3/bin/

Voilà.

Chris