]> 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:57:23 +0000 (15:57 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 31 Oct 2022 14:57:23 +0000 (15:57 +0100)
scripts/chatbot-to-ldap

index ab12a93bc74edc464486041b70f33bba39b6d0ee..8510aaf9c4b230c5c979e0b8fc6e16c66da377f8 100755 (executable)
@@ -8,6 +8,9 @@ fi
 declare -a ACCOUNTS_REMOVE=()
 declare -A ACCOUNTS_MIGRATE=()
 
+# SIMULATE="n"
+SIMULATE="y"
+
 ACCOUNTS_MIGRATE['angel.ortiz']='angel.ortiz'
 ACCOUNTS_MIGRATE['bjoern.buehring']='bjoern.buehring'
 ACCOUNTS_MIGRATE['daniel.quolke']='daniel.quolke'
@@ -48,6 +51,9 @@ ACCOUNTS_REMOVE+=('tom.juzek')
 ACCOUNTS_REMOVE+=('vasko.mihaylov')
 ACCOUNTS_REMOVE+=('veselin.bochev')
 
+echo
+echo "Executing Puppet agent ..."
+echo
 i=0
 while [[ -e "/opt/puppetlabs/puppet/cache/state/agent_catalog_run.lock" ]] ; do
     modulus=$(( $i % 10 ))
@@ -58,29 +64,44 @@ while [[ -e "/opt/puppetlabs/puppet/cache/state/agent_catalog_run.lock" ]] ; do
     i=$(( $1 + 1 ))
 done
 
-puppet agent --test
+cmd="puppet agent --test"
+if [[ "${SIMULATE}" == "y" ]] ; then
+    echo "Executing: ${cmd}"
+else
+    eval ${cmd}
+fi
 
 echo
-if id kuntz >/dev/null ; then
+if id kuntz >/dev/null 2>&1 ; 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
+if id klaus.kuntz >/dev/null 2>&1 ; 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
 
+echo
+
 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}\""
+        CUR_OWNER=$( stat --format "%U" "${old_home}" )
+        if [[ "${CUR_OWNER}" != "${new_account}" ]] ; then
+            echo "Chowning \"${old_home}\" to user \"${new_account}\": ..."
+            cmd="chown -R \"${new_account}\": \"${old_home}\""
+            if [[ "${SIMULATE}" == "y" ]] ; then
+                echo "Executing: ${cmd}"
+            else
+                eval ${cmd}
+            fi
+        fi
         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."
@@ -95,9 +116,17 @@ echo
 
 for old_account in "${ACCOUNTS_REMOVE[@]}" ; do
     old_home="/home/${old_account}"
+    if id "${old_account}" >/dev/null 2>&1 ; then
+        continue
+    fi
     if [[ -d "${old_home}" ]] ; then
+        cmd="rm -rf \"${old_home}\""
         echo "Removing '${old_home}' ..."
-        echo "rm -rf \"${old_home}\""
+        if [[ "${SIMULATE}" == "y" ]] ; then
+            echo "Executing: ${cmd}"
+        else
+            eval ${cmd}
+        fi
     fi
 done