summaryrefslogtreecommitdiffstats
path: root/lcpubsh/bin/nuke.sh
diff options
context:
space:
mode:
authorGeorg2021-08-14 20:38:16 +0200
committerGeorg2021-08-14 20:38:16 +0200
commit39e54cc83b2d4d78191ada3dceafa22208336641 (patch)
tree5223463e800b43ff22b4b6c444c49cc2759724ea /lcpubsh/bin/nuke.sh
parentc27753da863b3c44ceb81b2fe6ac689550704f89 (diff)
downloadpublic-shell-master.tar.gz
public-shell-master.tar.bz2
public-shell-master.zip
Improvements 14/08/2021HEADmaster
Signed-off-by: Georg <georg@lysergic.dev>
Diffstat (limited to 'lcpubsh/bin/nuke.sh')
-rw-r--r--lcpubsh/bin/nuke.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/lcpubsh/bin/nuke.sh b/lcpubsh/bin/nuke.sh
new file mode 100644
index 0000000..33e3aed
--- /dev/null
+++ b/lcpubsh/bin/nuke.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+# georg@lysergic.dev
+set -e
+OUTPUT="nc -N 127.0.0.2 2424"
+echo "Shell removal invoked." | $OUTPUT
+if [ ! "$#" -eq 0 ]; then
+user="$(echo "$1" |tr '[:upper:]' '[:lower:]')"
+if id "$user" &>/dev/null; then
+ CONTAINER="$(docker ps -qf "name=$user")"
+ echo "User: $user - Container ID: $CONTAINER" | $OUTPUT
+ if [ ! -z "$CONTAINER" ]; then
+ docker stop $CONTAINER
+ if [ $? -eq "0" ]; then
+ echo "Running shell found and stopped."
+ else
+ echo "Shell could not be stopped. Maybe it's lready down?"
+ fi
+ docker rm $CONTAINER
+ if [ $? -eq "0" ]; then
+ echo "Shell container found and removed."
+ else
+ echo "Shell could not be removed. Maybe it doesn't exist?"
+ fi
+ else
+ echo "ID could not be determined."
+ fi
+ sudo /usr/sbin/userdel -f $user | $OUTPUT
+ sudo /usr/sbin/groupdel -f $user | $OUTPUT
+ sudo /usr/bin/rm -rf /home/$user
+ sudo /usr/bin/rm -rf /var/spool/mail/$user
+ INITEMP=$(mktemp --tmpdir initemp.XXXXX)
+ trap "rm -f $INITEMP" 0 1 2 3 15
+ sed "/$user/d" "/etc/dockersh.ini" > "$INITEMP"
+ cat "$INITEMP" > /etc/dockersh.ini
+ echo "Done." | $OUTPUT
+ echo "OK."
+else
+ echo "Aborted: User not found."
+fi
+else
+ echo "No argument supplied."
+fi