-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
254 lines (222 loc) · 8.21 KB
/
install.sh
File metadata and controls
254 lines (222 loc) · 8.21 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
#!/bin/bash
set -e
#######################################
# CS-ClusterMTA One-Line Installer
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/bauer-group/CS-ClusterMTA/main/install.sh | sudo bash
#
#######################################
REPO_URL="https://github.com/bauer-group/CS-ClusterMTA.git"
INSTALL_DIR="/opt/clustermta"
BRANCH="main"
#######################################
# Colors and Output
#######################################
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
print_banner() {
echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ ██████╗██╗ ██╗ ██╗███████╗████████╗███████╗██████╗ ║"
echo "║ ██╔════╝██║ ██║ ██║██╔════╝╚══██╔══╝██╔════╝██╔══██╗ ║"
echo "║ ██║ ██║ ██║ ██║███████╗ ██║ █████╗ ██████╔╝ ║"
echo "║ ██║ ██║ ██║ ██║╚════██║ ██║ ██╔══╝ ██╔══██╗ ║"
echo "║ ╚██████╗███████╗╚██████╔╝███████║ ██║ ███████╗██║ ██║ ║"
echo "║ ╚═════╝╚══════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ║"
echo "║ MTA ║"
echo "║ ║"
echo "║ Self-Hosted Installer ║"
echo "║ ║"
echo "╚═══════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
}
print_success() { echo -e "${GREEN}✓${NC} $1"; }
print_warning() { echo -e "${YELLOW}!${NC} $1"; }
print_error() { echo -e "${RED}✗${NC} $1"; }
print_info() { echo -e "${BLUE}→${NC} $1"; }
#######################################
# Root Check
#######################################
check_root() {
if [ "$EUID" -ne 0 ]; then
print_error "This script must be run as root!"
echo "Please run with: curl -fsSL ... | sudo bash"
exit 1
fi
}
#######################################
# Parse Arguments
#######################################
AUTO_START=false
INTERACTIVE=true
while [[ $# -gt 0 ]]; do
case $1 in
--start|-s)
AUTO_START=true
shift
;;
--yes|-y)
INTERACTIVE=false
shift
;;
--help|-h)
echo "CS-ClusterMTA Installer"
echo ""
echo "Usage:"
echo " curl -fsSL <url>/install.sh | sudo bash [options]"
echo ""
echo "Options:"
echo " --start, -s Start the stack after installation"
echo " --yes, -y Non-interactive mode (no prompts)"
echo " --help, -h Show this help message"
echo ""
echo "Examples:"
echo " # Interactive installation"
echo " curl -fsSL <url>/install.sh | sudo bash"
echo ""
echo " # Install and start automatically"
echo " curl -fsSL <url>/install.sh | sudo bash -s -- --start"
exit 0
;;
*)
print_error "Unknown option: $1"
exit 1
;;
esac
done
#######################################
# Check Requirements
#######################################
check_requirements() {
print_info "Checking requirements..."
# Check OS
if [ -f /etc/os-release ]; then
. /etc/os-release
if [ "$ID" != "ubuntu" ] && [ "$ID" != "debian" ]; then
print_warning "This script is designed for Ubuntu/Debian. Other distros may work but are untested."
fi
fi
# Check for git
if ! command -v git &> /dev/null; then
print_info "Installing git..."
apt-get update -qq
apt-get install -y -qq git
fi
# Check for curl
if ! command -v curl &> /dev/null; then
print_info "Installing curl..."
apt-get update -qq
apt-get install -y -qq curl
fi
print_success "Requirements satisfied"
}
#######################################
# Check Docker
#######################################
check_docker() {
if command -v docker &> /dev/null; then
DOCKER_VERSION=$(docker --version 2>/dev/null | grep -oP '\d+\.\d+' | head -1)
print_success "Docker $DOCKER_VERSION found"
return 0
else
print_error "Docker is not installed!"
echo ""
echo "Please install Docker first:"
echo " https://docs.docker.com/engine/install/"
echo ""
return 1
fi
}
#######################################
# Clone Repository
#######################################
clone_repository() {
print_info "Downloading CS-ClusterMTA..."
if [ -d "$INSTALL_DIR/.git" ]; then
print_info "Existing installation found, updating..."
cd "$INSTALL_DIR"
git fetch origin
git reset --hard origin/$BRANCH
else
if [ -d "$INSTALL_DIR" ]; then
print_warning "Removing existing $INSTALL_DIR (not a git repo)"
rm -rf "$INSTALL_DIR"
fi
git clone --depth 1 --branch $BRANCH "$REPO_URL" "$INSTALL_DIR"
fi
cd "$INSTALL_DIR"
git config core.fileMode false
chmod +x *.sh 2>/dev/null || true
print_success "Repository cloned to $INSTALL_DIR"
}
#######################################
# Run Setup
#######################################
run_setup() {
print_info "Running setup..."
cd "$INSTALL_DIR"
./setup.sh
print_success "Setup complete"
}
#######################################
# Start Stack
#######################################
start_stack() {
print_info "Starting CS-ClusterMTA..."
cd "$INSTALL_DIR"
./clustermta.sh start
print_success "Stack started"
}
#######################################
# Print Summary
#######################################
print_summary() {
local IP
IP=$(hostname -I 2>/dev/null | awk '{print $1}')
IP=${IP:-localhost}
echo ""
echo -e "${GREEN}╔═══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ Installation Complete! ║${NC}"
echo -e "${GREEN}╚═══════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo " Installation: $INSTALL_DIR"
echo ""
echo " Next steps:"
echo " 1. Edit configuration:"
echo -e " ${BLUE}nano $INSTALL_DIR/.env${NC}"
echo ""
echo " 2. Start the mail server:"
echo -e " ${BLUE}cd $INSTALL_DIR && sudo ./clustermta.sh start${NC}"
echo ""
echo " 3. Access admin panel:"
echo -e " ${BLUE}https://<your-hostname>/admin/${NC}"
echo ""
echo " Management commands:"
echo " cd $INSTALL_DIR"
echo " ./clustermta.sh status|logs|stop|restart|backup"
echo ""
}
#######################################
# Main
#######################################
main() {
print_banner
check_root
check_requirements
if ! check_docker; then
exit 1
fi
echo ""
clone_repository
run_setup
if [ "$AUTO_START" = true ]; then
start_stack
fi
print_summary
}
main "$@"