0

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

0

1 Answer 1

1

It sounds like $HOME is being changed to /root within your script's environment. Try using $SUDO_USER instead of $ON_USER, and $(eval echo ~$SUDO_USER) instead of ~:

ak@myo5a:~$ echo "$(grep -v "^#" ~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0)"
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-qH8a0TOc6f,guid=873a5a81a7abe448ef2c293000000012
DBUS_SESSION_BUS_PID=2013
DBUS_SESSION_BUS_WINDOWID=8388609
ak@myo5a:~$ sudo -sH
root@myo5a:/home/ak# echo "USER=$USER; HOME=$HOME; SUDO_USER=$SUDO_USER; SUDO_HOME=$(eval echo ~$SUDO_USER)"
USER=root; HOME=/root; SUDO_USER=ak; SUDO_HOME=/home/ak
root@myo5a:/home/ak# echo "$(grep -v "^#" $(eval echo ~$SUDO_USER)/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0)"
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-qH8a0TOc6f,guid=873a5a81a7abe448ef2c293000000012
DBUS_SESSION_BUS_PID=2013
DBUS_SESSION_BUS_WINDOWID=8388609
root@myo5a:/home/ak# sudo -u $SUDO_USER touch /cant_touch_this
touch: cannot touch `/cant_touch_this': Permission denied
3
  • doesn't work as I need it to grand system modification access and specific USER case application for given folders and configs. SUDO_USER still only returns root...
    – user12213
    Mar 12, 2011 at 2:19
  • What user are you running sudo -s as?
    – ændrük
    Mar 12, 2011 at 4:21
  • @Cypher2 My example is consistent with the design of sudo and Ubuntu's default file permissions. The sudo manual explains that "The -u option causes sudo to run the specified command as a user other than root." Running a command via sudo -u $USER is the same thing as running the command as the user $USER. Thus, you should not expect to have any elevated privileges when using sudo -u $SUDO_USER unless sudo -s was originally run as root.
    – ændrük
    Mar 12, 2011 at 21:49

You must log in to answer this question.