【问题标题】:Debian Package Creation- How to install configuration files?Debian 软件包创建 - 如何安装配置文件?
【发布时间】:2013-03-07 04:43:25
【问题描述】:

我真的被这个小问题(我确定)困住了,所以任何帮助都将不胜感激。我用 dh_make 创建了一个标准的 ubuntu 包。这个包的目的是创建一个包,它将设置系统需要的所有 ldap 相关包,包括它的配置。我正在尝试执行的步骤之一是在备份现有文件的同时复制 /etc/ldap.conf 文件。我该怎么做呢?我试图创建一个基本上如下所示的 postinst 脚本,但我不清楚包如何存储文件,并且我收到一条错误消息,提示缺少 etc/ldap.conf 文件。最好的方法是什么?这是我的 postinst 脚本:

#!/bin/bash -xv

install -v -b etc/ldap.conf /etc/ldap.conf  > /tmp/tst 2>&1

这是我的骨架结构:

root@hqd-clientb-16:~/navldapubuntu-0.1/debian# 树 ├── 更新日志 ├── 兼容 ├── 控制 ├── 版权 ├── 文档 ├──等 └── ldap.conf ├── 安装 ├── 后勤 ├── 自述文件.Debian ├── README.source ├── 规则 ├── 来源 └── 格式 ├── navldapubuntu └──等 ├── navldapubuntu.debhelper.log ├── navldapubuntu.dirs └── navldapubuntu.doc-base.EX

这是我创建的包的一些附加信息。

dpkg --contents tnoldapubuntu_0.1-1_all.deb(截断输出) ./usr/ ./usr/share/ ./usr/share/doc
./usr/share/doc/navldapubuntu/ ./usr/share/doc/navldapubuntu/版权 ./usr/share/doc/navldapubuntu/README.Debian ./usr/share/doc/navldapubuntu/changelog.Debian.gz ./etc/ldap.conf

【问题讨论】:

  • 在 postinst 中备份?也许在preinst?检查文件是否存在:if [ -f /etc/ldap.conf ] then cp /etc/ldap.conf /etc/ldap.conf.dist fi,对吧?
  • 问题不在cp的逻辑上。问题是源 /etc/ldap.conf 不存在。如何将它包含在包中,以便我的安装后脚本可以看到 /etc/ldap.conf 文件?现在我的脚本中出现错误,说明如下: install: cannot stat `/navldap-0.1/debian/etc/ldap.conf': No such file or director
  • 奇怪的是,您在/etc 中没有文件并抛出错误,您没有在其他目录中?脚本无法在包中的文件上运行stat,您从哪个目录运行安装?
  • 对不起..我不清楚您的评论。我想要做的是将文件存储在包中(参见上面的 dpkg --contents )。创建包后,我想要安装包内的文件,并且该文件不是本地文件。我不清楚如何做到这一点。

标签: linux ubuntu debian package


【解决方案1】:

有一个专门用于创建配置包的工具:http://debathena.mit.edu/config-packages

这是一个简单的模板,可能有助于快速入门。

文件列表

  • 模板(目录)
  • 模板/debian(目录)
  • 模板/debian/控件
  • 模板/debian/changelog
  • 模板/debian/displace
  • 模板/debian/规则
  • 模板/debian/postinst
  • 模板/debian/安装
  • 模板/debian/docs
  • 模板/debian/compat
  • 模板/自述文件
  • 模板/构建
  • 模板/文件(目录)
  • 模板/文件/etc/ldap.conf.mycompanyname

内容

模板/debian/控件:

Source: PACKAGE_NAME
Section: morpho/misc
Priority: optional
Maintainer: MAINTAINER
Build-Depends: debhelper, config-package-dev (>= 5.0~)

Package: PACKAGE_NAME
Architecture: all
Depends: ${misc:Depends}, DEPENDENCY [, DEPENDENCY ...]
Provides: ${diverted-files}
Conflicts: ${diverted-files}
Description: PACKAGE_DESCRIPTION_SHORT
PACKAGE_DESCRIPTION_LONG.

模板/debian/置换

/etc/ldap/ldap.conf.mycompanyname

模板/debian/安装

files/* /

模板/debian/postinst

#!/bin/sh
set -e
#DEBHELPER#

POSTINST_SCRIPT

模板/debian/规则

#!/usr/bin/make -f

# Exclude *.svn* from building 
# you probably don't need this if don't use SVN
export DH_ALWAYS_EXCLUDE=.svn

# Core (check http://debathena.mit.edu/config-packages for more information)
%:
        dh $@ --with=config-package

# Prevent dh_installdeb of treating files in /etc as configuration files
# you need this if need configuration files been always rewritten
# even if changed
override_dh_installdeb:
        dh_installdeb
        rm debian/*/DEBIAN/conffiles

模板/debian/docs

README
BUILD

最后你可以使用以下命令构建这个包:

dpkg-buildpackage -us -uc -I.svn

【讨论】:

  • 感谢您提供完整的示例,这正是我想要的!
  • 我发现被替换的文件后缀“mycompanyname”需要是包名前缀(例如“mycompanyname-ldap-config”)与config-package-dev 5.1.2
【解决方案2】:

您需要在 DEBIAN 目录中创建一个“conffiles”文件,在“控制”文件旁边,并在其中声明 /etc/ldap.conf。所以这个文件会自动被认为是一个配置文件,修改它会提示“新的配置文件,你要覆盖吗,yadda yadda”。

【讨论】:

  • 非常感谢。在创建包含 /etc/ldap.conf 的 conffiles 文件后构建时出现错误。另外,是否可以传递一个标志来创建 /etc/ldap.conf 的备份文件? : dpkg-deb --build debian/navldapubuntu .. dpkg-deb: 错误: conffile `/etc/ldap.conf' 没有出现在包 dh_builddeb: dpkg-deb --build debian/tnoldapubuntu .. 返回退出代码 2
  • 实际上,conffiles 文件看起来只是保留了文件。我希望该软件包包含一个版本的 ldap.conf 文件,该文件在我执行 apt-get 安装时安装。例如: (1) 使用自定义的 ldap.conf 文件构建包 (2) apt-get install "package name" 并且这个自定义的 ldap.conf 也会被安装。希望这是有道理的?
  • 有道理,所以你应该在你的包中包含 /etc/ldap.conf。如果你这样做会怎样?
猜你喜欢
  • 2013-06-30
  • 2017-12-30
  • 2012-02-15
  • 2016-10-08
  • 2018-05-21
  • 2012-01-18
  • 2011-04-25
  • 2011-01-17
  • 1970-01-01
相关资源
最近更新 更多