#!/bin/bash

#auto_install_pid=`ps -aux | grep auto_install | grep -v grep | awk -F " " '{print $2}'`
#kill -9 $auto_install_pid
echo "destroy k8s allinone default start"
docker exec -it kubeasz ezctl destroy default &
# nerdctl exec -it kubeasz ezctl destroy default
sleep 5
systemctl restart docker
sleep 5
#kubeasz_pid=`docker ps | grep kubeasz | awk -F " " '{print $1}'`
echo "#########################################################"
#echo "kubeasz_pid="$kubeasz_pid
#docker stop "$kubeasz_pid"
#docker rm "$kubeasz_pid"
cd "$install_path"/soft && ./ezdown -C
docker system prune -a
systemctl stop docker
systemctl disable containerd

rm -rf /etc/kubeasz
rm -rf /etc/kube
rm -rf /usr/bin/containerd*
rm -rf /usr/bin/ctr
rm -rf /usr/bin/docker
rm -rf /usr/bin/dockerd
rm -rf /usr/bin/docker-init
rm -rf /usr/bin/docker-proxy
rm -rf /usr/bin/runc
rm -rf /etc/docker
rm -rf /var/lib/docker
rm -rf /etc/kubernetes
rm -rf /etc/kube-lb
rm -rf /opt/kube
rm -rf /run/containerd
rm -rf /usr/bin/containerd
rm -rf /opt/containerd
rm -rf /usr/local/bin/docker-compose
rm -rf /run/docker
rm -rf /home/edoc2/macrowing/docker
rm -rf /var/run/docker
rm -rf /var/lib/etcd
rm -rf /home/edoc2
rm -rf /kube/bin/etcd
rm -rf /etc/calico
rm -rf /var/lib/dockershim
rm -rf /var/lib/calico
rm -rf /var/lib/kube*
rm -rf /root/.kube
rm -rf /var/lib/cni
rm -rf /var/lib/containerd
rm -rf /etc/systemd/system/kube*
rm -rf /etc/containerd
rm -rf /etc/cni

file="/root/.bashrc"
pattern1="kubeasz"
pattern2="kubectl"
pattern3="crictl"
# 创建临时文件
temp_file1="/tmp/file1"
temp_file2="/tmp/file2"
temp_file3="/tmp/file3"
# 使用 grep 命令过滤掉匹配到的行，并将结果输出到临时文件
grep -v "$pattern1" "$file" > "$temp_file1"
mv -f "$temp_file1" "$file"
rm -rf "$temp_file1"
sleep 1
grep -v "$pattern2" "$file" > "$temp_file2"
mv -f "$temp_file2" "$file"
rm -rf "$temp_file2"
sleep 1
grep -v "$pattern3" "$file" > "$temp_file3"
mv -f "$temp_file3" "$file"
rm -rf "$temp_file3"

echo "destroy k8s allinone default finished"
sleep 8
rm -rf /root/.ssh/*
sleep 3
reboot
