-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·492 lines (421 loc) · 13.5 KB
/
install.sh
File metadata and controls
executable file
·492 lines (421 loc) · 13.5 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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
#!/bin/bash
# Installation script for the boilerplate-laravel project.
#
# This script provides installation options for Standalone, Docker, or Kubernetes deployments.
# It handles composer and npm installations with fallback logic and error checking.
set -e # Exit on error
# Colors for output
RED='\e[91m'
GREEN='\e[92m'
YELLOW='\e[93m'
BLUE='\e[94m'
RESET='\e[39m'
# Function to print colored messages
print_message() {
local color=$1
local message=$2
echo -e "${color}${message}${RESET}"
}
print_header() {
echo ""
echo "=================================="
echo "$1"
echo "=================================="
echo ""
}
print_error() {
print_message "$RED" "❌ ERROR: $1"
}
print_success() {
print_message "$GREEN" "✅ $1"
}
print_info() {
print_message "$BLUE" "ℹ️ $1"
}
print_warning() {
print_message "$YELLOW" "⚠️ $1"
}
# Check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Download composer.phar if composer is not available
ensure_composer() {
if command_exists composer; then
print_success "Composer is already installed"
COMPOSER_CMD="composer"
return 0
fi
print_warning "Composer command not found. Attempting to download composer.phar..."
if ! command_exists curl; then
print_error "curl is required to download composer. Please install curl or composer manually."
return 1
fi
if ! command_exists php; then
print_error "PHP is required. Please install PHP first."
return 1
fi
# Download composer installer
print_info "Downloading Composer installer..."
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
# Verify installer (optional but recommended)
print_info "Installing Composer locally..."
php composer-setup.php --quiet
# Clean up installer
php -r "unlink('composer-setup.php');"
if [ -f "composer.phar" ]; then
print_success "Composer.phar downloaded successfully"
COMPOSER_CMD="php composer.phar"
return 0
else
print_error "Failed to download composer.phar"
return 1
fi
}
# Install composer dependencies
install_composer_dependencies() {
print_header "🎬 COMPOSER INSTALL"
# Check if vendor directory exists
if [ -d "vendor" ] && [ -f "vendor/autoload.php" ]; then
print_info "Vendor directory already exists. Skipping composer install."
read -p "Do you want to reinstall composer dependencies? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_success "Skipping composer install"
return 0
fi
fi
# Ensure composer is available
if ! ensure_composer; then
print_error "Cannot proceed without Composer"
return 1
fi
# Run composer install
print_info "Running: $COMPOSER_CMD install"
if eval "$COMPOSER_CMD install --no-interaction --prefer-dist"; then
print_success "Composer dependencies installed successfully"
return 0
else
print_error "Composer install failed"
return 1
fi
}
# Install npm dependencies
install_npm_dependencies() {
print_header "🎬 NPM INSTALL"
# Check if node_modules directory exists
if [ -d "node_modules" ]; then
print_info "node_modules directory already exists. Skipping npm install."
read -p "Do you want to reinstall npm dependencies? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_success "Skipping npm install"
return 0
fi
fi
# Check if npm is available
if ! command_exists npm; then
print_error "npm is not installed. Please install Node.js and npm first."
print_info "Visit: https://nodejs.org/"
return 1
fi
# Run npm install
print_info "Running: npm install"
if npm install; then
print_success "NPM dependencies installed successfully"
return 0
else
print_error "NPM install failed"
return 1
fi
}
# Build frontend assets
build_frontend_assets() {
print_header "🎬 NPM BUILD"
# Check if npm is available
if ! command_exists npm; then
print_error "npm is not installed. Cannot build assets."
return 1
fi
# Run npm build
print_info "Running: npm run build"
if npm run build; then
print_success "Frontend assets built successfully"
return 0
else
print_error "NPM build failed"
return 1
fi
}
# Standalone installation
install_standalone() {
print_header "STANDALONE INSTALLATION"
print_info "Starting standalone installation process..."
clear
echo "=================================="
echo "===== USER: [$(whoami)]"
echo "===== [PHP $(php -r 'echo phpversion();')]"
echo "=================================="
echo ""
# Setup the .env file
copy=true
while true; do
read -p "🎬 DEV ---> DID YOU WANT TO COPY THE .ENV.EXAMPLE TO .ENV? (y/n) " yn
case $yn in
[Yy]* )
print_success "Copying .env.example to .env"
cp .env.example .env
copy=true
break
;;
[Nn]* )
print_success "Continuing with your .env configuration"
copy=false
break
;;
* )
print_warning "Please answer yes or no."
;;
esac
done
echo ""
echo "=================================="
echo ""
# Ask user to confirm that .env file is properly setup before continuing
if [ "$copy" = true ]; then
while true; do
read -p "🎬 DEV ---> DID YOU SETUP YOUR DATABASE CREDENTIALS IN THE .ENV FILE? (y/n) " cond
case $cond in
[Yy]* )
print_success "Perfect let's continue with the setup"
break
;;
[Nn]* )
print_warning "Please setup your .env file and run this script again"
exit 0
;;
* )
print_warning "Please answer yes or no."
;;
esac
done
fi
echo ""
echo "=================================="
echo ""
# Install composer dependencies
if ! install_composer_dependencies; then
print_error "Installation failed at composer install step"
exit 1
fi
echo ""
echo "=================================="
echo ""
# Install npm dependencies
if ! install_npm_dependencies; then
print_warning "NPM install failed, but continuing..."
fi
echo ""
echo "=================================="
echo ""
# Build frontend assets
if ! build_frontend_assets; then
print_warning "NPM build failed, but continuing..."
fi
echo ""
echo "=================================="
echo ""
# Generate Laravel key
print_header "🎬 PHP ARTISAN KEY:GENERATE"
if php artisan key:generate; then
print_success "Application key generated"
else
print_error "Failed to generate application key"
exit 1
fi
echo ""
echo "=================================="
echo ""
# Run database migrations
print_header "🎬 PHP ARTISAN MIGRATE:FRESH"
if php artisan migrate:fresh; then
print_success "Database migrated successfully"
else
print_error "Database migration failed"
exit 1
fi
echo ""
echo "=================================="
echo ""
# Seeding database
print_header "🎬 PHP ARTISAN DB:SEED"
if php artisan db:seed; then
print_success "Database seeded successfully"
else
print_error "Database seeding failed"
exit 1
fi
echo ""
echo "=================================="
echo ""
# Run PHPUnit tests
print_header "🎬 RUNNING PHPUNIT TESTS"
if [ -f "vendor/bin/phpunit" ]; then
if ./vendor/bin/phpunit; then
print_success "PHPUnit tests passed"
else
print_warning "PHPUnit tests failed. Please review the errors."
fi
else
print_warning "PHPUnit not found. Skipping tests."
fi
echo ""
echo "=================================="
echo ""
# Run optimization commands for Laravel
print_header "🎬 PHP ARTISAN OPTIMIZE:CLEAR"
php artisan optimize:clear
php artisan route:clear
echo ""
print_success "=================================="
print_success "============== DONE =============="
print_success "=================================="
echo ""
# Ask if user wants to start the server
while true; do
read -p "🎬 DEV ---> DID YOU WANT TO START THE SERVER? (y/n) " cond
case $cond in
[Yy]* )
print_success "Starting server..."
php artisan serve
break
;;
[Nn]* )
print_success "Installation complete. You can start the server later with: php artisan serve"
exit 0
;;
* )
print_warning "Please answer yes or no."
;;
esac
done
}
# Docker installation
install_docker() {
print_header "DOCKER INSTALLATION"
print_info "Starting Docker installation process..."
# Check if Docker is installed
if ! command_exists docker; then
print_error "Docker is not installed. Please install Docker first."
print_info "Visit: https://docs.docker.com/get-docker/"
exit 1
fi
print_success "Docker is installed"
# Check for docker-compose
if ! command_exists docker-compose && ! docker compose version >/dev/null 2>&1; then
print_error "Docker Compose is not installed. Please install Docker Compose first."
print_info "Visit: https://docs.docker.com/compose/install/"
exit 1
fi
print_success "Docker Compose is available"
# Setup .env file
if [ ! -f ".env" ]; then
print_info "Copying .env.example to .env"
cp .env.example .env
print_warning "Please edit .env file to configure your Docker environment"
read -p "Press Enter to continue after editing .env..."
fi
# Build and start containers
print_info "Building and starting Docker containers..."
if command_exists docker-compose; then
docker-compose up -d --build
else
docker compose up -d --build
fi
if [ $? -eq 0 ]; then
print_success "Docker containers started successfully"
print_info "Your application should be available at http://localhost"
else
print_error "Failed to start Docker containers"
exit 1
fi
}
# Kubernetes installation
install_kubernetes() {
print_header "KUBERNETES INSTALLATION"
print_info "Starting Kubernetes installation process..."
# Check if kubectl is installed
if ! command_exists kubectl; then
print_error "kubectl is not installed. Please install kubectl first."
print_info "Visit: https://kubernetes.io/docs/tasks/tools/"
exit 1
fi
print_success "kubectl is installed"
# Check for k8s config files
if [ ! -d "k8s" ] && [ ! -d "kubernetes" ]; then
print_error "No Kubernetes configuration directory found (k8s/ or kubernetes/)"
print_warning "Kubernetes installation requires configuration files."
print_info "Please create Kubernetes manifests in a k8s/ or kubernetes/ directory"
exit 1
fi
# Determine config directory
K8S_DIR="k8s"
if [ ! -d "$K8S_DIR" ] && [ -d "kubernetes" ]; then
K8S_DIR="kubernetes"
fi
print_info "Using Kubernetes configurations from: $K8S_DIR/"
# Setup .env file
if [ ! -f ".env" ]; then
print_info "Copying .env.example to .env"
cp .env.example .env
print_warning "Please edit .env file to configure your Kubernetes environment"
read -p "Press Enter to continue after editing .env..."
fi
# Apply Kubernetes configurations
print_info "Applying Kubernetes configurations..."
if kubectl apply -f "$K8S_DIR/"; then
print_success "Kubernetes resources created successfully"
print_info "Check status with: kubectl get pods"
else
print_error "Failed to apply Kubernetes configurations"
exit 1
fi
}
# Main installation menu
main() {
clear
print_header "BOILERPLATE-LARAVEL INSTALLER"
echo "Please select installation type:"
echo ""
echo " 1) Standalone (Local development/production)"
echo " 2) Docker (Containerized deployment)"
echo " 3) Kubernetes (K8s cluster deployment)"
echo " 4) Exit"
echo ""
while true; do
read -p "Enter your choice (1-4): " choice
case $choice in
1)
install_standalone
break
;;
2)
install_docker
break
;;
3)
install_kubernetes
break
;;
4)
print_info "Installation cancelled"
exit 0
;;
*)
print_warning "Invalid choice. Please enter 1, 2, 3, or 4."
;;
esac
done
}
# Run main function
main