Makefile:安装可从 CLI 或打包系统使用的目标吗?

发布于 2024-09-15 05:17:57 字数 1058 浏览 4 评论 0原文

给定我的 Makefile 的这个简单安装目标:

install: zrm $(CONF)
        install -D -m 0755 -o mysql -g mysql conf/lvm0.conf $(DESTDIR)/$(CONFDIR)/lvm0/mysql-zrm.conf
        install -D -m 0755 -o mysql -g mysql conf/inc1.conf $(DESTDIR)/$(CONFDIR)/inc1/mysql-zrm.conf
        install -D -m 0755 -o mysql -g mysql conf/dump0.conf $(DESTDIR)/$(CONFDIR)/dump0/mysql-zrm.conf

        install -d -m 0755 -o mysql -g mysql $(DESTDIR)/$(PLUGIN)
        install    -m 0755 -o mysql -g mysql post-backup-st-zrm.pl $(DESTDIR)/$(PLUGIN)

        install -d -m 0755 -o root -g root $(DESTDIR)/$(BINDIR)
        install    -m 4755 -o root -g root zrm $(DESTDIR)/$(BINDIR)

我只需以 root 身份执行 make install(或使用 sudo),它就会完美安装。 作为 foo(非特权)用户,调用 make install 将返回错误(-o 选项需要超级用户)。

我需要更改此设置,以便我可以 sudo make installmake install DESTDIR=/tmp/foo 甚至将其打包到 .deb 或 .rpm 中,然后调用从我的 Makefile 安装目标。

对我来说最好的解决方案是什么?替换对 cp 的安装调用?删除 -o 并放置 chown/chmod ?

谢谢。

given this simple install target for my Makefile:

install: zrm $(CONF)
        install -D -m 0755 -o mysql -g mysql conf/lvm0.conf $(DESTDIR)/$(CONFDIR)/lvm0/mysql-zrm.conf
        install -D -m 0755 -o mysql -g mysql conf/inc1.conf $(DESTDIR)/$(CONFDIR)/inc1/mysql-zrm.conf
        install -D -m 0755 -o mysql -g mysql conf/dump0.conf $(DESTDIR)/$(CONFDIR)/dump0/mysql-zrm.conf

        install -d -m 0755 -o mysql -g mysql $(DESTDIR)/$(PLUGIN)
        install    -m 0755 -o mysql -g mysql post-backup-st-zrm.pl $(DESTDIR)/$(PLUGIN)

        install -d -m 0755 -o root -g root $(DESTDIR)/$(BINDIR)
        install    -m 4755 -o root -g root zrm $(DESTDIR)/$(BINDIR)

I can simply do make install as root (or use sudo) and it will beautifully install.
As foo (unprivileged) user, calling make install will returns an error (-o option needs super-user).

I need to change this so that I can both sudo make install, make install DESTDIR=/tmp/foo or even package this into .deb or .rpm and just call the install target from my Makefile.

What will be the best solution for me ? Replace install calls to cp ? Remove -o and put a chown/chmod ?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人骨 2024-09-22 05:17:57

您可以将 install 命令设置为一个可以在 make 命令行上覆盖的变量,就像

INSTALL_USER = mysql
INSTALL_GROUP = mysql
INSTALL = install -d -m 0755 -o $(INSTALL_USER) -g $(INSTALL_GROUP)
INSTALL_DIR = $(INSTALL) -d

我希望打包系统能够处理您的 makefile 一样,因为这是其他人的事情已经写了。 Debian 软件包构建以 root 身份运行(或者通常通过 fakeroot 假装以 root 身份运行),因此它将允许并看到所有权的变化。

请注意,Debian 政策不允许您设置的权限,因为它要求所有文件都由 root 拥有,除非有一个令人信服的理由不这样做。我看不到任何文件由 mysql 拥有的原因(或者我是否错过了插件和配置文件不能由 root 拥有的一些特定于 mysql 的原因?)。原因是安全问题:如果有人设法将文件覆盖为 mysql,他们不应该能够将代码注入到可执行文件和配置文件中。

由于发行版维护者可能想要覆盖您设置的权限,因此不要为此烦恼。

You can make install command a variable that can be overridden on the make command line, something like

INSTALL_USER = mysql
INSTALL_GROUP = mysql
INSTALL = install -d -m 0755 -o $(INSTALL_USER) -g $(INSTALL_GROUP)
INSTALL_DIR = $(INSTALL) -d

I'd expect packaging systems to be able to cope with your makefile anyway, because it's the kind of things other people have written. Debian package building runs as root (or rather usually pretends to run as root, through fakeroot), so it will allow and see the ownership changes.

Note that Debian policy would not allow the permissions you set, since it requires all files to be owned by root unless there is a compelling reason not to. I can't see a reason for any of the files to be owned by mysql (or have I missed some mysql-specific reason why the plugins and configuration files can't be owned by root?). The reason is a security issue: if someone manages to overwrite files as mysql, they should not be able to inject code into executables and configuration files.

Since distribution maintainers may want to override the permissions you set anyway, don't agonize over this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文