#!/bin/bash


echo "开始执行k3s默认的清除内容！"

chmod +x /usr/local/bin/k3s-uninstall.sh
chmod +x /usr/local/bin/k3s-agent-uninstall.sh

/usr/local/bin/k3s-uninstall.sh
/usr/local/bin/k3s-agent-uninstall.sh
rm -rf /root/k3s-install/


echo "开始清理containerd"

echo "关停所有的容器！"
crictl ps -a | grep -v Running | awk '{print $1}' | xargs sudo crictl rm && crictl rmi --prune

echo "清除所有的镜像！"
crictl images -q | xargs -n 1 crictl rmi 2>/dev/null

apt-remove containerd

echo "开始清理docker相关的内容"

docker system df
# 占用存储空间，又没有用的容器
docker images -aq -f 'dangling=true' | xargs docker rmi

# 删除所有
echo "删除所有"
docker system prune -a

echo ""
echo "清除docker运行的容器！"
docker stop $(docker ps -a  | awk '{print $1 }')
docker rm $(docker ps -a  | awk '{print $1 }')


echo "删除镜像"
docker rmi $(docker images | grep "none" | awk '{print $3}')

echo "删除所有镜像 谨慎使用"
docker rmi $(docker images -q) -f

echo ""
echo "开始删除docker的文件"
rm -rf /var/lib/docker

echo " "
echo "开始清理系统残余"
echo ""
apt-get autoremove


echo "开始清理系统日志残留"
rm -rf /var/log/journal/





