]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding scripts/manage-users
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 22 Apr 2022 12:59:23 +0000 (14:59 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 22 Apr 2022 12:59:23 +0000 (14:59 +0200)
scripts/manage-users [new file with mode: 0755]

diff --git a/scripts/manage-users b/scripts/manage-users
new file mode 100755 (executable)
index 0000000..300eb24
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+
+for user in $(ls -1 /home ); do
+
+    if [[ -d "/home/${user}" ]] ; then
+
+        echo
+        echo "Performing user: ${user}"
+
+        sudo_name=$( echo "${user}" | sed -e 's/\./_/g' )
+        sudo_file="/etc/sudoers.d/10_${sudo_name}"
+        ak_file="/home/${user}/.ssh/authorized_keys"
+        mailbox="/var/mail/${user}"
+
+        if [[ -f "${sudo_file}" ]] ; then
+            echo "Removing '${sudo_file}' ..."
+            rm -v "${sudo_file}"
+        else
+            echo "File '${sudo_file}' does not exists."
+        fi
+
+        ak_file="/home/${user}/.ssh/authorized_keys"
+
+        if [[ -f "${ak_file}" ]] ; then
+            echo "Removing '${ak_file}' ..."
+            rm -v "${ak_file}"
+        else
+            echo "File '${ak_file}' does not exists."
+        fi
+
+        if [[ -f "${mailbox}" ]] ; then
+            echo "Removing '${mailbox}' ..."
+            rm -v "${mailbox}"
+        else
+            echo "File '${mailbox}' does not exists."
+        fi
+
+        if getent passwd "${user}" ; then
+            echo "Removing user '${user}' ..."
+            userdel "${user}"
+        else
+            echo "User '${user}' does not exists."
+        fi
+
+        sleep 0.5
+
+    fi
+
+done
+
+echo
+echo "Performing group: 'pixel'"
+if getent group 'pixel' ; then
+    echo "Removing group 'pixel' ..."
+    groupdel 'pixel'
+else
+    echo "Group 'pixel' does not exists."
+fi
+
+