$ON_USER returning root instead of $USER

Posted by Nathanel Titane on Ask Ubuntu See other posts from Ask Ubuntu or by Nathanel Titane
Published on 2011-03-11T22:11:19Z Indexed on 2011/03/12 0:18 UTC
Read the original article Hit count: 191

Filed under:
|
|
|

Hello everybody!

With Natty coming out soon, I've been at work updating my deployment and self-config script to make my desktop on 11.04 run and look the way I want it to.

One bummer is that dbus seems to have changed and does not permit, in the same manner Lucid and Maverick did, the authentication of the current user by terminal call using grep and cat.

Ideally, to run the script, I would sudo -s and then launch it as

# chmod +x install && ./install

Instead of returning my user name.. it now returns root and applies changes to the root profile and aborts whenever paths do not correspond.

Here is my script header:

#!/bin/bash

ON_USER=$(echo ~ | awk -F'/' '{ print $1 $2 $3 }' | sed 's/home//g')

export $(grep -v "^#" ~/.dbus/session-bus/`cat /var/lib/dbus/machine-id`-0)

if sudo -u $ON_USER test -z "$DBUS_SESSION_BUS_ADDRESS" ;
then eval `sudo -u $ON_USER dbus-launch --sh-syntax --exit-with-session`
fi

RELEASE=$(lsb_release -cs)

How could I make it return the actual user now that natty is coming?

Thanks for the help

© Ask Ubuntu or respective owner

Related posts about 11.04

Related posts about terminal