0

I have this very simple postinst file for a .Deb package:

#!/bin/sh

echo 'alias command_pandora="sudo /usr/local/bin/pandora"' >> ~/.bashrc

echo 'Pandora Storage Server Installation complete.'

When I run it I even get the 'Pandora Storage Server Installation complete.' message, but nothing is appended to ~/.bashrc; nevertheless when I run this command alone in the terminal:

echo 'alias command_pandora="sudo /usr/local/bin/pandora"' >> ~/.bashrc

It does work. I already tried modifying the file permisions for ~/.bashrc but still get the same result. I also tried running a separate script with the same content and running it and it also works, so it seems to be related to dpkg.

Why is the content not being appended?

jcjuarez
  • 81
  • 7

1 Answers1

1

The postinst script runs as root. Package installation is a system installation utility; it should absolutely not modify users' private files, including those of root.

Tangentially, defining an alias seems like the wrong solution to your problem. Generally, prefer functions or shell scripts over aliases.

If the tool requires privileged access through sudo, perhaps refactor it to run itself with sudo (maybe with a check to only do this when it is connected to a terminal, to prevent it from hanging when run unattended).

Or, simply, include /usr/bin/command_pandora in the package with the following contents:

#!/bin/sh
exec sudo /usr/local/bin/pandora "$@"

(Marginally, I suppose it could add something to /etc/skel/.bashrc but this will only create a new alias for users which are created after this change, or users whose .bashrc presciently run source /etc/skel/.bashrc. I don't think that's a good idea, either.)

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Also, your package should definitely not be creating `/usr/local/bin/pandora`. The directory `/usr/local/bin` is for packages which have been installed outside the control of `dpkg`; if your package installs something, it should be in `/usr/bin` (or perhaps `/usr/sbin` for binaries which qualify for this). – tripleee Jan 05 '23 at 10:11