|
| 1 | +#!/bin/bash -e |
| 2 | +# |
| 3 | +# Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +# For any questions about this software or licensing, |
| 18 | +# please email opensource@seagate.com or cortx-questions@seagate.com. |
| 19 | +# |
| 20 | +################################## |
| 21 | +# Configure ldap-replication |
| 22 | +################################## |
| 23 | +usage() { echo "Usage: [-h <file containing hostnames of nodes in cluster>] [-p <rootDN password>]" 1>&2; exit 1; } |
| 24 | + |
| 25 | +while getopts ":h:p:" o; do |
| 26 | + case "${o}" in |
| 27 | + h) |
| 28 | + host_list=${OPTARG} |
| 29 | + ;; |
| 30 | + p) |
| 31 | + password=${OPTARG} |
| 32 | + ;; |
| 33 | + *) |
| 34 | + usage |
| 35 | + ;; |
| 36 | + esac |
| 37 | +done |
| 38 | +shift "$((OPTIND-1))" |
| 39 | + |
| 40 | +if [ -z ${host_list} ] || [ -z ${password} ] |
| 41 | +then |
| 42 | + usage |
| 43 | + exit 1 |
| 44 | +fi |
| 45 | + |
| 46 | +INSTALLDIR="/opt/seagate/cortx/s3/install/ldap/replication" |
| 47 | + |
| 48 | +# checkHostValidity will check if all provided hosts are valid and reachable |
| 49 | +checkHostValidity() |
| 50 | +{ |
| 51 | + while read host; do |
| 52 | + isValid=$(ping -c 1 ${host} | grep bytes | wc -l) |
| 53 | + if [ "$isValid" -le 1 ] |
| 54 | + then |
| 55 | + echo "ERROR: $host is either invalid or not reachable." |
| 56 | + exit |
| 57 | + else |
| 58 | + echo "INFO: $host is valid and reachable." |
| 59 | + fi |
| 60 | + done < "$host_list" |
| 61 | +} |
| 62 | + |
| 63 | +# Check if hosts are valid |
| 64 | +checkHostValidity |
| 65 | + |
| 66 | +# getServerIdFromHostFile will generate serverid from host list provided |
| 67 | +id=1 |
| 68 | +getServerIdFromHostFile() |
| 69 | +{ |
| 70 | + while read host; do |
| 71 | + if [ "$host" == "$HOSTNAME" ] |
| 72 | + then |
| 73 | + break |
| 74 | + fi |
| 75 | + id=$(expr ${id} + 1) |
| 76 | + done < "$host_list" |
| 77 | +} |
| 78 | + |
| 79 | +# update serverID |
| 80 | +getServerIdFromHostFile |
| 81 | + |
| 82 | +sed -e "s/\${serverid}/$id/" $INSTALLDIR/serverIdTemplate.ldif > scriptServerId.ldif |
| 83 | +ldapmodify -Y EXTERNAL -H ldapi:/// -f scriptServerId.ldif |
| 84 | +rm scriptServerId.ldif |
| 85 | + |
| 86 | +ldapadd -Y EXTERNAL -H ldapi:/// -f $INSTALLDIR/syncprov_delta.ldif |
| 87 | +ldapadd -Y EXTERNAL -H ldapi:/// -f $INSTALLDIR/index_delta.ldif |
| 88 | + |
| 89 | +# update replication config |
| 90 | +echo "dn: olcDatabase={2}mdb,cn=config" > scriptConfig.ldif |
| 91 | +echo "changetype: modify" >> scriptConfig.ldif |
| 92 | +echo "add: olcSyncRepl" >> scriptConfig.ldif |
| 93 | +rid=1 |
| 94 | +while read host; do |
| 95 | + if [ "$host" != "$HOSTNAME" ] |
| 96 | + then |
| 97 | + sed -e "s/\${rid}/$rid/" -e "s/\${provider}/$host/" -e "s/\${credentials}/$password/" $INSTALLDIR/deltaConfigTemplate.ldif >> scriptConfig.ldif |
| 98 | + rid=`expr ${rid} + 1` |
| 99 | + fi |
| 100 | +done <$host_list |
| 101 | + |
| 102 | +echo "-" >> scriptConfig.ldif |
| 103 | +echo "add: olcMirrorMode" >> scriptConfig.ldif |
| 104 | +echo "olcMirrorMode: TRUE" >> scriptConfig.ldif |
| 105 | + |
| 106 | +ldapmodify -Y EXTERNAL -H ldapi:/// -f scriptConfig.ldif |
| 107 | +rm scriptConfig.ldif |
0 commit comments