3.5. Examples#

This sections contains several simple examples for the use of Univention Configuration Registry. The complete source of these examples is available separately. The download location is given in each example below. Since almost all Univention Corporate Server packages use UCR, their source code provides additional examples.

3.5.1. Minimal File example#

This example provides a template for /etc/papersize, which is used to configure the default paper size. A Univention Configuration Registry Variable print/papersize is registered, which can be used to configure the paper size.

Source code: UCS source: doc/developer-reference/ucr/papersize/

conffiles/etc/papersize

The template file only contains one line. Please note that this file does not start with the “UCRWARNING”, since the file must only contain the paper size and no comments.

@%@print/papersize@%@
debian/papersize.univention-config-registry

The file defines the templates and is processed by univention-install-config-registry during the package build and afterwards by univention-config-registry during normal usage.

Type: file
File: etc/papersize
debian/papersize.univention-config-registry-variables

The file describes the newly defined Univention Configuration Registry Variable.

[print/papersize]
Description[en]=specify preferred paper size [a4]
Description[de]=Legt die bevorzugte Papiergröße fest [a4]
Type=str
Categories=service-cups
debian/papersize.postinst

Sets the Univention Configuration Registry Variable to a default value after package installation.

#!/bin/sh

case "$1" in
configure)
  ucr set print/papersize?a4
  ;;
esac

#DEBHELPER#

exit 0
debian/rules

Invoke univention-install-config-registry during package build to install the files to the appropriate location. It also creates the required commands for the maintainer scripts (see debian/preinst, debian/prerm, debian/postinst, debian/postrm) to register and un-register the templates during package installation and removal.

#!/usr/bin/make -f
%:
  dh $@ --with ucr

Note

Tabulators must be used for indentation in this Makefile-type file.

debian/control

The automatically generated dependency on univention-config is inserted by univention-install-config-registry through debian/papersize.substvars.

Source: papersize
Section: univention
Priority: optional
Maintainer: Univention GmbH <packages@univention.de>
Build-Depends:
 debhelper-compat (= 12),
 univention-config-dev (>= 15.0.3),
Standards-Version: 4.3.0.3

Package: papersize
Architecture: all
Depends: ${misc:Depends}
Description: An example package to configure the papersize
 This purpose of this package is to show how Univention Config
 Registry is used.
 .
 For more information about UCS, refer to:
 https://www.univention.de/

3.5.2. Multifile example#

This example provides templates for /etc/hosts.allow and /etc/hosts.deny, which is used to control access to system services. See hosts_access.5 for more details.

Source code: UCS source: doc/developer-reference/ucr/hosts/

conffiles/etc/hosts.allow.d/00header; conffiles/etc/hosts.deny.d/00header

The first file fragment of the file. It starts with @%@UCRWARNING=# @%@, which is replaced by the warning text and a list of all sub-files.

@%@UCRWARNING=# @%@
# /etc/hosts.allow: list of hosts that are allowed to access the system.
#                   See the manual pages hosts_access(5) and hosts_options(5).
conffiles/etc/hosts.allow.d/50dynamic`; conffiles/etc/hosts.deny.d/50dynamic

A second file fragment, which uses Python code to insert access control entries configured through the Univention Configuration Registry Variables hosts/allow/ and hosts/deny/.

@!@
for key, value in sorted(configRegistry.items()):
    if key.startswith('hosts/allow/'):
    print(value)
@!@
debian/hosts.univention-config-registry

The file defines the templates and is processed by univention-install-config-registry.

Type: multifile
Multifile: etc/hosts.allow

Type: subfile
Multifile: etc/hosts.allow
Subfile: etc/hosts.allow.d/00header

Type: subfile
Multifile: etc/hosts.allow
Subfile: etc/hosts.allow.d/50dynamic
Variables: ^hosts/allow/.*

Type: multifile
Multifile: etc/hosts.deny

Type: subfile
Multifile: etc/hosts.deny
Subfile: etc/hosts.deny.d/00header

Type: subfile
Multifile: etc/hosts.deny
Subfile: etc/hosts.deny.d/50dynamic
Variables: ^hosts/deny/.*
debian/hosts.univention-config-registry-variables

The file describes the newly defined Univention Configuration Registry Variables.

[hosts/allow/.*]
Description[en]=An permissive access control entry for system services, e.g. "ALL: LOCAL"
Description[de]=Eine erlaubende Zugriffsregel für Systemdienste, z.B. "ALL: LOCAL".
Type=str
Categories=service-net

[hosts/deny/.*]
Description[en]=An denying access control entry for system services, e.g. "ALL: ALL".
Description[de]=Eine verbietende Zugriffsregel für Systemdienste, z.B. "ALL: ALL".
Type=str
Categories=service-net

3.5.3. Services#

This example provides a template to control the atd service through an Univention Configuration Registry Variable atd/autostart.

Source code: UCS source: doc/developer-reference/ucr/service/

conffiles/etc/init.d/atd

The template replaces the original file with a version, which checks the Univention Configuration Registry Variable atd/autostart before starting the at daemon. Please note that the “UCRWARNING” is put after the hash-bash line.

#! /bin/sh
@%@UCRWARNING=# @%@
### BEGIN INIT INFO
# Provides:          atd
# Required-Start:    $syslog $time $remote_fs
# Required-Stop:     $syslog $time $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Deferred execution scheduler
# Description:       Debian init script for the atd deferred executions
#                    scheduler
### END INIT INFO
# pidfile: /var/run/atd.pid
#
# Author: Ryan Murray <rmurray@debian.org>
#

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/sbin/atd
PIDFILE=/var/run/atd.pid

test -x "$DAEMON" || exit 0

. /lib/lsb/init-functions

case "$1" in
  start)
  log_daemon_msg "Starting deferred execution scheduler" "atd"
  start_daemon -p "$PIDFILE" "$DAEMON"
  log_end_msg $?
    ;;
  stop)
  log_daemon_msg "Stopping deferred execution scheduler" "atd"
  killproc -p "$PIDFILE" "$DAEMON"
  log_end_msg $?
    ;;
  force-reload|restart)
    "$0" stop
    "$0" start
    ;;
  status)
    status_of_proc -p "$PIDFILE" "$DAEMON" atd && exit 0 || exit $?
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|force-reload|status}"
    exit 1
    ;;
esac

exit 0

Note

The inclusion of init-autostart.lib and use of check_autostart.

debian/service.univention-config-registry

The file defines the templates.

Type: file
File: etc/init.d/atd
Mode: 755
Variables: atd/autostart

Note

The additional Mode statement to mark the file as executable.

debian/service.univention-config-registry-variables

The file adds a description for the Univention Configuration Registry Variable atd/autostart.

[atd/autostart]
Description[en]=Automatically start the AT daemon on system startup [yes]
Description[de]=Automatischer Start des AT-Dienstes beim Systemstart [yes]
Type=bool
Categories=service-at
debian/service.postinst

Set the Univention Configuration Registry Variable to automatically start the atd on new installations.

#!/bin/sh

case "$1" in
configure)
  ucr set atd/autostart?yes
  ;;
esac

#DEBHELPER#

exit 0
debian/control

univention-base-files must be added manually as an additional dependency, since it is used from within the shell code.

Source: service
Section: univention
Priority: optional
Maintainer: Univention GmbH <packages@univention.de>
Build-Depends:
 debhelper-compat (= 12),
 univention-config-dev (>= 15.0.3),
Standards-Version: 4.3.0.3

Package: service
Architecture: all
Depends: ${misc:Depends},
 univention-base-files,
Description: An example package to configure services
 This purpose of this package is to show how Univention Config
 Registry is used.
 .
 For more information about UCS, refer to:
 https://www.univention.de/