#!/bin/bash
checkcode () {
    if [ -z "$1" ]; then
        echo "Error! Use Checkcode like checkcode \$?" >&2
        exit 1
    fi

    retcode=$1

    if [ ! $retcode -eq 0 ]; then
        printf " \033[0;31mError Code: $retcode\033[0m\n"
    else
        printf " \033[0;32mOK!\033[0m\n"
    fi

}

echo -e "\n\033[0;31mCRASHING DOCKER AND EVERYTHING IN IT WITH NO SURVIVORS\033[0m\n"

echo -n "1/9: Stopping Docker... "
sudo docker stop $(sudo docker ps -a -q) >/dev/null 2>&1
checkcode $?

echo -n "2/9 Removing Docker Containers..."
sudo docker rm -v $(sudo docker ps -a -q) >/dev/null 2>&1
checkcode $?

echo -n "3/9 Removing Docker Images..."
sudo docker rmi $(sudo docker images -a -q) >/dev/null 2>&1
checkcode $?

echo -n "4/9 Removing Docker Volumes..."
sudo docker volume rm $(sudo docker volume ls -q) >/dev/null 2>&1
checkcode $?

echo -n "5/9 Removing Docker Networks..."
sudo docker network rm $(sudo docker network ls -q) >/dev/null 2>&1
checkcode $?

echo -n "6/9 Stopping Docker Daemon..."
sudo systemctl stop docker >/dev/null 2>&1
checkcode $?

echo -n "7/9 Disabling Docker Daemon Start At Boot..."
sudo systemctl disable docker >/dev/null 2>&1
checkcode $?

echo -n "8/9 Updating Package Repos..."
sudo apt update >/dev/null 2>&1
checkcode $?

echo -n "9/9 Removing and Purging docker.io and docker-compose"
sudo apt purge docker.io docker-compose -y >/dev/null 2>&1
checkcode $?

echo -e "\n\n\033[0;32mdonesies docker gone and purged\033[0m\n\n"