构建一个预配置的 debian 包 [英] Building a preconfigured debian package
问题描述
我正在尝试构建一个 debian 包,它会自动配置我的所有机器以使用相同的配置文件和设置.
例如,我正在尝试设置诸如 alter/etc/default/hostapd 之类的内容.我目前正在使用 dh_install 将文件复制到/etc/default/hostapd 并使用我想要的配置来执行此操作.
这会导致错误:
试图覆盖'/etc/default/hostapd',它也在包hostapd中
创建覆盖/etc/default/hostapd 等设置的 debian 软件包的正确方法是什么?
错误的原因是因为任何将文件写入系统的包都被标记为它的所有者.当两个包拥有同一个文件时,deb 机制不喜欢它.
您最好的选择是使用 dpkg-divert 将其他软件包的文件重命名为不同的名称.在您的预安装脚本中,输入以下命令(假设您的包名为 my_package:
dpkg-divert --divert/etc/default/hostapd.saved.my_package --package my_package --rename --add/etc/default/hostapd上一个>在您的 postrm 脚本中,您需要输入相反的命令(未经测试,RTFM 以正确获取精确的语法):
dpkg-divert --divert/etc/default/hostapd.saved.my_package --package my_package --rename --remove/etc/default/hostapd上一个>至少在过去,有一个更简单(虽然不太安全)的选项可以在 debian 控制文件中放置一个conffile"字段.这告诉系统这个包安装的文件会覆盖另一个包的文件.但是,我不确定我是否会推荐这种方法,因为它可能会在卸载时破坏.
I am trying to build a debian package which automatically configures all my machines to use the same configuration files and settings.
For example I am trying to set things like alter /etc/default/hostapd. I am currently doing this by using dh_install to copy a file to /etc/default/hostapd with the configuration I want it to have.
This results in the error:
trying to overwrite '/etc/default/hostapd', which is also in package hostapd
What is the correct way to create a debian package which overwrites the settings such as /etc/default/hostapd ?
解决方案The reason for the error is because any package that writes a file to the system is marked as its owner. The deb mechanism does not like it when two packages own the same file.
Your best option is to use dpkg-divert in order to rename the other package's file to a different name. In your preinst script, put the following command (assuming your package is called my_package:
dpkg-divert --divert /etc/default/hostapd.saved.my_package --package my_package --rename --add /etc/default/hostapdIn your postrm script, you need to put the opposite command (untested, RTFM to get the precise syntax correctly):
dpkg-divert --divert /etc/default/hostapd.saved.my_package --package my_package --rename --remove /etc/default/hostapdAt least in the past, there was a simpler (though less safe) option to put a "conffile" field in the debian control file. This tells the system that this package installs files that overwrite another package's files. I'm not sure I would recommend this method, however, as it might break things in case of uninstall.
这篇关于构建一个预配置的 debian 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!