4

I developed an application for Debian and created .deb installation package using equivs-build. The control file which I used to create package has a line running a postinst script, setup.sh. In this file, I tried to get the login name of the user using several methods including:

USER=$(logname)
USER=$(who am i | awk '{print $1}')

These ways work properly when I try them as root in a terminal window. Unfortunately, they all failed during installation and login user name is retrieved as "root". This leads all the paths in the script to be wrong and script exits with an error, causing Software Center to show an error message and stopping installation.

However, using dpkg to install the package as below, my application was installed successfully.

dpkg -i package-name

So, why this is happening? How to get login name properly?

3

What you're trying to do cannot possibly work right.

.deb packages are not private to each user – they're all installed system-wide, which is why the 'logname' output shows "root" – therefore they must work identically for all users, and cannot have anyone's home directory hardcoded into the system-wide configuration files.

Remember that Linux is a multi-user operating system – there can be multiple user accounts created, and even logged in at the same time. So if your package does this, then it'll only work for whoever installs it, but will become impossible to use for everyone else on that computer!

The difference between dpkg and Software Center here is that the former performs all actions and runs scripts directly, so the postinst scripts are still running within the user's login session. However, the Software Center delegates actual installation to a background service which runs "outside" any login sessions, and doesn't interact with users in any way.

1
  • 1
    The reason why I am trying to achieve this is my application is a parental controls application which should be installed for just one user. Oct 12 '14 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.