#!/bin/sh

set -e

## Source debconf library.
. /usr/share/debconf/confmodule

if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ]; then
    db_get ocfs2-tools/init
    O2CB_ENABLED="$RET"
    db_get ocfs2-tools/clustername
    O2CB_BOOTCLUSTER="$RET"
    db_get ocfs2-tools/heartbeat_threshold
    O2CB_HEARTBEAT_THRESHOLD="$RET"
    db_get ocfs2-tools/idle_timeout
    O2CB_IDLE_TIMEOUT_MS="$RET"
    db_get ocfs2-tools/keepalive_delay
    O2CB_KEEPALIVE_DELAY_MS="$RET"
    db_get ocfs2-tools/reconnect_delay
    O2CB_RECONNECT_DELAY_MS="$RET"

    cat > /etc/default/o2cb <<EOF
#
# This is a configuration file for automatic startup of the O2CB
# driver.  It is generated by running 'dpkg-reconfigure ocfs2-tools'.
# Please use that method to modify this file.
#

# O2CB_ENABLED: 'true' means to load the driver on boot.
O2CB_ENABLED=${O2CB_ENABLED:-false}

# O2CB_BOOTCLUSTER: If not empty, the name of a cluster to start.
O2CB_BOOTCLUSTER=${O2CB_BOOTCLUSTER}

# O2CB_HEARTBEAT_THRESHOLD: Iterations before a node is considered dead.
O2CB_HEARTBEAT_THRESHOLD=${O2CB_HEARTBEAT_THRESHOLD}

# O2CB_IDLE_TIMEOUT_MS: Time in ms before a network connection is considered dead.
O2CB_IDLE_TIMEOUT_MS=${O2CB_IDLE_TIMEOUT_MS}

# O2CB_KEEPALIVE_DELAY_MS: Max. time in ms before a keepalive packet is sent.
O2CB_KEEPALIVE_DELAY_MS=${O2CB_KEEPALIVE_DELAY_MS}

# O2CB_RECONNECT_DELAY_MS: Min. time in ms between connection attempts.
O2CB_RECONNECT_DELAY_MS=${O2CB_RECONNECT_DELAY_MS}

EOF

fi

#DEBHELPER#
