Custom Debian Distributions Toolkit (CDDT)

Author: Sergio Talens-Oliag
email:sto@debian.org
Date: 2006-01-30 01:01:56 +0100 (dl, 30 gen 2006)

Introduction

The cddt-runtime is a debian package that provides tools to:

To be able to handle package installation, upgrades and removals, the system installs hooks for apt on /etc/apt/apt.conf.d/10cddt-apt.

To execute scripts when bringing network interfaces up and down we install a script called 10cddt-net on the following ifupdown directories:

On the following sections we will describe how those subsystems work.

The apt hook

The /etc/apt/apt.conf.d/10cddt script installs hooks to call a program (cddt-apt) before and after dpkg is run. The hook calls cddt-apt with the argument pre-install-pkgs before dpkg is run and calls it again with the argument post-invoke if the dpkg execution succeeds.

The cddt-apt script

This program is used to undo the actions done by cddt scripts before upgrading a package (when called with the pre-install-pkgs argument) and re-execute them after the new versions are installed (option post-invoke).

The scripts that are going to be executed by cddt-apt must be available on the directory /etc/cddt/apt-scripts.d. The scripts can be installed on this directory directly by packages or can be installed on /etc/cddt/apt-scripts and enabled or disabled using the command update-cddt-apt-scripts.d.

The apt-scripts must support the following options:

  • packages: prints a lists of packages that are afected by the script, one per line.

    The list is used by cddt-apt to know if it has to run the pre-dpkg and post-dpkg commands of the script when called from apt:

    • On the pre-install-pkgs step, if a listed package is going to be modified by the next dpkg run, the script is called with the pre-dpkg argument to remove customizations before calling dpkg.
    • On the post-invoke step the cddt-apt script checks the list of packages again and if any of them has been installed or updated the script is called with the post-dpkg argument.

    The scripts must include the package they come from (if any) to force their execution after the initial instalation, before its removal or after script upgrades.

  • pre-dpkg: this command is called to remove the customizations done by the script, stopping or restarting services if needed. This option is used by cddt-apt on the pre-install-pkgs step when one or more packages related to this script are going to be modified (installed, removed or updated).

    Note that the system imposes no restrictions on how to apply or remove customizations nor says anything about what to do on problematic cases.

    If we use cddt-divert to handle configuration installation and removal we can force the removal of customizations when the configurations are modified (the installed files are different from the ones generated by the config scripts) or broken (some files are customized but others don't; the customized files can be modified or not) or ask the user about what to do.

  • post-dpkg: Option used by cddt-apt after runnig dpkg (post-invoke step) when one or more packages related to this script have been installed or upgraded.

    The command installs customized configuration files on the system and stops or starts the needed services.

    When using cddt-divert if a conffile is already diverted when starting it is left alone, as we assume that the user requested to leave it as is instead of removing it. Anyway a question can also be shown to the user if needed.

Besides the previous two arguments the cddt-apt program also can be used to call individual scripts available on /etc/cddt/apt-scripts.d; the syntax is:

cddt-apt COMMAND SCRIPT_NAME

Where COMMAND is one of pre-dpkg, post-dpkg or packages and SCRIPT_NAME is the name of a script available on /etc/cddt/apt-scripts.d.

Diverting files for CDD

The cddt-divert program is the tool used to replace system files with the files generated by cddt's configuration scripts.

The program diverts files one by one and uses a directory to keep copies of the ORIGINAL and the REPLACED versions of each file.

The copies are used to undo diversions and to compare the CURRENT version of a system file against the REPLACED or ORIGINAL version of it.

The comparisions can be used to know if a user has changed a REPLACED file or not (i.e. before removing a diversion we always compare CURRENT and REPLACED to see if the operation is safe and don't proceed if the files differ, unless the --force option is given).

For simplicity the current script only supports one version of each diverted file, that is, if you do a diversion using this tool you can't replace it with another diversion unless you remove the previous one.

The valid ACTIONS and their arguments are:

  • add FILEPATH REPLPATH: Adds a diversion to the file found on FILEPATH if it is not already diverted, replacing it's contents with the contents of the REPLPATH file. If the file was already diverted the command fails. The copies of the file are left in $CDDTK_DIVERT_DIR/$FILEPATH/repl and $CDDTK_DIVERT_DIR/$FILEPATH/orig. Note that if the file does not exist when the tool is called the orig copy is not present.
  • del FILEPATH [ --force ]: Removes the diversion of the file found on FILEPATH if its CURRENT contents are equal to the ones used when it was REPLACED. If the contents are different it only removes the diversion when the --force option is given. In that later case the three versions of the file are left on the directory $CDDTK_DIVERT_DIR/$FILEPATH/$TIMESTAMP as curr, repl and orig. Note that if there is no curr or orig file that means that the file was not present on the filesystem when the copy was done.
  • orig FILEPATH: Prints the contents of the original file on the standard output.
  • repl FILEPATH: Prints the contents of the replacement file on the standard output (if the user has not changed anything has to be equal to the CURRENT version).
  • status [ FILEPATH ]: Prints the list of all diverted files. If a FILEPATH is given it only prints if that file is diverted or not.

All the files are stored on the directory given by the CDDTK_DIVERT_DIR environment variable; if it is not defined the default path is /var/lib/cddt/divert/. In any case, if the directory does not exist the command fails.