[英]How do I run only some makefile commands as root?
I have an install target in my Makefile and wish to run some commands that install shared libraries(requires root permissions) and some that install config files into $HOME/.config
我在Makefile中有一个安装目标,希望运行一些命令来安装共享库(需要root权限),而一些命令将配置文件安装到
$HOME/.config
Usually I'd just tell the user to run sudo make install, however that results in the config file being installed to /root/.config
instead of the actual users config directory. 通常,我只是告诉用户运行sudo make install,但这会导致将配置文件安装到
/root/.config
而不是实际用户的config目录。
How do I work around this issue? 如何解决此问题? Thanks alot.
非常感谢。
You can just change the owner and permissions of the config files, although a Makefile
that installs per user configuration files, is not a good idea because it would ideally need to find out how many users exist on the system to install the files for each user. 您可以仅更改配置文件的所有者和权限,尽管按用户配置文件安装的
Makefile
并不是一个好主意,因为理想情况下,它需要找出系统上存在多少个用户才能为每个用户安装文件。
If you use the install
command, you could even do 如果使用
install
命令,您甚至可以
install -v -m644 -o$(USERNAME) -g$(USERGROUP) $(FILE) $(USERHOME)/.config/$(FILE)
A better approach would be to let the program install the default config files from a system wide directory when it doesn't find them, for example 更好的方法是让程序在找不到文件时从系统范围的目录中安装默认配置文件。
/usr/share/my-application/default-config/config.conf
and then the program would search for the files in the appropriate directoy and copy them to the $HOME
directory of the user that is currently running the program, that if the files are modifiable by the user, otherwise you just access them from their system-wide location. 然后程序将在适当的目录中搜索文件,并将它们复制到当前正在运行该程序的用户的
$HOME
目录中,如果该文件可由用户修改,否则您可以从其系统访问它们-广泛的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.