Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use whoami in lieu of who + awk script #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NoSuck
Copy link

@NoSuck NoSuck commented Sep 15, 2020

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
Member

These aren't equivalent:

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

who -m has the desired behaviour.

@NoSuck
Copy link
Author

NoSuck commented Sep 15, 2020

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
Member

A more relevant example:

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

@NoSuck
Copy link
Author

NoSuck commented Sep 21, 2020

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
Copy link

MichaIng commented Oct 27, 2020

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
Copy link
Author

NoSuck commented Oct 30, 2020

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.

None yet

3 participants