Debian Codegraph @

debian/slapd.postinst

raw
1 #! /bin/sh
2
3 set -e
4
5 . /usr/share/debconf/confmodule
6
7 # This will be replaced with debian/slapd.scripts-common which includes
8 # various helper functions and $OLD_VERSION and $SLAPD_CONF
9 #SCRIPTSCOMMON#
10
11 postinst_initial_configuration() { # {{{
12 # Configure slapd for the first time (when first installed)
13 # Usage: postinst_initial_configuration
14
15 if manual_configuration_wanted; then
16 echo " Omitting slapd configuration as requested." >&2
17 else
18 crypt_admin_pass
19 create_new_configuration
20 fi
21 }
22
23 # }}}
24 postinst_upgrade_configuration() { # {{{
25 # Handle upgrading slapd from some older version
26 # Usage: postinst_upgrade_configuration
27
28 # Better back up the config file in any case
29 backup_config_once
30
31 # Check if the database format has changed.
32 if database_format_changed; then
33
34 # During upgrading we have to load the old data
35 move_incompatible_databases_away
36 if ! load_databases; then
37 return 1
38 fi
39 fi
40
41 # Update permissions of all database directories
42 update_databases_permissions
43
44 # Versions prior to 2.4.7-1 could create a slapd.conf that wasn't
45 # readable by the openldap user.
46 update_permissions "${SLAPD_CONF}"
47 }
48
49 # }}}
50 # Ignore the init script failure and just calls "true". This is
51 # useful when we don't want the failure to interrupt an upgrade
52 # operation if there's been a failure to upgrade the configuration.
53 ignore_init_failure() { # {{{
54 if [ "$MODE" = "configure" ] && [ "$FAILED_TO_UPGRADE_CONFIGURATION" -eq 1 ]; then
55 true
56 fi
57 }
58 # }}}
59
60 # Create a new user. Don't create the user, however, if the local
61 # administrator has already customized slapd to run as a different user.
62 if [ "$MODE" = "configure" ] || [ "$MODE" = "reconfigure" ] ; then
63 if [ "openldap" = "$SLAPD_USER" ] ; then
64 create_new_user
65 fi
66 fi
67
68 # Initialize the FAILED_TO_UPGRADE_CONFIGURATION variable to 0. This
69 # variable will be set if/when there is a failure during the attempt
70 # to upgrade the existing configuration. It is useful to determine
71 # e.g. whether we should ignore the init script failure that will
72 # likely happen in these scenarios.
73 FAILED_TO_UPGRADE_CONFIGURATION=0
74
75 # Configuration.
76 if is_initial_configuration "$@"; then
77 postinst_initial_configuration
78 else
79 if ! postinst_upgrade_configuration; then
80 # An error occurred while attempting to upgrade the
81 # current configuration. This can mean many things,
82 # but usually it means that the user is using an
83 # unsupported backend.
84 #
85 # We need to:
86 #
87 # - Set the FAILED_TO_UPGRADE_CONFIGURATION to 1, in
88 # order to signal that there has been a problem
89 # while upgrading the configuration and the
90 # subsequent slapd init startup failure should not
91 # interefere with a possible dist-upgrade operation
92 # (see the "ignore_init_failure" function).
93 #
94 # - Display a critical notice to the user letting
95 # him/her know that manual action must be taken
96 # before the slapd can be started again.
97 #
98 # Note that the slapd service will fail to start after
99 # this, but that should be gracefully handled by
100 # dh_installinit's --error-handler option.
101 FAILED_TO_UPGRADE_CONFIGURATION=1
102 db_input critical slapd/postinst_error || true
103 db_go || true
104 fi
105 fi
106
107 db_stop || true
108
109 #DEBHELPER#
110
111 exit 0
112
113 # vim: set sw=8 foldmethod=marker: