-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauto_install.sh
More file actions
executable file
·367 lines (305 loc) · 11.4 KB
/
auto_install.sh
File metadata and controls
executable file
·367 lines (305 loc) · 11.4 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
#!/bin/bash
#
# Server Backup Web Application Auto-Installation Script
# This script downloads and installs the Server Backup Web Application on any Linux distribution
#
# Check if script is running as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Please use sudo."
exit 1
fi
echo "=========================================================="
echo " Server Backup Web Application Auto-Installation"
echo "=========================================================="
echo ""
# Detect Linux distribution
detect_distro() {
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
DISTRO_FAMILY=$ID_LIKE
DISTRO_VERSION=$VERSION_ID
else
echo "Cannot detect Linux distribution."
exit 1
fi
echo "Detected distribution: $DISTRO ($DISTRO_FAMILY)"
}
# Install Node.js and npm based on distribution
install_nodejs() {
echo "Checking for Node.js..."
if command -v node &> /dev/null && command -v npm &> /dev/null; then
NODE_VERSION=$(node -v)
echo "Node.js is already installed: $NODE_VERSION"
return 0
fi
echo "Installing Node.js and npm..."
if [[ "$DISTRO" == "ubuntu" || "$DISTRO" == "debian" || "$DISTRO_FAMILY" == *"debian"* ]]; then
# Ubuntu/Debian
apt-get update
apt-get install -y curl gnupg2 software-properties-common
# Install Node.js 20.x
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
elif [[ "$DISTRO" == "fedora" || "$DISTRO_FAMILY" == *"fedora"* ]]; then
# Fedora
dnf install -y curl
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
dnf install -y nodejs
elif [[ "$DISTRO" == "rhel" || "$DISTRO" == "centos" || "$DISTRO_FAMILY" == *"rhel"* ]]; then
# RHEL/CentOS
if [[ "$DISTRO_VERSION" == "7"* ]]; then
# CentOS 7
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
yum install -y nodejs
else
# CentOS 8+/RHEL 8+
dnf install -y curl
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
dnf install -y nodejs
fi
elif [[ "$DISTRO" == "arch" || "$DISTRO" == "manjaro" || "$DISTRO_FAMILY" == *"arch"* ]]; then
# Arch Linux
pacman -Sy --noconfirm nodejs npm
elif [[ "$DISTRO" == "opensuse" || "$DISTRO" == "sles" ]]; then
# openSUSE/SLES
zypper refresh
zypper install -y nodejs20 npm20
else
echo "Unsupported distribution: $DISTRO"
echo "Please install Node.js 18+ manually and run this script again."
exit 1
fi
# Verify installation
if command -v node &> /dev/null && command -v npm &> /dev/null; then
NODE_VERSION=$(node -v)
NPM_VERSION=$(npm -v)
echo "Node.js installed successfully: $NODE_VERSION"
echo "npm installed successfully: $NPM_VERSION"
else
echo "Failed to install Node.js. Please install manually."
exit 1
fi
}
# Install system dependencies
install_system_deps() {
echo "Installing system dependencies..."
if [[ "$DISTRO" == "ubuntu" || "$DISTRO" == "debian" || "$DISTRO_FAMILY" == *"debian"* ]]; then
apt-get update
apt-get install -y git build-essential python3 sqlite3
elif [[ "$DISTRO" == "fedora" || "$DISTRO_FAMILY" == *"fedora"* ]]; then
dnf install -y git gcc gcc-c++ make python3 sqlite
elif [[ "$DISTRO" == "rhel" || "$DISTRO" == "centos" || "$DISTRO_FAMILY" == *"rhel"* ]]; then
if [[ "$DISTRO_VERSION" == "7"* ]]; then
yum install -y git gcc gcc-c++ make python3 sqlite
else
dnf install -y git gcc gcc-c++ make python3 sqlite
fi
elif [[ "$DISTRO" == "arch" || "$DISTRO" == "manjaro" || "$DISTRO_FAMILY" == *"arch"* ]]; then
pacman -Sy --noconfirm git base-devel python sqlite
elif [[ "$DISTRO" == "opensuse" || "$DISTRO" == "sles" ]]; then
zypper install -y git gcc gcc-c++ make python3 sqlite3
else
echo "Warning: Cannot auto-install system dependencies for $DISTRO"
echo "Please ensure git, build-essential, python3, and sqlite3 are installed."
fi
echo "System dependencies installed."
}
# Check for required tools
check_requirements() {
echo "Checking for required tools..."
# Check for git
if ! command -v git &> /dev/null; then
echo "Git is not installed. Installing..."
install_system_deps
fi
echo "Git is installed."
}
# Download the application
download_application() {
echo "Downloading Server Backup Web Application from repository..."
# Default installation directory (standard location for installed software)
INSTALL_DIR="/opt/server-backup"
# Ask user for installation directory
read -p "Enter installation directory (default: $INSTALL_DIR): " USER_DIR
if [ ! -z "$USER_DIR" ]; then
INSTALL_DIR="$USER_DIR"
fi
# Create directory if it doesn't exist
mkdir -p "$INSTALL_DIR"
# Check if directory is not empty
if [ "$(ls -A $INSTALL_DIR 2>/dev/null)" ]; then
echo "Directory $INSTALL_DIR is not empty."
read -p "Do you want to continue? This may overwrite existing files. (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Installation cancelled."
exit 1
fi
fi
# Clone or update the repository
if [ -d "$INSTALL_DIR/.git" ]; then
echo "Repository already exists. Updating..."
cd "$INSTALL_DIR"
git pull
else
echo "Cloning repository..."
git clone https://github.com/lyarinet/Multi-Server-Backup-Manager.git "$INSTALL_DIR"
if [ $? -ne 0 ]; then
echo "Failed to download application. Please check your internet connection and repository URL."
exit 1
fi
fi
cd "$INSTALL_DIR"
echo "Download complete. Installation directory: $INSTALL_DIR"
export INSTALL_DIR
}
# Install Node.js dependencies
install_dependencies() {
echo "Installing Node.js dependencies..."
cd "$INSTALL_DIR"
# Install dependencies
npm install
if [ $? -ne 0 ]; then
echo "Failed to install dependencies. Please check the error messages above."
exit 1
fi
echo "Dependencies installed successfully."
}
# Set up database
setup_database() {
echo "Setting up database..."
cd "$INSTALL_DIR"
# Generate database migrations
npm run db:generate
# Run database migrations
npm run db:migrate
if [ $? -ne 0 ]; then
echo "Warning: Database setup may have encountered issues."
else
echo "Database setup complete."
fi
}
# Build the application
build_application() {
echo "Building the application..."
cd "$INSTALL_DIR"
# Build for production
npm run build
if [ $? -ne 0 ]; then
echo "Warning: Build may have encountered issues. You can build manually later with 'npm run build'."
else
echo "Build complete."
fi
}
# Create systemd service (automatic)
create_systemd_service() {
echo ""
echo "Setting up systemd service for autostart..."
cd "$INSTALL_DIR"
if [ -f "manage-autostart.sh" ]; then
chmod +x manage-autostart.sh
# Install systemd service
echo "Installing systemd service..."
./manage-autostart.sh install
if [ $? -eq 0 ]; then
# Enable autostart on boot
echo "Enabling autostart on boot..."
./manage-autostart.sh enable
if [ $? -eq 0 ]; then
echo "✅ Systemd service installed and enabled successfully!"
echo " Service will start automatically on system boot."
else
echo "⚠️ Service installed but failed to enable. You can enable it manually:"
echo " sudo systemctl enable backup-system"
fi
else
echo "⚠️ Failed to install systemd service. You can install it manually:"
echo " cd $INSTALL_DIR"
echo " sudo ./manage-autostart.sh install"
echo " sudo ./manage-autostart.sh enable"
fi
else
echo "⚠️ Autostart script not found. Skipping systemd setup."
fi
}
# Set permissions
set_permissions() {
echo "Setting permissions..."
cd "$INSTALL_DIR"
# Make scripts executable
find . -name "*.sh" -type f -exec chmod +x {} \;
# Set ownership to current user (or www-data if exists)
if id "www-data" &>/dev/null; then
chown -R www-data:www-data "$INSTALL_DIR"
echo "Permissions set to www-data:www-data"
else
# Get the user who ran sudo
SUDO_USER=${SUDO_USER:-$USER}
if [ "$SUDO_USER" != "root" ]; then
chown -R "$SUDO_USER:$SUDO_USER" "$INSTALL_DIR"
echo "Permissions set to $SUDO_USER:$SUDO_USER"
else
echo "Permissions set (running as root)"
fi
fi
echo "Permissions set."
}
# Main function
main() {
detect_distro
check_requirements
install_nodejs
install_system_deps
download_application
install_dependencies
setup_database
build_application
set_permissions
create_systemd_service
echo ""
echo "=========================================================="
echo " Server Backup Web Application Installation Complete!"
echo "=========================================================="
echo ""
echo "Installation directory: $INSTALL_DIR"
echo ""
echo "Next steps:"
echo "1. Navigate to the installation directory:"
echo " cd $INSTALL_DIR"
echo ""
echo "2. Start the development server:"
echo " npm run dev"
echo " - Frontend will be available at: http://$(hostname -I | awk '{print $1}'):5173"
echo " - Backend API will be available at: http://$(hostname -I | awk '{print $1}'):3010"
echo ""
echo "3. Or start the production server:"
echo " npm start"
echo " - Application will be available at: http://$(hostname -I | awk '{print $1}'):3000"
echo ""
echo "4. Access the application:"
echo " Development: http://$(hostname -I | awk '{print $1}'):5173"
echo " Production: http://$(hostname -I | awk '{print $1}'):3000"
echo ""
echo "5. Default credentials:"
echo " Username: admin"
echo " Password: admin123"
echo " ⚠️ IMPORTANT: Change the default password after first login!"
echo ""
echo "6. Systemd service:"
echo " ✅ Service installed and enabled automatically"
echo " The application will start automatically on system boot"
echo " To manage the service:"
echo " - Start: sudo systemctl start backup-system"
echo " - Stop: sudo systemctl stop backup-system"
echo " - Status: sudo systemctl status backup-system"
echo " - Restart: sudo systemctl restart backup-system"
echo ""
echo "Note: Application is installed in $INSTALL_DIR"
echo " This is the standard location for installed software (/opt/)"
echo ""
echo "For more information, see README.md"
echo "=========================================================="
}
# Run the main function
main