]> Frank Brehm's Git Trees - pixelpark/ldap-migration.git/commitdiff
Parametrizing environment and its dependend variables
authorFrank Brehm <frank@brehm-online.com>
Tue, 8 Feb 2022 09:55:24 +0000 (10:55 +0100)
committerFrank Brehm <frank@brehm-online.com>
Tue, 8 Feb 2022 09:55:24 +0000 (10:55 +0100)
after-migration.sh

index b6f8e1a573ae183d0ce41dabad6704d03955a0be..1c7b74cac02e07e5c25e30533f12cbb9685c8587 100755 (executable)
@@ -24,19 +24,36 @@ cd "${BASE_DIR}" || exit 99
 BASE_DIR=$( readlink -f . )
 
 LDAP_USR="cn=admin"
-# LDAP_URL="ldaps://dev-ldap2.pixelpark.com"
-LDAP_URL="ldaps://prd-ds.pixelpark.com"
-# LDAP_PWD_FILE="${HOME}/.private/dirsrv-dev-dpx-admin-pwd-wonl.txt"
-LDAP_PWD_FILE="${HOME}/.private/dirsrv-prd-dpx-admin-pwd-wonl.txt"
 LDAP_BASE="o=isp"
 GLOBAL_SEARCH_BASE="o=isp"
 DPX_SEARCH_BASE="o=Pixelpark,o=isp"
 DPX_PEOPLE_SEARCH_BASE="ou=People,${DPX_SEARCH_BASE}"
 SERVICE_SP_SEARCH_BASE="ou=service_sp,ou=Applications,${DPX_SEARCH_BASE}"
 
+ENVIRONMENT="prd"
+
+declare -A LDAP_URIS=()
+LDAP_URIS['prd']="ldaps://prd-ds.pixelpark.com"
+LDAP_URIS['test']="ldaps://test-ds.pixelpark.com"
+LDAP_URIS['dev']="ldaps://dev-ldap2.pixelpark.com"
+
+LDAP_URL="${LDAP_URIS['prd']}"
+
+declare -A LDAP_PWD_FILES=()
+LDAP_PWD_FILES['prd']="${HOME}/.private/dirsrv-prd-dpx-admin-pwd-wonl.txt"
+LDAP_PWD_FILES['test']="${HOME}/.private/dirsrv-test-dpx-admin-pwd-wonl.txt"
+LDAP_PWD_FILES['dev']="${HOME}/.private/dirsrv-dev-dpx-admin-pwd-wonl.txt"
+
+LDAP_PWD_FILE="${LDAP_PWD_FILES['prd']}"
+
 OLD_IMAP_SERVER='mail-brln-store02.pixelpark.com'
-# NEW_IMAP_SERVER='dev-imap01.pixelpark.com'
-NEW_IMAP_SERVER='prd-imap01.pixelpark.com'
+
+declare -A NEW_IMAP_SERVERS=()
+NEW_IMAP_SERVERS['prd']="prd-imap01.pixelpark.com"
+NEW_IMAP_SERVERS['test']="prd-imap01.pixelpark.com"
+NEW_IMAP_SERVERS['dev']="idev-imap01.pixelpark.com"
+
+NEW_IMAP_SERVER="${NEW_IMAP_SERVERS['prd']}"
 
 LDIF_FILE=
 
@@ -145,8 +162,10 @@ error() {
 #------------------------------------------------------------------------------
 description() {
     cat <<-EOF
-       Updates in NLAP the Password of Frank Brehm and moves the mailHost
-       from '${OLD_IMAP_SERVER}' to '${NEW_IMAP_SERVER}'.
+
+       Updates in LDAP the passwords of the members of the department 'Betrieb',
+       adds the public SSH keys of them, adds some additional LDAP objects like groups,
+       adds standard ACIs and moves the mailHost from '${CYAN}${OLD_IMAP_SERVER}${NORMAL}' to the new one.
 
        EOF
 
@@ -172,11 +191,14 @@ empty_line() {
 usage() {
 
     cat <<-EOF
-       Usage: ${BASENAME} [-s|--simulate] [-d|--debug] [[-v|--verbose] | [-q|--quiet]] [--nocolor]
+       Usage: ${BASENAME} [-E|--env ENVIRONMENT] [-s|--simulate] [-d|--debug] [[-v|--verbose] | [-q|--quiet]] [--nocolor]
               ${BASENAME} [-h|--help]
               ${BASENAME} [-V|--version]
 
            Options:
+               -E|--env|--environment ENVIRONMENT
+                               The LDAP environment to use as the target of this script.
+                               Must be one of '${CYAN}prd${NORMAL}', '${CYAN}test${NORMAL}' or '${CYAN}dev${NORMAL}'. Default: '${CYAN}prod${NORMAL}'."
                -s|--simulate   Simulation mode, nothing is really done.
                -d|--debug      Debug output (bash -x).
                -v|--verbose    Set verbosity on.
@@ -193,8 +215,8 @@ usage() {
 get_options() {
 
     local tmp=
-    local short_options="sdvqhV"
-    local long_options="simulate,debug,verbose,quiet,help,version"
+    local short_options="E:sdvqhV"
+    local long_options="env:,environment:,simulate,debug,verbose,quiet,help,version"
     local py_version=
     local py_found="n"
     local ret=
@@ -204,7 +226,7 @@ get_options() {
     ret="$?"
     if [[ "${ret}" != 0 ]] ; then
         echo "" >&2
-        usage >&2
+        echo -e "$( usage )" >&2
         exit 1
     fi
     set -e
@@ -214,6 +236,11 @@ get_options() {
 
     while true ; do
         case "$1" in
+            -E|--env|--environment)
+                ENVIRONMENT="$2"
+                shift
+                shift
+                ;;
             -s|--simulate)
                 SIMULATE="y"
                 shift
@@ -248,9 +275,9 @@ get_options() {
                 shift
                 ;;
             -h|--help)
-                description
+                echo -e "$( description )"
                 echo
-                usage
+                echo -e "$( usage )"
                 exit 0
                 ;;
             -V|--version)
@@ -273,9 +300,26 @@ get_options() {
     if [[ "${VERBOSE}" == "y" && "${QUIET}" == "y" ]] ; then
         error "Options '${RED}--verbose${NORMAL}' and '${RED}--quiet${NORMAL}' are mutually exclusive."
         echo >&2
-        usage >&2
+        echo -e "$( usage )" >&2
+        exit 1
+    fi
+
+    if [[ "${ENVIRONMENT}" != 'prd' && "${ENVIRONMENT}" != 'test' && "${ENVIRONMENT}" != 'dev' ]] ; then
+        error "Wrong environment '${RED}${ENVIRONMENT}${NORMAL}' given."
+        echo >&2
+        echo -e "$( usage )" >&2
         exit 1
     fi
+    LDAP_URL="${LDAP_URIS[${ENVIRONMENT}]}"
+    LDAP_PWD_FILE="${LDAP_PWD_FILES[${ENVIRONMENT}]}"
+    NEW_IMAP_SERVER="${NEW_IMAP_SERVERS[${ENVIRONMENT}]}"
+
+    local msg="Environment '${CYAN}${ENVIRONMENT}${NORMAL}':\n"
+    msg+="   ${CYAN}*${NORMAL} LDAP URL:        '${CYAN}${LDAP_URL}${NORMAL}'\n"
+    msg+="   ${CYAN}*${NORMAL} Password file:   '${CYAN}${LDAP_PWD_FILE}${NORMAL}'\n"
+    msg+="   ${CYAN}*${NORMAL} New IMAP server: '${CYAN}${NEW_IMAP_SERVER}${NORMAL}'\n"
+
+    info "${msg}"
 
     if [[ ! -f "${LDAP_PWD_FILE}" ]] ; then
         error "Password file '${RED}${LDAP_PWD_FILE}${NORMAL}' not found" >&2
@@ -851,7 +895,7 @@ add_uid_pool() {
     max_uid=$(( ${max_uid} + 1 ))
     debug "uidNumber of pool: ${CYAN}${max_uid}${NORMAL}."
 
-    cn=$( echo "${dn}" | sed -e 's/,.*//' | awk -F= '{ print $2 }'
+    cn=$( echo "${dn}" | sed -e 's/,.*//' | awk -F= '{ print $2 }' )
     debug "Common name of pool: '${CYAN}${cn}${NORMAL}'."
 
     cat > "${LDIF_FILE}" <<-EOF
@@ -920,7 +964,7 @@ add_gid_pool() {
     max_gid=$(( ${max_gid} + 1 ))
     debug "gidNumber of pool: ${CYAN}${max_gid}${NORMAL}."
 
-    cn=$( echo "${dn}" | sed -e 's/,.*//' | awk -F= '{ print $2 }'
+    cn=$( echo "${dn}" | sed -e 's/,.*//' | awk -F= '{ print $2 }' )
     debug "Common name of pool: '${CYAN}${cn}${NORMAL}'."
 
     cat > "${LDIF_FILE}" <<-EOF