-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_greencloud.sh
More file actions
78 lines (64 loc) · 1.9 KB
/
Copy pathremove_greencloud.sh
File metadata and controls
78 lines (64 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
set -e
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Spinner animation
spin() {
local pid=$!
local delay=0.1
local spinstr='|/-\\'
while ps -p $pid > /dev/null 2>&1; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
# Step counter
step=1
total=4
step_progress() {
echo -e "${CYAN}Step $step of $total: $1${NC}"
((step++))
}
# Prompt user for GreenCloud API key and login
gccli logout -q > /dev/null 2>&1
echo -e "\n${CYAN}Please enter your GreenCloud API key:${NC}"
read -r API_KEY
gccli login -k "$API_KEY" > /dev/null 2>&1
# Extract and display GreenCloud Node ID
echo -e "\n${CYAN}Extracting GreenCloud Node ID...${NC}"
systemctl restart gcnode
sleep 2
NODE_ID=$(systemctl status gcnode | grep -oP '(?<=ID → )[a-f0-9-]+')
echo -e "${GREEN}✔ Captured Node ID: $NODE_ID${NC}"
# Removing node from GreenCloud using captured NODE_ID
echo -e "\n${CYAN}Removing node from GreenCloud...${NC}"
systemctl stop gcnode
gccli node delete -i $NODE_ID #> /dev/null 2>&1
echo -e "${GREEN}✔ Node removed successfully!${NC}"
# Begin script
step_progress "Removing containerd..."
(apt remove -y containerd) > /dev/null 2>&1 & spin
echo -e "${GREEN}✔ containerd removed${NC}"
step_progress "Removing runc..."
(apt remove runc -y) > /dev/null 2>&1 & spin
echo -e "${GREEN}✔ runc removed${NC}"
step_progress "Removing GreenCloud Node and CLI..."
(
rm -r /var/lib/greencloud
rm /usr/local/bin/gccli
) & spin
echo -e "${GREEN}✔ GreenCloud node and CLI removed"
step_progress "Removing gcnode systemd service..."
(
rm /etc/systemd/system/gcnode.service
systemctl daemon-reload
) > /dev/null 2>&1 & spin
echo -e "${GREEN}✔ gcnode service removed${NC}"
echo -e "\n${YELLOW}🎉 All $((step - 1)) removal steps completed successfully!${NC}"