简体   繁体   中英

Debian Package Creation- How to install configuration files?

I've been really stuck on this minor (I'm sure) issue so any help would be greatly appreciated. I've created a standard ubuntu package with dh_make. The purpose of this package is to create a package that will set up all the ldap related packages that a system needs including it's configuration. One of the steps I'm trying to do is to copy over an /etc/ldap.conf file while making a backup of the existing file. How do I do this? I tried to create a postinst script that looks essentially like the following, but I'm not clear on how the package stores the files and I get an error saying missing etc/ldap.conf file. What's the best way to do this? Here is my postinst script:

#!/bin/bash -xv

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

Here is my skeleton structure:

root@hqd-clientb-16:~/navldapubuntu-0.1/debian# tree


     ├── changelog
     ├── compat
     ├── control
     ├── copyright
     ├── docs
     ├── etc
        └── ldap.conf
     ├── install
     ├── postinst
     ├── README.Debian
     ├── README.source
     ├── rules
     ├── source
       └── format
     ├── navldapubuntu
       └── etc
     ├── navldapubuntu.debhelper.log
     ├── navldapubuntu.dirs
     └── navldapubuntu.doc-base.EX

Here's some additional information of the package I created.

dpkg --contents tnoldapubuntu_0.1-1_all.deb (truncated output)
    ./usr/
    ./usr/share/
    ./usr/share/doc
./usr/share/doc/navldapubuntu/ ./usr/share/doc/navldapubuntu/copyright ./usr/share/doc/navldapubuntu/README.Debian ./usr/share/doc/navldapubuntu/changelog.Debian.gz ./etc/ldap.conf

There is a special tool that designed for creation of configuration packages: http://debathena.mit.edu/config-packages

Here is a simple template that could be helpful for a quick start.

List of files

  • template (directory)
  • template/debian (directory)
  • template/debian/control
  • template/debian/changelog
  • template/debian/displace
  • template/debian/rules
  • template/debian/postinst
  • template/debian/install
  • template/debian/docs
  • template/debian/compat
  • template/README
  • template/BUILD
  • template/files (directory)
  • template/files/etc/ldap.conf.mycompanyname

Content

template/debian/control:

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.

template/debian/displace

/etc/ldap/ldap.conf.mycompanyname

template/debian/install

files/* /

template/debian/postinst

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

POSTINST_SCRIPT

template/debian/rules

#!/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

template/debian/docs

README
BUILD

And finally you can build this package with the following command:

dpkg-buildpackage -us -uc -I.svn

You need to create a "conffiles" file in the DEBIAN directory, next to the "control" file, and declare /etc/ldap.conf in it. So this file will be automatically considered a configuration file, and changes to it will prompt a "new config file, would you want to overwrite, yadda yadda".

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