-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstallation_checks.sh
232 lines (198 loc) · 5.63 KB
/
installation_checks.sh
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/bash
# Function to print messages in a consistent format
print_message() {
echo -e "\n\033[1;34m$1\033[0m"
}
# Function to print error messages
print_error() {
echo -e "\n\033[1;31mERROR: $1\033[0m"
}
# Check if running as root
if [ "$EUID" -ne 0 ]; then
print_error "This script must be run as root."
exit 1
fi
# Function to check if command executed successfully
check_status() {
if [ $? -eq 0 ]; then
echo "✓ $1 completed successfully"
else
echo "✗ Error: $1 failed"
exit 1
fi
}
# Function to check Docker installation
check_docker() {
if command -v docker &> /dev/null; then
echo "Docker is already installed"
docker --version
if sudo docker run hello-world &> /dev/null; then
echo "Docker is working properly"
return 0
else
echo "Docker is installed but not working properly. Proceeding with repair..."
return 1
fi
else
echo "Docker is not installed"
return 1
fi
}
# Function to check Docker Compose installation
check_docker_compose() {
if docker compose version &> /dev/null; then
echo "Docker Compose (new version) is already installed and working"
docker compose version
return 0
elif docker-compose --version &> /dev/null; then
echo "Old docker-compose found. Will upgrade to new Docker Compose"
return 1
else
echo "Docker Compose is not installed"
return 1
fi
}
# Function to install Docker
install_docker() {
echo "Downloading Docker installation script..."
wget -O get-docker.sh https://get.docker.com
check_status "Docker script download"
chmod +x get-docker.sh
check_status "Setting execute permission"
echo "Installing Docker..."
sudo ./get-docker.sh
check_status "Docker installation"
echo "Starting Docker service..."
sudo systemctl start docker
sudo systemctl enable docker
check_status "Docker service startup"
# Clean up
rm get-docker.sh
}
# Function to setup Docker permissions
setup_docker_permissions() {
# Check if user is already in docker group
if groups $USER | grep &>/dev/null '\bdocker\b'; then
echo "User $USER is already in docker group"
else
echo "Setting up Docker permissions..."
sudo groupadd docker 2>/dev/null || true
sudo usermod -aG docker $USER
check_status "Docker permission setup"
echo "Note: You'll need to log out and log back in for group changes to take effect"
fi
}
# Function to detect OS
detect_os() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
else
echo "Cannot detect OS"
exit 1
fi
}
# Check and install Docker if needed
if ! check_docker; then
install_docker
fi
# Detect OS
detect_os
echo "Detected OS: $OS"
# Setup Docker permissions
setup_docker_permissions
check_jq() {
if command -v jq &> /dev/null; then
echo "jq is already installed"
jq --version
return 0
else
echo "jq is not installed"
return 1
fi
}
install_jq() {
echo "Installing jq..."
if [ "$OS" = "ubuntu" ]; then
sudo apt-get update
sudo apt-get install -y jq
elif [ "$OS" = "centos" ]; then
sudo yum install -y epel-release
sudo yum install -y jq
else
echo "Unsupported OS for jq installation"
exit 1
fi
check_status "jq installation"
}
if ! check_jq; then
install_jq
fi
check_sysstat() {
if command -v sadf &> /dev/null; then
echo "sysstat is already installed"
sysstat --version
return 0
else
echo "sysstat is not installed"
return 1
fi
}
install_sysstat() {
echo "Installing sysstat..."
if [ "$OS" = "ubuntu" ]; then
sudo apt-get update
sudo apt-get install -y sysstat
# Enable sysstat data collection
sudo sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
sudo systemctl enable sysstat
sudo systemctl start sysstat
elif [ "$OS" = "centos" ]; then
sudo yum install -y sysstat
sudo systemctl enable sysstat
sudo systemctl start sysstat
else
echo "Unsupported OS for sysstat installation"
exit 1
fi
check_status "sysstat installation"
}
# Add this code block before creating the telegraf.conf file
if ! check_sysstat; then
install_sysstat
fi
# Main installation process
echo "Starting Docker setup verification..."
# Check and fix Docker Compose
if ! check_docker_compose; then
if command -v docker-compose &> /dev/null; then
echo "Removing old docker-compose..."
if [ "$OS" = "ubuntu" ]; then
sudo apt remove docker-compose
elif [ "$OS" = "centos" ]; then
sudo yum remove docker-compose
fi
fi
echo "Docker Compose plugin will be installed via Docker installation"
# Modern Docker installations include Docker Compose as a plugin
# Verify installation
if ! docker compose version &> /dev/null; then
echo "Installing Docker Compose plugin..."
if [ "$OS" = "ubuntu" ]; then
sudo apt-get update
sudo apt-get install -y docker-compose-plugin
elif [ "$OS" = "centos" ]; then
sudo yum install -y docker-compose-plugin
fi
fi
check_status "Docker Compose installation"
fi
# Final verification
echo -e "\nFinal Verification:"
echo "Docker version:"
docker --version
echo -e "\nDocker Compose version:"
docker compose version
echo -e "\nTesting Docker:"
docker run hello-world
echo -e "\nSetup process completed!"