#!/usr/bin/env bash
#
# Copyright (C) 2003 VA Linux Systems Japan, K.K.
#
# LICENSE NOTICE
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#

# $Id: update-vaj-robust,v 1.4 2004/04/02 02:34:15 taru Exp $

set -e

eval `ultrapossum-config init`

tmp=`tempfile`
trap "/bin/rm -f $tmp; eval `ultrapossum-config term`" 0

configure() {
  id="VAJ-ROBUST"
  if test "x$RPLOCK" != "x" && test "x$BACKUP$SLAVES" != "x"; then
    add_startmark "##" $id > $tmp
    echo "replockfile $RPLOCK" >> $tmp
    add_endmark "##" $id >> $tmp
    add_end_vaconf $SLAPDCONF $tmp $id
  else
    remove
  fi
}

remove() {
  if test -f $SLAPDCONF; then strip_vaconf $SLAPDCONF $id; fi
}

sanity() {
  :
}

case "x$1" in
        xconfigure)
                configure
  		ultrapossum-config set .status ULTRAPOSSUM_MODULE_VAJ_ROBUST=installed
		/bin/rm -f $CONFSTATUS
        ;;
        xremove)
                remove
  		ultrapossum-config remove .status ULTRAPOSSUM_MODULE_VAJ_ROBUST
		/bin/rm -f $CONFSTATUS
        ;;
        xsanity)
                sanity
        ;;
        x)
                echo "Usage: $0 <configure|remove|sanity>" 1>&2
                exit 1
        ;;
        x*)
                echo "Unknown argument: $1" 1>&2
                exit 1
        ;;
esac

