-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
398 lines (336 loc) · 10.6 KB
/
Copy pathinstall.sh
File metadata and controls
398 lines (336 loc) · 10.6 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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#!/bin/bash
# 🚀 Automated Installation Script for n8n OpenCart Node
# Автоматизований скрипт встановлення n8n OpenCart Node
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
N8N_USER="n8n"
N8N_HOME="/home/$N8N_USER"
N8N_DATA_DIR="$N8N_HOME/.n8n"
SERVICE_FILE="/etc/systemd/system/n8n.service"
NGINX_SITE="/etc/nginx/sites-available/n8n"
# Functions
print_header() {
echo -e "${BLUE}================================${NC}"
echo -e "${BLUE} $1${NC}"
echo -e "${BLUE}================================${NC}"
}
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
check_root() {
if [[ $EUID -ne 0 ]]; then
print_error "Цей скрипт повинен виконуватися з правами root"
echo "Використовуйте: sudo $0"
exit 1
fi
}
detect_os() {
if [[ -f /etc/os-release ]]; then
. /etc/os-release
OS=$ID
VERSION=$VERSION_ID
else
print_error "Неможливо визначити операційну систему"
exit 1
fi
print_info "Виявлена ОС: $OS $VERSION"
}
install_nodejs() {
print_header "Встановлення Node.js"
case $OS in
ubuntu|debian)
apt update
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs
;;
centos|rhel)
curl -fsSL https://rpm.nodesource.com/setup_lts.x | bash -
yum install -y nodejs
;;
*)
print_error "Непідтримувана операційна система: $OS"
exit 1
;;
esac
print_info "Node.js версія: $(node --version)"
print_info "npm версія: $(npm --version)"
}
install_n8n_and_node() {
print_header "Встановлення n8n та OpenCart node"
# Install n8n globally
npm install -g n8n
print_info "n8n встановлено"
# Check if we're installing from local directory or npm
if [[ -f "package.json" ]]; then
print_info "Встановлення OpenCart node з локальної директорії"
npm run build
npm pack
PACKAGE_FILE=$(ls *.tgz | head -n1)
npm install -g "$PACKAGE_FILE"
rm "$PACKAGE_FILE"
else
print_info "Встановлення OpenCart node з npm registry"
npm install -g n8n-nodes-opencart
fi
print_info "OpenCart node встановлено"
}
create_user() {
print_header "Створення користувача n8n"
if ! id "$N8N_USER" &>/dev/null; then
useradd -r -s /bin/false -d "$N8N_HOME" "$N8N_USER"
print_info "Користувач $N8N_USER створено"
else
print_info "Користувач $N8N_USER вже існує"
fi
# Create directories
mkdir -p "$N8N_DATA_DIR"
chown -R "$N8N_USER:$N8N_USER" "$N8N_HOME"
print_info "Директорії створено"
}
create_systemd_service() {
print_header "Створення systemd сервісу"
cat > "$SERVICE_FILE" << EOF
[Unit]
Description=n8n automation tool with OpenCart integration
After=network.target
[Service]
Type=simple
User=$N8N_USER
Group=$N8N_USER
ExecStart=/usr/bin/n8n start
Environment=N8N_CUSTOM_EXTENSIONS=/usr/lib/node_modules/n8n-nodes-opencart
Environment=N8N_HOST=0.0.0.0
Environment=N8N_PORT=5678
Environment=N8N_PROTOCOL=http
Environment=NODE_ENV=production
WorkingDirectory=$N8N_DATA_DIR
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable n8n
print_info "Systemd сервіс створено"
}
configure_firewall() {
print_header "Налаштування брандмауера"
case $OS in
ubuntu|debian)
if command -v ufw &> /dev/null; then
ufw allow 5678/tcp
print_info "UFW правило додано для порту 5678"
fi
;;
centos|rhel)
if command -v firewall-cmd &> /dev/null; then
firewall-cmd --permanent --add-port=5678/tcp
firewall-cmd --reload
print_info "Firewalld правило додано для порту 5678"
fi
;;
esac
}
install_nginx() {
print_header "Встановлення та налаштування Nginx"
case $OS in
ubuntu|debian)
apt install -y nginx
;;
centos|rhel)
yum install -y nginx
;;
esac
# Create nginx configuration
cat > "$NGINX_SITE" << 'EOF'
server {
listen 80;
server_name _;
location / {
proxy_pass http://localhost:5678;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
# Security headers
proxy_set_header X-Frame-Options DENY;
proxy_set_header X-Content-Type-Options nosniff;
proxy_set_header X-XSS-Protection "1; mode=block";
}
}
EOF
# Enable site
if [[ -d "/etc/nginx/sites-enabled" ]]; then
ln -sf "$NGINX_SITE" /etc/nginx/sites-enabled/
# Remove default site
rm -f /etc/nginx/sites-enabled/default
fi
# Test nginx configuration
nginx -t
systemctl enable nginx
systemctl restart nginx
print_info "Nginx налаштовано"
}
start_services() {
print_header "Запуск сервісів"
systemctl start n8n
systemctl start nginx
print_info "Сервіси запущено"
}
create_env_file() {
print_header "Створення файлу конфігурації"
ENV_FILE="$N8N_DATA_DIR/.env"
cat > "$ENV_FILE" << EOF
# n8n Configuration with OpenCart Node
N8N_HOST=0.0.0.0
N8N_PORT=5678
N8N_PROTOCOL=http
N8N_CUSTOM_EXTENSIONS=/usr/lib/node_modules/n8n-nodes-opencart
# Security (змініть на свої значення!)
N8N_BASIC_AUTH_ACTIVE=true
N8N_BASIC_AUTH_USER=admin
N8N_BASIC_AUTH_PASSWORD=changeme
# Database (для production рекомендується PostgreSQL)
# DB_TYPE=postgresdb
# DB_POSTGRESDB_HOST=localhost
# DB_POSTGRESDB_PORT=5432
# DB_POSTGRESDB_DATABASE=n8n
# DB_POSTGRESDB_USER=n8n_user
# DB_POSTGRESDB_PASSWORD=secure_password
# Encryption (ОБОВ'ЯЗКОВО змініть!)
N8N_ENCRYPTION_KEY=your_32_character_encryption_key
# Webhooks
WEBHOOK_URL=http://your-domain.com/
# Logging
N8N_LOG_LEVEL=info
N8N_LOG_OUTPUT=file
N8N_LOG_FILE=/var/log/n8n/n8n.log
EOF
chown "$N8N_USER:$N8N_USER" "$ENV_FILE"
print_info "Конфігураційний файл створено: $ENV_FILE"
}
setup_logging() {
print_header "Налаштування логування"
LOG_DIR="/var/log/n8n"
mkdir -p "$LOG_DIR"
chown "$N8N_USER:$N8N_USER" "$LOG_DIR"
# Logrotate configuration
cat > /etc/logrotate.d/n8n << EOF
$LOG_DIR/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
copytruncate
su $N8N_USER $N8N_USER
}
EOF
print_info "Логування налаштовано"
}
print_completion() {
print_header "Встановлення завершено!"
echo -e "${GREEN}"
echo "✅ n8n з OpenCart node успішно встановлено!"
echo ""
echo "🌐 Доступ до n8n:"
echo " http://your-server-ip:5678"
echo " або"
echo " http://your-domain.com"
echo ""
echo "🔐 Базова автентифікація:"
echo " Користувач: admin"
echo " Пароль: changeme"
echo ""
echo "⚙️ Конфігурація:"
echo " Файл: $N8N_DATA_DIR/.env"
echo " Логи: /var/log/n8n/"
echo ""
echo "🔧 Команди управління:"
echo " sudo systemctl status n8n # Статус"
echo " sudo systemctl restart n8n # Перезапуск"
echo " sudo systemctl stop n8n # Зупинка"
echo " sudo systemctl start n8n # Запуск"
echo " sudo journalctl -u n8n -f # Перегляд логів"
echo ""
echo -e "${RED}⚠️ ВАЖЛИВО: Змініть паролі та ключі шифрування в файлі .env!${NC}"
echo -e "${GREEN}"
}
# Main execution
main() {
print_header "n8n OpenCart Node Installation"
check_root
detect_os
# Ask for confirmation
echo -e "${YELLOW}Цей скрипт встановить:${NC}"
echo " • Node.js LTS"
echo " • n8n automation tool"
echo " • OpenCart integration node"
echo " • Nginx reverse proxy"
echo " • Systemd service"
echo ""
read -p "Продовжити встановлення? [y/N]: " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "Встановлення скасовано"
exit 0
fi
# Installation steps
install_nodejs
install_n8n_and_node
create_user
create_env_file
setup_logging
create_systemd_service
configure_firewall
# Ask for nginx
read -p "Встановити Nginx reverse proxy? [y/N]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
install_nginx
fi
start_services
print_completion
}
# Check for help argument
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
echo "n8n OpenCart Node Installation Script"
echo ""
echo "Використання:"
echo " sudo $0 # Інтерактивне встановлення"
echo " sudo $0 --auto # Автоматичне встановлення (без запитань)"
echo " sudo $0 --help # Показати цю довідку"
echo ""
echo "Цей скрипт встановлює:"
echo " • Node.js LTS"
echo " • n8n automation platform"
echo " • OpenCart integration node"
echo " • Systemd service для автозапуску"
echo " • Nginx reverse proxy (опціонально)"
echo ""
exit 0
fi
# Auto installation mode
if [[ "$1" == "--auto" ]]; then
export AUTO_MODE=true
main
else
main
fi