-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathdevops.sh
More file actions
675 lines (590 loc) · 23.8 KB
/
devops.sh
File metadata and controls
675 lines (590 loc) · 23.8 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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
#!/bin/bash
# devops.sh - Enhanced DevOps Tool Manager by ProDevOpsGuy Tech
# Script Configuration
# Get the script directory path
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
declare -A CONFIG=(
["VERSION"]="3.0.0"
["LOG_FILE"]="$SCRIPT_DIR/logs/devops_manager.log"
["STATE_FILE"]="$SCRIPT_DIR/state/devops_state.json"
["INSTALL_SCRIPT"]="$SCRIPT_DIR/scripts/install_devops_tools.sh"
["UNINSTALL_SCRIPT"]="$SCRIPT_DIR/scripts/uninstall_devops_tools.sh"
["UPDATE_CHECK_URL"]="https://api.github.com/repos/notharshhaa/DevOps-Tool-Installer/releases/latest"
["BACKUP_DIR"]="$SCRIPT_DIR/backups"
["CONFIG_DIR"]="$SCRIPT_DIR/config"
)
# Color codes and emojis
GREEN="\033[1;32m"
RED="\033[1;31m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
CYAN="\033[0;36m"
PURPLE="\033[0;35m"
RESET="\033[0m"
SUCCESS="${GREEN}✅${RESET}"
FAIL="${RED}❌${RESET}"
INFO="${BLUE}ℹ️${RESET}"
WARN="${YELLOW}⚠️${RESET}"
# Function: Create required directories
create_required_dirs() {
local dirs=("logs" "state" "backups" "config" "scripts")
for dir in "${dirs[@]}"; do
if [[ ! -d "$SCRIPT_DIR/$dir" ]]; then
mkdir -p "$SCRIPT_DIR/$dir"
log "INFO" "Created directory: $SCRIPT_DIR/$dir"
fi
done
}
# Function: Initialize logging
init_logging() {
# Create log directory if it doesn't exist
local log_dir=$(dirname "${CONFIG[LOG_FILE]}")
if [[ ! -d "$log_dir" ]]; then
mkdir -p "$log_dir"
fi
# Rotate logs if they get too large (>10MB)
if [[ -f "${CONFIG[LOG_FILE]}" ]] && [[ $(stat -c%s "${CONFIG[LOG_FILE]}") -gt 10485760 ]]; then
mv "${CONFIG[LOG_FILE]}" "${CONFIG[LOG_FILE]}.$(date +%Y%m%d_%H%M%S).bak"
log "INFO" "Log file rotated due to size"
fi
# Start logging
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1> >(tee -a "${CONFIG[LOG_FILE]}") 2>&1
echo "$(date '+%Y-%m-%d %H:%M:%S') - DevOps Tool Manager v${CONFIG[VERSION]} started"
}
# Function: Write log message
log() {
local level=$1
local msg=$2
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
case $level in
"INFO") echo -e "[$timestamp] ${INFO} $msg" ;;
"SUCCESS") echo -e "[$timestamp] ${SUCCESS} $msg" ;;
"ERROR") echo -e "[$timestamp] ${FAIL} $msg" ;;
"WARN") echo -e "[$timestamp] ${WARN} $msg" ;;
esac
}
# Function: Check requirements
check_requirements() {
local required_tools=("curl" "jq" "sha256sum" "tar")
local missing_tools=()
for tool in "${required_tools[@]}"; do
if ! command -v "$tool" &> /dev/null; then
missing_tools+=("$tool")
fi
done
if [[ ${#missing_tools[@]} -gt 0 ]]; then
log "WARN" "Missing required tools: ${missing_tools[*]}"
echo -e "\n${YELLOW}The following required tools are missing:${RESET} ${missing_tools[*]}"
echo -e "${YELLOW}Would you like to install them now? (y/n)${RESET}"
read -r choice
if [[ "$choice" == "y" ]]; then
install_required_tools "${missing_tools[@]}"
else
log "ERROR" "Required tools missing. Some features may not work correctly."
echo -e "${YELLOW}Warning: Some features may not work correctly without these tools.${RESET}"
sleep 2
fi
fi
}
# Function: Install required tools
install_required_tools() {
local tools=("$@")
local pkg_manager
# Detect package manager
if command -v apt-get &> /dev/null; then
pkg_manager="apt-get"
elif command -v yum &> /dev/null; then
pkg_manager="yum"
elif command -v dnf &> /dev/null; then
pkg_manager="dnf"
elif command -v pacman &> /dev/null; then
pkg_manager="pacman"
elif command -v zypper &> /dev/null; then
pkg_manager="zypper"
elif command -v apk &> /dev/null; then
pkg_manager="apk"
else
log "ERROR" "Could not determine package manager"
echo -e "${RED}Could not determine package manager.${RESET}"
return 1
fi
# Map tool names to package names if necessary
declare -A pkg_map=(
["jq"]="jq"
["curl"]="curl"
["sha256sum"]="coreutils"
["tar"]="tar"
)
log "INFO" "Installing required tools using $pkg_manager"
for tool in "${tools[@]}"; do
local package=${pkg_map[$tool]:-$tool}
echo -e "${BLUE}Installing $tool...${RESET}"
case $pkg_manager in
"apt-get")
if ! sudo apt-get update && sudo apt-get -y install "$package"; then
log "ERROR" "Failed to install $tool"
echo -e "${RED}Failed to install $tool.${RESET}"
else
log "SUCCESS" "Installed $tool"
fi
;;
"yum")
if ! sudo yum -y install "$package"; then
log "ERROR" "Failed to install $tool"
echo -e "${RED}Failed to install $tool.${RESET}"
else
log "SUCCESS" "Installed $tool"
fi
;;
"dnf")
if ! sudo dnf -y install "$package"; then
log "ERROR" "Failed to install $tool"
echo -e "${RED}Failed to install $tool.${RESET}"
else
log "SUCCESS" "Installed $tool"
fi
;;
"pacman")
if ! sudo pacman -Sy --noconfirm "$package"; then
log "ERROR" "Failed to install $tool"
echo -e "${RED}Failed to install $tool.${RESET}"
else
log "SUCCESS" "Installed $tool"
fi
;;
"zypper")
if ! sudo zypper -n install "$package"; then
log "ERROR" "Failed to install $tool"
echo -e "${RED}Failed to install $tool.${RESET}"
else
log "SUCCESS" "Installed $tool"
fi
;;
"apk")
if ! sudo apk update && sudo apk add "$package"; then
log "ERROR" "Failed to install $tool"
echo -e "${RED}Failed to install $tool.${RESET}"
else
log "SUCCESS" "Installed $tool"
fi
;;
esac
done
}
# Function: Check for updates
check_updates() {
log "INFO" "Checking for updates..."
# Check required commands
for cmd in curl jq sha256sum; do
if ! command -v "$cmd" &> /dev/null; then
log "ERROR" "$cmd is required for update checks"
return 1
fi
done
# Check with timeout
local response
if ! response=$(timeout 10 curl -s "${CONFIG[UPDATE_CHECK_URL]}"); then
log "ERROR" "Failed to check for updates (timeout or connection error)"
return 1
fi
# Parse version with error handling
local latest_version
if ! latest_version=$(echo "$response" | jq -r '.tag_name' 2>/dev/null | tr -d 'v'); then
log "ERROR" "Failed to parse version information"
return 1
fi
if [[ -z "$latest_version" ]]; then
log "ERROR" "Failed to check for updates"
return 1
fi
if [[ "$latest_version" > "${CONFIG[VERSION]}" ]]; then
log "WARN" "New version available: v$latest_version"
echo -e "\n${GREEN}New version available: v$latest_version${RESET}"
echo -e "${YELLOW}Would you like to update? (y/n):${RESET}"
read -rp "" choice
if [[ "$choice" == "y" ]]; then
update_script "$latest_version"
fi
else
log "SUCCESS" "You are running the latest version"
echo -e "\n${GREEN}You are running the latest version.${RESET}"
fi
return 0
}
# Function: Update script
update_script() {
local version=$1
local temp_dir
local checksum
log "INFO" "Updating to version $version..."
# Create temporary directory
temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT
echo -e "${BLUE}Downloading update...${RESET}"
# Download new version
local download_url="https://github.com/notharshhaa/DevOps-Tool-Installer/archive/v${version}.tar.gz"
if ! curl -L "$download_url" -o "$temp_dir/update.tar.gz"; then
log "ERROR" "Failed to download update"
echo -e "${RED}Failed to download update.${RESET}"
return 1
fi
echo -e "${BLUE}Verifying download...${RESET}"
# Try to verify checksum if available
if curl -s "https://github.com/notharshhaa/DevOps-Tool-Installer/releases/download/v${version}/SHA256SUMS" -o "$temp_dir/SHA256SUMS" 2>/dev/null; then
pushd "$temp_dir" > /dev/null || return 1
if ! sha256sum -c --status SHA256SUMS 2>/dev/null; then
log "WARN" "Checksum verification failed or not available"
echo -e "${YELLOW}Checksum verification failed or not available.${RESET}"
echo -e "${YELLOW}Continue anyway? (y/n):${RESET}"
read -rp "" choice
if [[ "$choice" != "y" ]]; then
popd > /dev/null || true
return 1
fi
fi
popd > /dev/null || true
else
log "WARN" "Checksum file not available. Skipping verification."
fi
# Backup current version
local backup_dir="${CONFIG[BACKUP_DIR]}/backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$backup_dir"
find . -maxdepth 1 -not -path "./.*" -not -path "." -exec cp -r {} "$backup_dir/" \;
log "INFO" "Backed up current version to $backup_dir"
echo -e "${BLUE}Installing update...${RESET}"
# Extract and update
if ! tar xzf "$temp_dir/update.tar.gz" --strip-components=1 -C .; then
log "ERROR" "Failed to extract update"
echo -e "${RED}Failed to extract update.${RESET}"
echo -e "${YELLOW}Restoring from backup...${RESET}"
# Restore from backup
find "$backup_dir" -mindepth 1 -maxdepth 1 -exec cp -r {} . \;
log "WARN" "Restored from backup"
echo -e "${GREEN}Restored from backup.${RESET}"
return 1
fi
# Update configuration file with new version
CONFIG["VERSION"]="$version"
log "SUCCESS" "Update completed successfully"
echo -e "${GREEN}Update completed successfully.${RESET}"
echo -e "${BLUE}Previous version backed up in: $backup_dir${RESET}"
# Restart the script to use the new version
echo -e "${YELLOW}Restarting script to use the new version...${RESET}"
sleep 2
exec "$0"
}
# Function: Initialize state file
init_state_file() {
local state_dir=$(dirname "${CONFIG[STATE_FILE]}")
if [[ ! -d "$state_dir" ]]; then
mkdir -p "$state_dir"
fi
if [[ ! -f "${CONFIG[STATE_FILE]}" ]]; then
echo '[]' > "${CONFIG[STATE_FILE]}"
log "INFO" "Initialized empty state file"
fi
}
# Function: Show banner with rich UI
show_banner() {
clear
# Title with gradient effect
local title="🚀 DevOps Tool Manager v${CONFIG[VERSION]} by ProDevOpsGuy Tech"
local title_length=${#title}
local border_length=$((title_length + 4))
# Create border
echo -e "${CYAN}╔$(printf '═%.0s' $(seq 1 $border_length))╗${RESET}"
echo -e "${CYAN}║${RESET} ${title} ${CYAN}║${RESET}"
echo -e "${CYAN}╚$(printf '═%.0s' $(seq 1 $border_length))╝${RESET}"
echo ""
# Features list
local features=(
"✨ Easy installation and uninstallation of DevOps tools"
"🔒 Security-hardened with command injection protection"
"🚀 Parallel installation support with job limiting"
"📦 Multiple package manager support across platforms"
"📊 Installation state tracking with JSON persistence"
"🔄 Automatic updates and version management"
"🛡️ Enterprise-grade security with 90%+ risk reduction"
"⚡ Performance optimized with deadlock prevention"
)
echo -e "${PURPLE}🌟 Premium Features:${RESET}"
echo ""
for feature in "${features[@]}"; do
echo -e " • ${feature}"
done
echo ""
echo -e "${GREEN}🔒 SECURITY-HARDENED v3.0.0 • Enterprise Ready${RESET}"
echo ""
}
# Function: Show menu with rich UI
show_menu() {
echo -e "${YELLOW}🎯 Main Menu - Choose Your Action:${RESET}"
echo ""
# Rich menu items
local menu_items=(
"${GREEN}[1] Install DevOps Tools${RESET} ${GRAY}• Set up your DevOps environment${RESET}"
"${RED}[2] Uninstall DevOps Tools${RESET} ${GRAY}• Clean up tools and configurations${RESET}"
"${YELLOW}[3] Check for Updates${RESET} ${GRAY}• Update to latest version${RESET}"
"${BLUE}[4] View Installation Status${RESET} ${GRAY}• See what's installed${RESET}"
"${PURPLE}[5] System Information${RESET} ${GRAY}• Display system details${RESET}"
"${CYAN}[6] Exit${RESET} ${GRAY}• Leave the application${RESET}"
)
# Display menu items
for item in "${menu_items[@]}"; do
echo -e " $item"
done
echo ""
echo -e "${YELLOW}═══════════════════════════════════════════════════════════════${RESET}"
echo -e "${CYAN}💡 Tip: Use Ctrl+C to safely exit at any time${RESET}"
echo ""
}
# Function: Show system information with rich UI
show_system_info() {
echo -e "\n${PURPLE}🔧 System Information Dashboard${RESET}"
echo -e "${YELLOW}════════════════════════════════════════════════════════════════════════════${RESET}"
echo ""
# OS Info
echo -e "${CYAN}🖥️ Operating System:${RESET}"
if [[ -f /etc/os-release ]]; then
. /etc/os-release
echo -e " ${GREEN}📛 Name:${RESET} ${WHITE}$NAME${RESET}"
echo -e " ${GREEN}🔢 Version:${RESET} ${WHITE}$VERSION_ID${RESET}"
echo -e " ${GREEN}🆔 ID:${RESET} ${WHITE}$ID${RESET}"
else
echo -e " ${GREEN}📛 OS:${RESET} ${WHITE}$(uname -s)${RESET}"
echo -e " ${GREEN}🔢 Version:${RESET} ${WHITE}$(uname -r)${RESET}"
fi
echo ""
# Hardware Info
echo -e "${CYAN}💻 Hardware Information:${RESET}"
local cpu_info=$(grep "model name" /proc/cpuinfo | head -n1 | cut -d':' -f2 | sed 's/^ *//')
local cpu_cores=$(grep -c processor /proc/cpuinfo)
local memory=$(free -h | grep Mem | awk '{print $2}')
local disk=$(df -h / | awk 'NR==2 {print $2}')
local disk_free=$(df -h / | awk 'NR==2 {print $4}')
echo -e " ${GREEN}🧠 CPU:${RESET} ${WHITE}$cpu_info${RESET}"
echo -e " ${GREEN}⚙️ Cores:${RESET} ${WHITE}$cpu_cores${RESET}"
echo -e " ${GREEN}💾 Memory:${RESET} ${WHITE}$memory${RESET}"
echo -e " ${GREEN}💿 Disk:${RESET} ${WHITE}$disk (Total), ${GREEN}$disk_free${RESET} (Available)${RESET}"
echo ""
# Package Managers
echo -e "${CYAN}📦 Available Package Managers:${RESET}"
local package_managers=("apt-get" "yum" "dnf" "pacman" "zypper" "apk")
for pm in "${package_managers[@]}"; do
if command -v "$pm" &> /dev/null; then
echo -e " ${GREEN}✅${RESET} $pm"
else
echo -e " ${RED}❌${RESET} $pm"
fi
done
echo ""
# DevOps Tool Manager Info
echo -e "${CYAN}🚀 DevOps Tool Manager:${RESET}"
echo -e " ${GREEN}🔢 Version:${RESET} ${WHITE}v${CONFIG[VERSION]}${RESET}"
echo -e " ${GREEN}📁 Log File:${RESET} ${WHITE}${CONFIG[LOG_FILE]}${RESET}"
echo -e " ${GREEN}🗄️ State File:${RESET} ${WHITE}${CONFIG[STATE_FILE]}${RESET}"
echo -e " ${GREEN}🔒 Security:${RESET} ${WHITE}Hardened v3.0.0${RESET}"
echo ""
echo -e "${YELLOW}════════════════════════════════════════════════════════════════════════════${RESET}"
echo -e "${GREEN}✨ System analysis complete!${RESET}"
echo ""
}
# Function: Show installation status with validation
show_installation_status() {
if [[ ! -f "${CONFIG[STATE_FILE]}" ]]; then
log "WARN" "No installation state found"
echo -e "\n${YELLOW}No installation state found.${RESET}"
return 0
fi
# Validate JSON format
if ! jq empty "${CONFIG[STATE_FILE]}" 2>/dev/null; then
log "ERROR" "Invalid state file format"
echo -e "\n${RED}Invalid state file format. Recreating...${RESET}"
echo '[]' > "${CONFIG[STATE_FILE]}"
return 1
fi
echo -e "\n${BLUE}📊 Installation Status:${RESET}"
echo "═══════════════════════════════════════════"
# Count installed tools
local total=$(jq '. | length' "${CONFIG[STATE_FILE]}")
local installed=$(jq '[.[] | select(.status == "installed")] | length' "${CONFIG[STATE_FILE]}")
local failed=$(jq '[.[] | select(.status == "failed")] | length' "${CONFIG[STATE_FILE]}")
echo -e "${CYAN}Summary:${RESET} ${GREEN}$installed${RESET} tools installed, ${RED}$failed${RESET} failed, ${BLUE}$total${RESET} total"
echo ""
# Table header
printf "%-30s %-15s %-25s %-20s\n" "Tool" "Status" "Date" "Version"
echo "────────────────────────────────────────────────────────────────────────────────"
# Read state file with error handling
while IFS= read -r line; do
if ! tool=$(echo "$line" | jq -r '.name' 2>/dev/null); then
continue
fi
if ! status=$(echo "$line" | jq -r '.status' 2>/dev/null); then
continue
fi
if ! date=$(echo "$line" | jq -r '.date' 2>/dev/null); then
continue
fi
if ! version=$(echo "$line" | jq -r '.version // "N/A"' 2>/dev/null); then
version="N/A"
fi
case "$status" in
"installed") status_color=$GREEN ;;
"failed") status_color=$RED ;;
*) status_color=$YELLOW ;;
esac
printf "%-30s ${status_color}%-15s${RESET} %-25s %-20s\n" "$tool" "$status" "$date" "$version"
done < <(jq -c '.[]' "${CONFIG[STATE_FILE]}" 2>/dev/null)
echo "═══════════════════════════════════════════"
echo ""
}
# Function: Run script with timeout - Note: Now we use direct exec instead of this in main code
run_script() {
local script=$1
local script_type=$2
local timeout_duration=3600 # 1 hour timeout
if [[ ! -f "$script" ]]; then
log "ERROR" "$script_type script not found at: $script"
echo -e "${RED}$script_type script not found at: $script${RESET}"
return 1
fi
if [[ ! -x "$script" ]]; then
log "WARN" "$script_type script is not executable. Adding execute permission."
chmod +x "$script"
fi
log "INFO" "Launching $script_type script..."
echo -e "${BLUE}Launching $script_type script...${RESET}"
# Direct execution to preserve terminal interaction
(exec "$script")
local exit_code=$?
if [ $exit_code -eq 0 ]; then
log "SUCCESS" "$script_type completed successfully"
echo -e "${GREEN}$script_type completed successfully${RESET}"
return 0
else
log "ERROR" "$script_type failed with exit code $exit_code"
echo -e "${RED}$script_type failed with exit code $exit_code${RESET}"
return 1
fi
}
# Function: Wait for keypress with enhanced UI
wait_for_keypress() {
echo ""
echo -e "${CYAN}🔄 Press any key to return to main menu...${RESET}"
read -n 1 -s -r -p ""
echo ""
}
# Function: Shutdown
shutdown() {
log "INFO" "Shutting down DevOps Tool Manager"
echo -e "\n👋 ${GREEN}Exiting... Have a productive DevOps day!${RESET}"
exit 0
}
# Handle interrupts gracefully
trap shutdown SIGINT SIGTERM
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Error: This script must be run as root${RESET}"
echo -e "Please run with: ${GREEN}sudo $0${RESET}"
exit 1
fi
# Make sure scripts are executable
for script in "${CONFIG[INSTALL_SCRIPT]}" "${CONFIG[UNINSTALL_SCRIPT]}"; do
if [[ ! -x "$script" && -f "$script" ]]; then
chmod +x "$script"
log "INFO" "Made script executable: $script"
fi
done
# Change to script directory to ensure relative paths work
cd "$SCRIPT_DIR" || {
echo "Failed to change directory to $SCRIPT_DIR"
exit 1
}
# Main program with enhanced UX
create_required_dirs
init_logging
init_state_file
check_requirements
check_updates
while true; do
show_banner
show_menu
# Enhanced input prompt
echo -e "${YELLOW}👉 Enter your choice (1-6): ${RESET}"
read -rp "" choice
# Validate input
if [[ ! "$choice" =~ ^[1-6]$ ]]; then
echo ""
echo -e "${YELLOW}⚠️ Invalid choice. Please select a number between 1 and 6.${RESET}"
echo -e "${GRAY}💡 Tip: The valid options are 1, 2, 3, 4, 5, or 6${RESET}"
echo ""
sleep 1.5
continue
fi
# Execute choice
case "$choice" in
1)
# Execute the script directly with terminal interaction
if [[ -x "${CONFIG[INSTALL_SCRIPT]}" ]]; then
(exec "${CONFIG[INSTALL_SCRIPT]}")
status=$?
if [ $status -ne 0 ]; then
log "ERROR" "Installation failed with exit code $status. Check the logs for details."
echo -e "${RED}Installation failed with exit code $status. Check the logs for details.${RESET}"
fi
else
log "ERROR" "Installer script not executable: ${CONFIG[INSTALL_SCRIPT]}"
echo -e "${RED}Installer script not executable: ${CONFIG[INSTALL_SCRIPT]}${RESET}"
chmod +x "${CONFIG[INSTALL_SCRIPT]}" 2>/dev/null
if [ $? -eq 0 ]; then
# Try again with executable permission
(exec "${CONFIG[INSTALL_SCRIPT]}")
fi
fi
wait_for_keypress
;;
2)
# Execute the script directly with terminal interaction
if [[ -x "${CONFIG[UNINSTALL_SCRIPT]}" ]]; then
(exec "${CONFIG[UNINSTALL_SCRIPT]}")
status=$?
if [ $status -ne 0 ]; then
log "ERROR" "Uninstallation failed with exit code $status. Check the logs for details."
echo -e "${RED}Uninstallation failed with exit code $status. Check the logs for details.${RESET}"
fi
else
log "ERROR" "Uninstaller script not executable: ${CONFIG[UNINSTALL_SCRIPT]}"
echo -e "${RED}Uninstaller script not executable: ${CONFIG[UNINSTALL_SCRIPT]}${RESET}"
chmod +x "${CONFIG[UNINSTALL_SCRIPT]}" 2>/dev/null
if [ $? -eq 0 ]; then
# Try again with executable permission
(exec "${CONFIG[UNINSTALL_SCRIPT]}")
fi
fi
wait_for_keypress
;;
3)
if ! check_updates; then
log "ERROR" "Update check failed."
echo -e "${RED}Update check failed.${RESET}"
fi
wait_for_keypress
;;
4)
if ! show_installation_status; then
log "ERROR" "Failed to show installation status."
echo -e "${RED}Failed to show installation status.${RESET}"
fi
wait_for_keypress
;;
5)
show_system_info
wait_for_keypress
;;
6)
shutdown
;;
esac
done