#!/bin/sh

set -e

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

## be sure to read the values from the config file.
if [ -e /etc/default/o2cb ]; then

    . /etc/default/o2cb

    if [ -z "$O2CB_HEARTBEAT_THRESHOLD" ];then
        O2CB_HEARTBEAT_THRESHOLD=7
    fi
    if [ -z "$O2CB_IDLE_TIMEOUT_MS" ];then
        O2CB_IDLE_TIMEOUT_MS=10000
    fi
    if [ -z "$O2CB_KEEPALIVE_DELAY_MS" ];then
        O2CB_KEEPALIVE_DELAY_MS=5000
    fi
    if [ -z "$O2CB_RECONNECT_DELAY_MS" ];then
   O2CB_RECONNECT_DELAY_MS=2000
    fi

    db_set ocfs2-tools/init "$O2CB_ENABLED"
    db_set ocfs2-tools/clustername "$O2CB_BOOTCLUSTER"
    db_set ocfs2-tools/heartbeat_threshold "$O2CB_HEARTBEAT_THRESHOLD"
    db_set ocfs2-tools/idle_timeout "$O2CB_IDLE_TIMEOUT_MS"
    db_set ocfs2-tools/keepalive_delay "$O2CB_KEEPALIVE_DELAY_MS"
    db_set ocfs2-tools/reconnect_delay "$O2CB_RECONNECT_DELAY_MS"
fi

if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ]; then
    db_input medium ocfs2-tools/init || true
    db_go || true
    db_get ocfs2-tools/init
    if [ "$RET" = "true" ]; then
	db_input medium ocfs2-tools/clustername || true
	db_go || true
	db_input medium ocfs2-tools/heartbeat_threshold || true
	db_go || true
	db_input low ocfs2-tools/idle_timeout || true
	db_go || true
	db_input low ocfs2-tools/keepalive_delay || true
	db_go || true
	db_input low ocfs2-tools/reconnect_delay || true
	db_go || true
    fi
fi

#DEBHELPER#
