#!/bin/bash
#------------------------------------------------
#scvldapconf - /var/www/html/scv/.scvldapconf を編集
PROGVER="3.1.0"
#2019/10/08
#Copyright J's Communication co.,ltd.
#------------------------------------------------
usage() {
  echo "scv ldap config editor $PROGVER"
  echo "scvldapconf -show   ;show scvldapconf"
  echo "scvldapconf -nano   ;edit scvldapconf using nano editor"
  echo "scvldapconf -vi     ;edit scvldapconf using vi editor"
  exit 1
}

#------------------------------------------------
PCOUNT=$#
if [ $PCOUNT -eq 0 ]; then
  usage
fi

LDAPCONF="/var/www/html/scv/.scvldapconf"

CLUSTER=`/usr/local/bin/scvclustd -cluster`
ROLE=`/usr/local/bin/scvclustd -role`

if [ -e $LDAPCONF ]; then
  :
else
  sudo touch $LDAPCONF
  sudo chown www-data:docker $LDAPCONF
  sudo chmod 660 $LDAPCONF
  sudo echo '[ldapconf]'  >> $LDAPCONF
  sudo echo 'HOST='       >> $LDAPCONF
  sudo echo 'PORT='       >> $LDAPCONF
  sudo echo 'BINDDN='     >> $LDAPCONF
  sudo echo 'BINDPWD='    >> $LDAPCONF
  sudo echo "BASEDN="     >> $LDAPCONF
fi

case "${1}" in
  "-show" ) sudo less $LDAPCONF ;;
  "-nano" ) sudo nano $LDAPCONF ;;
  "-vi"   ) sudo vi $LDAPCONF ;;
  * ) usage ;;
esac

if [ "$CLUSTER" = "1" ]; then
  echo cluster
  echo should be copy the file to all cluster servers from master.
fi


exit 0
#eof

