1

I wrote Postinst script for changing owner and file permission:

chown -R $(whoami)  ~/Desktop/my_file.desktop
chmod 777 ~/Desktop/my_file.desktop

but after installation it does nothing.

I'm really not getting what part of script is wrong. Please tell how to get dynamically username in Postinst script?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Mayur Wadekar
  • 29
  • 1
  • 7

1 Answers1

0

Package installation runs as root, unconditionally. There is no concept of an invoking user; indeed, the package installation may happen e.g. before any user accounts exist on the box.

It's extremely unclear what you actually hope to achieve, but it looks like perhaps your package should simply install a script which then performs the task when the user runs it. This will also conveniently create a file which is already owned by the current user, without any chown trickery.

Even if a user exists, there is no guarantee that they have a Desktop directory in their home directory, or that they are currently, or ever, logged in using a GUI.

Finally, whatever you are attempting to do, chmod 777 is wrong and dangerous. You should absolutely not assign write access for everyone, to anything, ever.

(Okay, so there are two or three obscure scenarios related to system administration where this is actually required and useful; otherwise it should probably be technically impossible in the first place.)

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • I've already done with root. But the Ubuntu not giving permission to run .desktop file. So I've write 'chown' into post_install script. Firstly I was done it by command prompt. – Mayur Wadekar Dec 14 '18 at 11:33
  • Again, you are not using the right tool for the job. Your question doesn't show enough detail to let me explain what the right tool is, but as suggested in this answer, something like putting the file creation in `/usr/bin/create_my_file_desktop` and having the user run that when they want to would probably be closer to what you actually need. – tripleee Dec 14 '18 at 11:36
  • thanks for this - "Finally, whatever you are attempting to do, chmod 777 is wrong and dangerous.". But it was just for purpose. And I'm really not doing this. But thanks for remind this me again :) – Mayur Wadekar Dec 14 '18 at 11:36
  • I simply wanted - after installation change owner of file through post_install – Mayur Wadekar Dec 14 '18 at 11:38
  • Yes, that much is clear, but a `.deb` package should not and attempt to, and indeed basically cannot, install anything outside of the system directories. – tripleee Dec 14 '18 at 11:39
  • Is there any other solution you have? Because every time I have to change owner through terminal which is really not acceptable at all. – Mayur Wadekar Dec 14 '18 at 11:42
  • This is the third time I explain this: Create a package which installs a script which the user can run when they want to. There may be ways to force them to run it e.g. from the GUI startup scripts, but this depends on the GUI. For a really serious, robust approach, maybe look into hooking in to the login process via PAM. See e.g. https://unix.stackexchange.com/questions/50014/how-to-have-pam-exec-run-the-script-as-the-current-user (just the first Google result for me). – tripleee Dec 14 '18 at 11:43
  • Yeah now I got it. Thanks for suggestion @tripleee – Mayur Wadekar Dec 14 '18 at 11:45