-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-nextcloud-aio.sh
More file actions
373 lines (314 loc) · 15.1 KB
/
install-nextcloud-aio.sh
File metadata and controls
373 lines (314 loc) · 15.1 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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/bin/bash
# Universal Nextcloud All-in-One Installation Script
# Compatible with: Ubuntu, Debian, AlmaLinux, Rocky Linux, CentOS, Fedora
# Automatically adapts to the distribution and version
LOG_FILE="/nextcloudinstall.log"
# Function to log messages to both console and log file
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
}
# Function to handle errors
error_exit() {
log "ERROR: $1"
log "Installation failed. Please check the log for details."
exit 1
}
# Create log file with header
echo "Nextcloud AIO Installation Log - $(date '+%Y-%m-%d %H:%M:%S')" > "$LOG_FILE"
echo "===================================================" >> "$LOG_FILE"
# Check if running as root
if [ "$(id -u)" -ne 0 ]; then
error_exit "This script must be run as root. Use 'sudo' or log in as root."
fi
# Detect Linux distribution
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
VERSION=$VERSION_ID
DISTRO_FAMILY=""
# Determine distribution family
if [[ "$DISTRO" == "ubuntu" || "$DISTRO" == "debian" || "$DISTRO" == "raspbian" ]]; then
DISTRO_FAMILY="debian"
elif [[ "$DISTRO" == "almalinux" || "$DISTRO" == "rocky" || "$DISTRO" == "centos" || "$DISTRO" == "rhel" || "$DISTRO" == "fedora" ]]; then
DISTRO_FAMILY="rhel"
else
log "Detected distribution: $DISTRO $VERSION"
log "This is not a well-known distribution. Attempting to detect package manager..."
# Try to detect package manager
if command -v apt &> /dev/null; then
DISTRO_FAMILY="debian"
elif command -v dnf &> /dev/null || command -v yum &> /dev/null; then
DISTRO_FAMILY="rhel"
else
error_exit "Unsupported Linux distribution. This script supports Debian/Ubuntu and RHEL-based distributions."
fi
fi
log "Detected distribution: $DISTRO $VERSION (Family: $DISTRO_FAMILY)"
else
error_exit "Could not detect Linux distribution. /etc/os-release file not found."
fi
# Function to install Docker on Debian-based systems (Ubuntu, Debian)
install_docker_debian() {
log "Installing Docker on Debian-based system..."
# Update package index
log "Updating package index..."
apt-get update -y >> "$LOG_FILE" 2>&1 || error_exit "Failed to update package index."
# Install prerequisites
log "Installing prerequisites..."
apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release software-properties-common >> "$LOG_FILE" 2>&1 || error_exit "Failed to install prerequisites."
# Add Docker's official GPG key
log "Adding Docker's GPG key..."
# Remove any old Docker GPG keys and repos to avoid conflicts
rm -f /etc/apt/keyrings/docker.gpg /usr/share/keyrings/docker-archive-keyring.gpg 2>/dev/null
rm -f /etc/apt/sources.list.d/docker.list 2>/dev/null
# Method for Ubuntu 22.04+ and Debian 11+
if mkdir -p /etc/apt/keyrings 2>/dev/null; then
curl -fsSL https://download.docker.com/linux/${DISTRO}/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg >> "$LOG_FILE" 2>&1
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/${DISTRO} $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
# Fallback method for older distributions
else
curl -fsSL https://download.docker.com/linux/${DISTRO}/gpg | apt-key add - >> "$LOG_FILE" 2>&1
add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/${DISTRO} $(lsb_release -cs) stable" >> "$LOG_FILE" 2>&1
fi
if [ $? -ne 0 ]; then
error_exit "Failed to add Docker repository."
fi
# Update package index again
log "Updating package index with Docker repository..."
apt-get update -y >> "$LOG_FILE" 2>&1 || error_exit "Failed to update package index."
# Install Docker
log "Installing Docker packages..."
apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin >> "$LOG_FILE" 2>&1
# If installation failed, try alternative method for older systems
if [ $? -ne 0 ]; then
log "Standard installation failed. Trying alternative method..."
apt-get install -y docker.io >> "$LOG_FILE" 2>&1 || error_exit "Failed to install Docker."
fi
# Verify installation
docker --version >> "$LOG_FILE" 2>&1 || error_exit "Docker installation verification failed."
log "Docker installed successfully."
# Enable and start Docker service
log "Enabling and starting Docker service..."
systemctl enable docker >> "$LOG_FILE" 2>&1
systemctl start docker >> "$LOG_FILE" 2>&1 || error_exit "Failed to start Docker service."
}
# Function to install Docker on RHEL-based systems (AlmaLinux, Rocky Linux, CentOS, Fedora)
install_docker_rhel() {
log "Installing Docker on RHEL-based system..."
# Install prerequisites
log "Installing prerequisites..."
if command -v dnf &> /dev/null; then
dnf install -y dnf-plugins-core >> "$LOG_FILE" 2>&1 || error_exit "Failed to install prerequisites."
# Add Docker repository
log "Adding Docker repository..."
# Different repository handling based on distribution
if [[ "$DISTRO" == "fedora" ]]; then
dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo >> "$LOG_FILE" 2>&1
else
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo >> "$LOG_FILE" 2>&1
fi
if [ $? -ne 0 ]; then
error_exit "Failed to add Docker repository."
fi
# Install Docker
log "Installing Docker packages..."
dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin >> "$LOG_FILE" 2>&1
# If installation fails, try alternative method
if [ $? -ne 0 ]; then
log "Standard installation failed. Trying alternative method..."
dnf install -y docker >> "$LOG_FILE" 2>&1 || error_exit "Failed to install Docker."
fi
else
# Fallback to yum for older systems
yum install -y yum-utils >> "$LOG_FILE" 2>&1 || error_exit "Failed to install prerequisites."
# Add Docker repository
log "Adding Docker repository..."
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo >> "$LOG_FILE" 2>&1 || error_exit "Failed to add Docker repository."
# Install Docker
log "Installing Docker packages..."
yum install -y docker-ce docker-ce-cli containerd.io >> "$LOG_FILE" 2>&1
# If installation fails, try alternative method
if [ $? -ne 0 ]; then
log "Standard installation failed. Trying alternative method..."
yum install -y docker >> "$LOG_FILE" 2>&1 || error_exit "Failed to install Docker."
fi
fi
# Verify installation
docker --version >> "$LOG_FILE" 2>&1 || error_exit "Docker installation verification failed."
log "Docker installed successfully."
# Enable and start Docker service
log "Enabling and starting Docker service..."
systemctl enable docker >> "$LOG_FILE" 2>&1
systemctl start docker >> "$LOG_FILE" 2>&1 || error_exit "Failed to start Docker service."
}
# Install Docker based on distribution family
if [ "$DISTRO_FAMILY" == "debian" ]; then
install_docker_debian
elif [ "$DISTRO_FAMILY" == "rhel" ]; then
install_docker_rhel
else
error_exit "Unsupported Linux distribution family: $DISTRO_FAMILY"
fi
# Configure IPv6 support for Docker
log "Configuring IPv6 support for Docker..."
mkdir -p /etc/docker
cat > /etc/docker/daemon.json << 'EOF'
{
"ipv6": true,
"fixed-cidr-v6": "fd00::/80",
"experimental": true,
"ip6tables": true
}
EOF
# Check if SELinux is enabled (common in RHEL-based systems)
if command -v getenforce &> /dev/null && [ "$(getenforce)" != "Disabled" ]; then
log "SELinux detected, adding necessary context for Docker socket..."
if [ -e /var/run/docker.sock ]; then
chcon -t container_file_t /var/run/docker.sock >> "$LOG_FILE" 2>&1 || log "Warning: Could not change SELinux context of docker.sock"
fi
fi
# Restart Docker to apply new configurations
log "Restarting Docker service..."
systemctl restart docker >> "$LOG_FILE" 2>&1 || error_exit "Failed to restart Docker service."
log "Docker service restarted successfully."
# Configure firewall if present
configure_firewall() {
log "Checking for firewall and configuring if necessary..."
# For systems with firewalld (RHEL-based typically)
if command -v firewall-cmd &> /dev/null; then
log "firewalld detected, configuring ports..."
firewall-cmd --permanent --add-port=80/tcp >> "$LOG_FILE" 2>&1
firewall-cmd --permanent --add-port=8080/tcp >> "$LOG_FILE" 2>&1
firewall-cmd --permanent --add-port=8443/tcp >> "$LOG_FILE" 2>&1
firewall-cmd --permanent --add-port=3478/tcp >> "$LOG_FILE" 2>&1
firewall-cmd --permanent --add-port=3478/udp >> "$LOG_FILE" 2>&1
firewall-cmd --reload >> "$LOG_FILE" 2>&1
log "firewalld configured successfully."
# For systems with ufw (Ubuntu/Debian typically)
elif command -v ufw &> /dev/null && ufw status | grep -q "active"; then
log "ufw detected and active, configuring ports..."
ufw allow 80/tcp >> "$LOG_FILE" 2>&1
ufw allow 8080/tcp >> "$LOG_FILE" 2>&1
ufw allow 8443/tcp >> "$LOG_FILE" 2>&1
ufw allow 3478/tcp >> "$LOG_FILE" 2>&1
ufw allow 3478/udp >> "$LOG_FILE" 2>&1
log "ufw configured successfully."
else
log "No active firewall detected or firewall is already configured."
fi
}
# Configure firewall
configure_firewall
# Get server IP address
SERVER_IP=$(hostname -I | awk '{print $1}')
log "Detected server IP address: $SERVER_IP"
# Check if Docker is running properly
log "Verifying Docker service status..."
if ! systemctl is-active --quiet docker; then
log "Docker service is not running. Attempting to fix..."
systemctl restart docker >> "$LOG_FILE" 2>&1
sleep 5
if ! systemctl is-active --quiet docker; then
error_exit "Docker service failed to start even after attempted fix."
fi
fi
# Run Nextcloud AIO container
log "Starting Nextcloud AIO container..."
docker run \
--init \
--sig-proxy=false \
--name nextcloud-aio-mastercontainer \
--restart always \
--publish 80:80 \
--publish 8080:8080 \
--publish 8443:8443 \
--volume nextcloud_aio_mastercontainer:/mnt/docker-aio-config \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
ghcr.io/nextcloud-releases/all-in-one:latest >> "$LOG_FILE" 2>&1 &
# Wait a bit for the container to start
log "Waiting for Nextcloud AIO container to start (30 seconds)..."
sleep 30
# Check if container is running
if docker ps | grep nextcloud-aio-mastercontainer > /dev/null; then
log "Nextcloud AIO container started successfully."
else
log "Warning: Nextcloud AIO container not found in running containers."
log "Attempting recovery..."
# Check if the container exists but is not running
if docker ps -a | grep nextcloud-aio-mastercontainer > /dev/null; then
log "Container exists but is not running. Checking logs..."
docker logs --tail 50 nextcloud-aio-mastercontainer >> "$LOG_FILE" 2>&1
# Try to restart the container
log "Attempting to restart the container..."
docker start nextcloud-aio-mastercontainer >> "$LOG_FILE" 2>&1
sleep 10
if docker ps | grep nextcloud-aio-mastercontainer > /dev/null; then
log "Container successfully restarted."
else
log "Failed to restart container. Recreating container..."
docker rm nextcloud-aio-mastercontainer >> "$LOG_FILE" 2>&1
docker run \
--init \
--sig-proxy=false \
--name nextcloud-aio-mastercontainer \
--restart always \
--publish 80:80 \
--publish 8080:8080 \
--publish 8443:8443 \
--volume nextcloud_aio_mastercontainer:/mnt/docker-aio-config \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
ghcr.io/nextcloud-releases/all-in-one:latest >> "$LOG_FILE" 2>&1 &
sleep 30
if ! docker ps | grep nextcloud-aio-mastercontainer > /dev/null; then
error_exit "Failed to start Nextcloud AIO container after multiple attempts."
fi
fi
else
error_exit "Failed to start Nextcloud AIO container and container not found."
fi
fi
# Log important access information
echo -e "\n\n===================== NEXTCLOUD ACCESS INFORMATION =====================" >> "$LOG_FILE"
echo "Nextcloud AIO Interface: https://$SERVER_IP:8080" >> "$LOG_FILE"
echo "Note: Always use IP address for this port, not a domain name!" >> "$LOG_FILE"
echo "Accept the self-signed certificate in your browser." >> "$LOG_FILE"
echo "" >> "$LOG_FILE"
echo "If you have a domain pointing to this server and ports 80/8443 open:" >> "$LOG_FILE"
echo "Alternative Nextcloud AIO Interface: https://your-domain:8443" >> "$LOG_FILE"
echo "" >> "$LOG_FILE"
echo "IMPORTANT: Make sure ports 80, 8080, 8443, 3478/TCP and 3478/UDP are open in your firewall!" >> "$LOG_FILE"
echo "====================================================================" >> "$LOG_FILE"
# Check for common port conflicts
check_port_conflicts() {
log "Checking for common port conflicts..."
# Check if ports 80, 8080, 8443 are already in use by other services
for port in 80 8080 8443; do
if netstat -tuln | grep ":$port " | grep -v "docker" > /dev/null; then
log "Warning: Port $port appears to be in use by another service."
log "This might cause issues with Nextcloud AIO. Consider stopping the conflicting service."
# Show the conflicting process
log "Process using port $port:"
if command -v lsof &> /dev/null; then
lsof -i :$port >> "$LOG_FILE" 2>&1
else
netstat -tulnp | grep ":$port " >> "$LOG_FILE" 2>&1
fi
fi
done
}
# Check for port conflicts
check_port_conflicts
# Print final instructions
log "Installation completed successfully!"
log "Access Nextcloud AIO Interface at: https://$SERVER_IP:8080"
log "See $LOG_FILE for detailed information and access URLs."
log "IMPORTANT: Remember to open port 3478/TCP and 3478/UDP in your firewall for Talk!"
# Display success message to console in a clear format
echo ""
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ NEXTCLOUD AIO INSTALLED ║"
echo "╚════════════════════════════════════════════════════════════════╝"
echo ""
echo "✅ Installation completed successfully!"
echo ""
echo "