1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
# This file can be included with #SCRIPTSCOMMON#
ANY_DATABASE_FORMAT_CHANGED="2.1.25-1"
DATABASE_FORMAT_CHANGED_BDB="2.1.25-1"
DATABASE_FORMAT_CHANGED_LDBM="2.1.12-1"
# Make the version we are upgrading from globally available
OLD_VERSION="$2"
# Source the init script configuration
if [ -f "/etc/default/slapd" ]; then
. /etc/default/slapd
fi
# Load the default location of the slapd config file
if [ -z "$SLAPD_CONF" ]; then
SLAPD_CONF="/etc/ldap/slapd.conf"
fi
# Check if we are upgrading from a version prior to OpenLDAP 2.1
upgrading_version_pre21() {
if dpkg --compare-versions "$OLD_VERSION" lt-nl 2.1; then
return 0
else
return 1
fi
}
# Check if any database backend would require a reload
database_might_need_reload() {
if dpkg --compare-versions "$OLD_VERSION" lt-nl "$ANY_DATABASE_FORMAT_CHANGED"; then
return 0
else
return 1
fi
}
# Check if database with backend passed needs to be reloaded
database_needs_reload() {
backend="$1"
format_changed=$(eval echo '$DATABASE_FORMAT_CHANGED_'`echo "$backend"|tr a-z A-Z`)
if dpkg --compare-versions "$OLD_VERSION" lt-nl "$format_changed"; then
return 0
else
return 1
fi
}
database_needs_fixing() {
if dpkg --compare-versions "$OLD_VERSION" lt-nl "2.1"; then
return 0
else
return 1
fi
}
# slapd supports continuation lines in the slapd.conf. Continuation lines
# start with spaces and are merged with the preceding line. This function
# uses perl to merge physical lines into logical lines as seen by the
# slapd config parser.
merge_logical_lines() {
perl -pe 'BEGIN { undef $/ }; s/\n(?!\n)\s+/ /g;'
}
# read slapd.conf file and evaluate include statements
# FIXME: circular loops will cause this to block forever
read_slapd_conf() {
merge_logical_lines | while read command data; do
if [ "$command" = "include" ]; then
file=`eval echo $data`
read_slapd_conf < $file
else
echo $command $data
fi
done
}
# Directory names are whitespace-sensitive, but suffixes are not. Discard
# whitespace, so we can create cleaner backup directory names.
canonical_suffix() {
eval echo $1 | sed -e 's/[[:space:]]+//g'
}
# Check if upgrading a database in the named backend is supported by
# our scripts.
supported_backend() {
case "$1" in ldbm|bdb) return 0; esac
return 1
}
# Print out the information about one database
write_database_info() {
backend=$1
suffix=$2
directory=$3
if supported_backend "$backend"; then
# If no directory was given use the compiled in value
if [ -z "$directory" ]; then
# TODO: This should be somewhere in /var - needs tweaking of
# configure.options
directory=/usr/share/ldap/openldap-data
fi
echo $backend '"'$suffix'"' '"'$directory'"'
else
echo "Warning: Backend $backend not supported by automatic upgrade." >&2
fi
}
# Get the list of configured databases from the slapd configuration file
get_database_list() {
(read_slapd_conf < $SLAPD_CONF && echo database) | \
while read command data; do
case $command in
database)
# Write information about previous database section if any
if [ -n "$backend" ] && [ -n "$suffix" ]; then
write_database_info "$backend" "$suffix" "$directory"
fi
backend=$data
suffix=""
directory=""
;;
suffix)
suffix=`canonical_suffix "$data"`
;;
directory)
directory=`eval echo $data`
;;
esac
done
}
# Check if this is the initial configuration and not an upgrade of an
# existing configuration
is_initial_configuration() {
# Plain installation
if [ "$1" = configure ] && [ -z "$2" ]; then
return 0
fi
# Configuration via dpkg-reconfigure
if [ "$1" = reconfigure ] || [ "$DEBCONF_RECONFIGURE" ]; then
return 0
fi
return 1
}
# Check, if the user wants an LDIF dump of the directory
# XXX: Currently dumps unconditionally
ldif_dump_wanted() {
return 0
}
# Ask for the filename of the dump file
# XXX: Currently just uses /var/backups/ldap/$OLD_VERSION/slapd-${suffix}-slapcat.ldif
ldif_dump_location() {
local suffix=$1
echo "/var/backups/ldap/$OLD_VERSION/slapd-${suffix}-slapcat.ldif"
}
# Create directory for dump file
create_ldif_dump_location() {
# Make our backup directory if it does not exist already
if [ -d /var/backups/ldap ]; then
chmod 700 /var/backups/ldap
else
mkdir -p -m 700 /var/backups/ldap
fi
mkdir -p -m 700 /var/backups/ldap/$OLD_VERSION/
}
# Check if a path refers to an empty directory
is_empty_dir() {
output=`find "$1" -type d -maxdepth 0 -empty`
if [ -n "$output" ]; then
return 0
else
return 1
fi
}
|