MinimServer Forum

Full Version: Installing MinimServer on Linux using su
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm installing MinimServer on a Pi running Ubuntu. I've created a MinimServer account and switch to that using "su - minimserver " or "sudo -i -u minimserver" but whenever I run minimserver/bin/setup it places my account name in the /etc/init.d/minimserver script rather than minimserver.

I'm assuming it's falling back on my sudo privileges as during setup it "Acquiring root privilege for system configuration update..." but never asks for the minimserver sudo password (although does fail if it doesn't belong to sudo group).

I know I can get it working by just modifying the script, or logging in directly (I assume), but does anyone know why this happens, and if there's a way of getting it to work through user switching?

I assume it's a Linux thing rather than MinimServer but thought someone might understand what's going on when using su.
MinimServer uses the output of the logname command as the username to write into the /etc/init.d/minimserver script. If the logname command produces no output, MinimServer uses the value of the $LOGNAME environment variable. If the $LOGNAME variable has no value, MinimServer assumes the username is root.

With your setup, what is the output from the logname command and what is the value of the $LOGNAME variable?
As per this answer it looks like logname returns the owner of the terminal, whereas $LOGNAME returns the user that executes the current shell.

In my scenario, I logged into the server via putty using account SIMON after which I switched to minimserver (su -i minimserver), and in that shell logname returned SIMON whereas $LOGNAME returned minimserver.

I tend to just use 'id -un' but have no idea how compatiable that is across distributions.
Having thought about it, you're probably falling back on logname because you're trying to get the UID from within a SUDO call.
I tried to do something like this a while ago and I couldn't find a way to expose the Real UID from the shell as opposed to the Effective UID either, which was maddening.
I fell back on using $SUDO_USER, which should be ok if you're controlling how it's being called (doing the sudo call yourself), but it doesn't work in all scenarios ("sudo su - <another user>" from memory).

Again, no idea how this works across distributions, but it can't hurt if it's just an additional check before logname.
The setup script doesn't use logname or $LOGNAME when it is running with root privilege (within a sudo call). It uses these when running without root privilege and passes the result to the sudo call.

I have tried doing what you are doing on two different Linux systems and I get the same result as you. I am not sure if there was a reason why the result of the logname command was used in preference to the $LOGNAME value when this code was written. At this point, I think the right thing to do is to reverse the order of these two checks, which would solve the problem you are having. If this causes problems in other environments, we can deal with these as needed.

This change will be in the next release of MinimServer for Linux.
(02-10-2021 10:27)simoncn Wrote: [ -> ]I am not sure if there was a reason why the result of the logname command was used in preference to the $LOGNAME value when this code was written.
Given you weren't aware of the difference, maybe you chose logname over $LOGNAME because it's immutable, as it's trivial to change the shell variable.

(02-10-2021 10:27)simoncn Wrote: [ -> ]At this point, I think the right thing to do is to reverse the order of these two checks, which would solve the problem you are having. If this causes problems in other environments, we can deal with these as needed.
Sounds like a safe and sensible approach given all the platforms you have to target!
Happy to be a beta tester at any point - as I'm sure lots of other users would be.
This change is available now in MinimServer 2.1.
Just performed a full uninstall and install onto a Pi 4 running 64 bit Ubuntu and everything works as expected.

Thanks @simoncn
Reference URL's