[maemo-developers] root from scripts Re: [maemo-developers] Is there a convenient way of switching between usb/bluetooth/wifi networking?

From: Frantisek Dufka dufkaf at seznam.cz
Date: Fri Sep 22 11:39:09 EEST 2006
Greg Morgan wrote:
> Of course the challenge is doing
> something with root.

If you have r&d mode enabled there is easy trick for shell scripts.

# use gainroot to become root and relaunch itself
if [ `id -u` != 0 ] ; then
#if not already root, call itself as root
         sudo gainroot <<EOF
$0 $*
# real script follows

The only problem is that with this stdin is not original console used 
for launching. If this is needed there is workaround like adding
before 'sudo gainroot <<EOF' line and using
$0 <$TTY $*

But there should be also check if tty returns 'not a tty'.


More information about the maemo-developers mailing list