#!/usr/bin/env bash
#
# Copyright (C) 2004 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-client,v 1.11 2004/10/26 03:35:13 taru Exp $

set -e

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

id="CLIENT"
. $SHAREDIR/plugin

configure() {
  if test "x$LDAPCONF" != "x"; then
    add_startmark "##" "$id" > $tmp
    $MODULEDIR/client/ldap.conf.sh >> $tmp
    add_endmark "##" "$id" >> $tmp
    add_end_vaconf "$LDAPCONF" "$tmp" "$id"
  fi
  # FIXME: c_rehash path
  if test "x$LDAPTLS_CACERTDIR" != "x"; then
    /bin/rm -rf "$LDAPTLS_CACERTDIR"
    install -d "$LDAPTLS_CACERTDIR"
    if test -d "$TLSSYSCONFDIR"; then
      if test -x "/usr/bin/c_rehash"; then
        find $TLSSYSCONFDIR -name '*.pem' | while read f
        do
          /bin/ln -s $f $LDAPTLS_CACERTDIR
        done
        (cd $LDAPTLS_CACERTDIR; c_rehash . > /dev/null 2>&1 )
      fi
    fi
  fi
}

remove() {
  if test "x$LDAPCONF" != "x"; then
    strip_vaconf "$LDAPCONF" "$id"
  fi
  if test "x$LDAPTLS_CACERTDIR" != "x"; then
    /bin/rm -rf $LDAPTLS_CACERTDIR
  fi
}

update "$1"

