# Common postfix maintscripts functions
#
# note: this file is used by old (<<3.9.0) postfix prerm scripts!

DYNAMICMAPS=/etc/postfix/dynamicmaps.cf

addmap() {
    map=$1 mkmap="$2"; re="^$map[[:space:]]"
    ! grep -qs "$re" $DYNAMICMAPS || return 0	# already exists
    # use official line if known
    if ! line="$(grep "$re" /usr/share/postfix/dynamicmaps.cf)"; then
	case "$map$mkmap" in  ## skip if mkmap is given in $2
	    (cdb|lmdb|sdbm) mkmap="mkmap_${map}_open" ;;
	esac
	line="$map		postfix-$map.so		dict_${map}_open	$mkmap"
    fi
    echo "Registering Postfix dynamic map entry $map in $DYNAMICMAPS"
    echo "$line" >> $DYNAMICMAPS
}

delmap() {
    map=$1
    if grep -qs "^$map[[:space:]]" $DYNAMICMAPS; then
	 echo "Removing $map map entry from $DYNAMICMAPS"
	 sed -i "/^$map[[:space:]]/d" $DYNAMICMAPS
    fi
}

runnewaliases() { # used by postfix and dynamicmaps postinst in <3.9.1-3
  :
}
