#!/bin/bash

#Preupgrade Assistant performs system upgradability assessment
#and gathers information required for successful operating system upgrade.
#Copyright (C) 2013 Red Hat Inc.
#Jakub Mazanek <jmazanek@redhat.com>
#
#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 3 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.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.
. /usr/share/preupgrade/common.sh
check_applies_to "openldap-servers"
#END GENERATED SECTION
if [ -z $SOLUTION_FILE ]; then
  SOLUTION_FILE="./solution.txt"
fi
cat /dev/null > $SOLUTION_FILE
confile='/etc/openldap/slapd.conf'
confdir='/etc/openldap/'
cust_confile='<your_configuration_file>'
cp --parents -ar $confdir $VALUE_TMP_PREUPGRADE/dirtyconf/


if ! [ -e "$confile" ];then
   echo " The $confile configuration file does not exist. If you have the slapd configuration file in an alternative location, type 
the following command to test its consistency:
slaptest -v -f $cust_confile" >> $SOLUTION_FILE
   echo "It is recommended to use a new directory format of the slapd configuration in Red Hat Enterprise Linux 7. If you want to migrate your slapd configuration to the new format, type:
slaptest -f $cust_confile -F $confdir
chown -R ldap:ldap $cust_confdir " >> $SOLUTION_FILE
   log_medium_risk "A directory format is recommended for the slapd configuration."
   exit_fail
else
   echo "It is recommended to use a new directory format of the slapd configuration in Red Hat Enterprise Linux 7. If you want to migrate your slapd configuration to the new format, type:
slaptest -f $confile -F $confdir
chown -R ldap:ldap $confdir " >> $SOLUTION_FILE
  slaptest -v -f "$confile" 2>&1 | grep "database ldbm" > /dev/null
   if [[ "$?" -eq 0 ]];then

      echo "Change the database directive in the $confile file to 'bdb'." >> $SOLUTION_FILE
      log_high_risk "The back-ldbm database back end is obsolete and should not be used."
      exit_fail
   else
      log_medium_risk "A directory format is recommended for the slapd configuration."
      exit_fail
   fi
fi
