简体   繁体   中英

Dynamically get username in Postinst script of .deb package

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?

Package installation runs as root , unconditionally. There is no concept of an invoking user; indeed, the package installation may happen eg 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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM