]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Nearly finished scripts/chatbot-to-ldap
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 31 Oct 2022 14:29:16 +0000 (15:29 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 31 Oct 2022 14:29:16 +0000 (15:29 +0100)
scripts/chatbot-to-ldap [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index d491bf3..ab12a93
@@ -1,5 +1,10 @@
 #!/bin/bash
 
+if [[ $(id -u -n) != "root" ]] ; then
+    echo "You must be root to execute this script!" >&2
+    exit 1
+fi
+
 declare -a ACCOUNTS_REMOVE=()
 declare -A ACCOUNTS_MIGRATE=()
 
@@ -29,8 +34,6 @@ ACCOUNTS_MIGRATE['thomas.lewin']='thomas.lewin'
 ACCOUNTS_MIGRATE['tobias.graul']='tobias.graul'
 ACCOUNTS_MIGRATE['tony.walter']='tony.walter'
 
-
-
 ACCOUNTS_REMOVE+=('bettina.lanser')
 ACCOUNTS_REMOVE+=('henning.malzahn')
 ACCOUNTS_REMOVE+=('janeric.gaidusch')
@@ -45,4 +48,56 @@ ACCOUNTS_REMOVE+=('tom.juzek')
 ACCOUNTS_REMOVE+=('vasko.mihaylov')
 ACCOUNTS_REMOVE+=('veselin.bochev')
 
+i=0
+while [[ -e "/opt/puppetlabs/puppet/cache/state/agent_catalog_run.lock" ]] ; do
+    modulus=$(( $i % 10 ))
+    if [[ "${modulus}" == "0" ]] ; then
+        echo "Waiting ..."
+    fi
+    sleep 1
+    i=$(( $1 + 1 ))
+done
+
+puppet agent --test
+
+echo
+if id kuntz >/dev/null ; then
+    echo "On this host there are still the old (hiera based) accounts active." >&2
+    exit 1
+fi
+
+if id klaus.kuntz >/dev/null ; then
+    echo "There seems to be enabled LDAP authentication."
+else
+    echo "There seems NOT to be LDAP authentication on this host." >&2
+    exit 5
+fi
+
+for old_account in "${!ACCOUNTS_MIGRATE[@]}" ; do
+    new_account="${ACCOUNTS_MIGRATE[${old_account}]}"
+    old_home="/home/${old_account}"
+    new_home="/home/${new_account}"
+    if [[ -d "${old_home}" ]] ; then
+        echo "Handling '${old_home}' => '${new_home}' ..."
+        echo "Chowning \"${old_home}\" to user \"${new_account}\": ..."
+        echo "chown -R \"${new_account}\": \"${old_home}\""
+        if [[ "${old_account}" != "${new_account}" ]] ; then
+            if [[ -d "${new_home}" ]] ; then
+                echo "Cannot move '${old_home}' => '${new_home}', because the target dir is already existing."
+            else
+                echo "mv -v \"${old_home}\" \"${new_home}\""
+            fi
+        fi
+    fi
+done
+
+echo
+
+for old_account in "${ACCOUNTS_REMOVE[@]}" ; do
+    old_home="/home/${old_account}"
+    if [[ -d "${old_home}" ]] ; then
+        echo "Removing '${old_home}' ..."
+        echo "rm -rf \"${old_home}\""
+    fi
+done