-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·327 lines (274 loc) · 9.31 KB
/
bootstrap.sh
File metadata and controls
executable file
·327 lines (274 loc) · 9.31 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
#!/bin/bash
#
# phpBorg Bootstrap Installer
# One-line installer for phpBorg v1.0
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/altzone/phpBorg/master/bootstrap.sh | sudo bash
#
# Or with custom branch:
# REPO_BRANCH=develop curl -fsSL https://raw.githubusercontent.com/altzone/phpBorg/master/bootstrap.sh | sudo bash
#
# Or download and run:
# wget https://raw.githubusercontent.com/altzone/phpBorg/master/bootstrap.sh
# sudo bash bootstrap.sh
#
# Don't exit on error - we handle errors explicitly with error_exit
set +e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Configuration
INSTALL_DIR="${INSTALL_DIR:-/opt/newphpborg}"
REPO_URL="${REPO_URL:-https://github.com/altzone/phpBorg.git}"
REPO_BRANCH="${REPO_BRANCH:-master}"
#
# Print banner
#
print_banner() {
clear
echo -e "${BLUE}"
cat << "EOF"
____ __ ______ ____
/ __ \/ / / / __ \/ __ )____ _________ _
/ /_/ / /_/ / /_/ / __ / __ \/ ___/ __ `/
/ ____/ __ / ____/ /_/ / /_/ / / / /_/ /
/_/ /_/ /_/_/ /_____/\____/_/ \__, /
/____/
EOF
echo -e "${NC}"
echo -e "${CYAN}Bootstrap Installer v1.0${NC}"
echo -e "${CYAN}Enterprise Backup System${NC}"
echo ""
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
echo ""
}
#
# Logging
#
log_info() {
echo -e "${CYAN}ℹ${NC} $@"
}
log_success() {
echo -e "${GREEN}✓${NC} $@"
}
log_warn() {
echo -e "${YELLOW}⚠${NC} $@"
}
log_error() {
echo -e "${RED}✗${NC} $@"
}
error_exit() {
log_error "$@"
echo ""
echo -e "${RED}Bootstrap failed!${NC}"
exit 1
}
#
# Pre-checks
#
check_root() {
if [ "$EUID" -ne 0 ]; then
error_exit "This script must be run as root. Use: sudo bash bootstrap.sh"
fi
log_success "Running as root"
}
check_os() {
if [ ! -f /etc/os-release ]; then
error_exit "Unable to detect OS (no /etc/os-release)"
fi
. /etc/os-release
log_success "Detected OS: ${ID} ${VERSION_ID}"
# Check if supported
case "${ID}" in
ubuntu|debian|centos|rhel|fedora|rocky|almalinux|arch|manjaro|alpine)
log_success "OS is supported"
;;
*)
log_warn "OS '${ID}' is not officially tested but may work"
;;
esac
}
check_internet() {
log_info "Checking internet connectivity..."
if ping -c 1 8.8.8.8 &> /dev/null; then
log_success "Internet connection OK"
else
error_exit "No internet connection"
fi
}
#
# Install prerequisites
#
install_prerequisites() {
echo ""
echo -e "${CYAN}▸ Installing Prerequisites${NC}"
echo ""
# Detect package manager
if command -v apt-get &> /dev/null; then
log_info "Using apt package manager"
apt-get update -qq
apt-get install -y -qq git curl wget > /dev/null 2>&1
elif command -v dnf &> /dev/null; then
log_info "Using dnf package manager"
dnf install -y -q git curl wget > /dev/null 2>&1
elif command -v yum &> /dev/null; then
log_info "Using yum package manager"
yum install -y -q git curl wget > /dev/null 2>&1
elif command -v pacman &> /dev/null; then
log_info "Using pacman package manager"
pacman -Sy --noconfirm --needed git curl wget > /dev/null 2>&1
elif command -v apk &> /dev/null; then
log_info "Using apk package manager"
apk add --no-cache git curl wget > /dev/null 2>&1
else
error_exit "No supported package manager found (apt, dnf, yum, pacman, apk)"
fi
log_success "Prerequisites installed (git, curl, wget)"
}
#
# Clone repository
#
clone_repository() {
echo ""
echo -e "${CYAN}▸ Cloning phpBorg Repository${NC}"
echo ""
# Create install directory
if [ ! -d "${INSTALL_DIR}" ]; then
log_info "Creating directory: ${INSTALL_DIR}"
mkdir -p "${INSTALL_DIR}"
fi
cd "${INSTALL_DIR}" || error_exit "Failed to change to ${INSTALL_DIR}"
# Check if already cloned
if [ -d "phpBorg/.git" ]; then
log_warn "phpBorg already exists, updating..."
cd phpBorg || error_exit "Failed to change to phpBorg directory"
# Check for local modifications
if ! git diff-index --quiet HEAD -- 2>/dev/null; then
log_warn "Local modifications detected, stashing changes..."
git stash save "Bootstrap auto-stash $(date +%Y%m%d_%H%M%S)" > /dev/null 2>&1
fi
# Fetch latest changes
git fetch origin > /dev/null 2>&1 || log_warn "Failed to fetch updates"
# Try to checkout the branch
if git checkout "${REPO_BRANCH}" > /dev/null 2>&1; then
git pull origin "${REPO_BRANCH}" > /dev/null 2>&1 || log_warn "Failed to pull updates"
log_success "Repository updated to ${REPO_BRANCH}"
else
# Branch doesn't exist, try default branch
log_warn "Branch '${REPO_BRANCH}' not found, using current branch"
git pull > /dev/null 2>&1 || log_warn "Failed to pull updates"
log_success "Repository updated"
fi
else
# Clone repository
log_info "Cloning from: ${REPO_URL}"
log_info "Branch: ${REPO_BRANCH}"
if git clone -q -b "${REPO_BRANCH}" "${REPO_URL}" phpBorg; then
log_success "Repository cloned"
cd phpBorg
else
# Try without branch (might be main/master)
log_warn "Branch '${REPO_BRANCH}' not found, trying default branch..."
if git clone -q "${REPO_URL}" phpBorg; then
log_success "Repository cloned (default branch)"
cd phpBorg
else
error_exit "Failed to clone repository"
fi
fi
fi
# Verify installer exists
if [ ! -f "install.sh" ]; then
error_exit "install.sh not found in repository"
fi
log_success "Repository ready: ${INSTALL_DIR}/phpBorg"
}
#
# Set permissions
#
set_permissions() {
log_info "Setting permissions..."
chmod +x install.sh
log_success "Permissions set"
}
#
# Display info
#
display_info() {
echo ""
echo -e "${GREEN}═══════════════════════════════════════════════════════════${NC}"
echo -e "${GREEN}Bootstrap Complete!${NC}"
echo -e "${GREEN}═══════════════════════════════════════════════════════════${NC}"
echo ""
echo -e "${CYAN}Installation directory:${NC} ${INSTALL_DIR}/phpBorg"
echo -e "${CYAN}Repository:${NC} ${REPO_URL}"
echo -e "${CYAN}Branch:${NC} ${REPO_BRANCH}"
echo ""
echo -e "${CYAN}Next step:${NC} The main installer will now start..."
echo ""
echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
echo ""
}
#
# Run main installer
#
run_installer() {
log_info "Starting main installer..."
echo ""
# Verify we're in the right directory
if [ ! -f "install.sh" ]; then
error_exit "install.sh not found. Current directory: $(pwd)"
fi
sleep 1
# Run the main installer
bash install.sh
local exit_code=$?
if [ ${exit_code} -eq 0 ]; then
echo ""
echo -e "${GREEN}═══════════════════════════════════════════════════════════${NC}"
echo -e "${GREEN}🎉 phpBorg Installation Complete!${NC}"
echo -e "${GREEN}═══════════════════════════════════════════════════════════${NC}"
echo ""
else
echo ""
echo -e "${RED}═══════════════════════════════════════════════════════════${NC}"
echo -e "${RED}Installation encountered errors (exit code: ${exit_code})${NC}"
echo -e "${RED}═══════════════════════════════════════════════════════════${NC}"
echo ""
echo -e "${YELLOW}Troubleshooting:${NC}"
echo " • Check logs: /var/log/phpborg-install.log"
echo " • Re-run: cd ${INSTALL_DIR}/phpBorg && sudo bash install.sh"
echo " • Support: https://github.com/altzone/phpBorg/issues"
echo ""
fi
exit ${exit_code}
}
#
# Main
#
main() {
# Display banner
print_banner
# Pre-checks
log_info "Running pre-installation checks..."
check_root
check_os
check_internet
# Install prerequisites
install_prerequisites
# Clone repository
clone_repository
# Set permissions
set_permissions
# Display info
display_info
# Run main installer
run_installer
}
# Run main function
main "$@"