Skip to content

Use whoami in lieu of who + awk script - #132

Open
NoSuck wants to merge 1 commit into
RPi-Distro:masterfrom
NoSuck:whoami
Open

Use whoami in lieu of who + awk script#132
NoSuck wants to merge 1 commit into
RPi-Distro:masterfrom
NoSuck:whoami

Conversation

@NoSuck

@NoSuck NoSuck commented Sep 15, 2020

Copy link
Copy Markdown

Rationale:

⋅ increased efficiency
⋅ succinctness
⋅ no additional dependencies
⋅ fixes fringe-case bug triggered when "who -m" outputs more than one user, e.g. as with "raspi-config nonint do_audio 1" bound to an Openbox menu item

Thank you.

Rationale:

⋅ increased efficiency
⋅ succinctness
⋅ no additional dependencies
⋅ fixes fringe-case bug triggered when "who -m" outputs more than one user, e.g. as with "raspi-config nonint do_audio 1" bound to an Openbox menu item

Thank you.
@XECDesign

Copy link
Copy Markdown
Member

These aren't equivalent:

$ sudo who -m | awk '{ print $1 }'
pi
$ sudo whoami
root

who -m has the desired behaviour.

@NoSuck

NoSuck commented Sep 15, 2020

Copy link
Copy Markdown
Author

How is that example relevant, given the parameter expansion of SUDO_USER? Are you able to produce the undesirable behavior using the actual code in the pull request?

@XECDesign

Copy link
Copy Markdown
Member

A more relevant example:

$ su -
Password:
# who -m | awk '{ print $1 }'
pi

@NoSuck

NoSuck commented Sep 21, 2020

Copy link
Copy Markdown
Author

Thank you. The explicit use of who -m seems to be for convenience, i.e. to avoid a whiptail dialog when run with su and not sudo. We should weigh this convenience against the aforementioned bug.

Put this in an appropriate place in raspi-config:

echo "$USER" >> ~/.raspi-config.bug.tmp

Then add and execute a window manager hotkey that calls raspi-config non-interactively. With Openbox (i.e. LXDE), execution of the following addition to rc.xml...

<keybind key="W-Q"> <action name="Execute"> <command>raspi-config nonint do_audio 0</command> </action> </keybind>

... results in the following output at ~/.raspi-config.bug.tmp:

... an empty file. Thus, the issue is no longer of convenience but of functionality, as there is no way to effectively run raspi-config non-interactively under these circumstances.

One solution is in this pull request. Do you offer any others?

@MichaIng

MichaIng commented Oct 27, 2020

Copy link
Copy Markdown

Probably best is if SUDO_USER and who -m are asked only if the current user is actually root? If it is not root, it is reasonable to assume it is the users that should be affected by raspi-config is the current one. This would also allow to configure other users via sudo -u micha raspi-config:

if [ $(id -u) = 0 ]; then
  USER=${SUDO_USER:-$(who -m | awk '{ print $1; exit }')}
else
  USER=$(whoami)
fi

@NoSuck I think this would solve your issue?

I also added exit to the awk so that it exits after processing the first who -m line for those rare situations, but of course it could be the wrong user then. But two lines in USER variable causes more havoc throughout the script, I guess 😉.

@NoSuck

NoSuck commented Oct 30, 2020

Copy link
Copy Markdown
Author

I think this would solve your issue?

Yes, it does. Thank you for the alternative. @XECDesign, does this look good to you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants