fix: refactor gitapply.sh for improved color handling and task management

This commit is contained in:
2025-12-23 20:36:15 -05:00
parent 62ce1e3642
commit 390a9e6877

View File

@@ -1,222 +1,165 @@
#!/bin/bash
# Colors - Blue to Teal/Cyan gradient palette
BLUE='\033[0;34m'
LBLUE='\033[1;34m'
CYAN='\033[0;36m'
LCYAN='\033[1;36m'
GREEN='\033[0;32m'
TEAL='\033[38;5;37m'
DTEAL='\033[38;5;30m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m' # No Color
# ============================================================================
# Virtnet.bond - Paymenter Load Balancer Git Update Script
# ============================================================================
# Symbols
CHECK="✔"
CROSS="✖"
ARROW="➜"
GEAR="⚙"
ROCKET="🚀"
SPARKLE="✨"
# 256-Color Gradient Palette (Blue to Teal)
# #0c00ff -> #0066ff -> #008dff -> #00a6ff -> #00bbe7 -> #00cd9a
C1='\e[38;5;21m' # Deep Blue
C2='\e[38;5;27m' # Blue
C3='\e[38;5;33m' # Light Blue
C4='\e[38;5;39m' # Cyan Blue
C5='\e[38;5;44m' # Cyan
C6='\e[38;5;43m' # Teal
# Animation frames
SPINNER_FRAMES=("⠋" "⠙" "⠹" "⠸" "⠼" "⠴" "⠦" "⠧" "⠇" "⠏")
PROGRESS_CHARS=("░" "▒" "▓" "█")
# Standard colors
WHITE='\e[97m'
GRAY='\e[90m'
RED='\e[91m'
YELLOW='\e[93m'
GREEN='\e[92m'
BOLD='\e[1m'
DIM='\e[2m'
NC='\e[0m'
# Typewriter effect function
typewriter() {
local text="$1"
local delay="${2:-0.03}"
for ((i=0; i<${#text}; i++)); do
echo -n "${text:$i:1}"
sleep "$delay"
done
# Spinner frames
SPIN=('⣾' '⣽' '⣻' '⢿' '⡿' '⣟' '⣯' '⣷')
# ============================================================================
# FUNCTIONS
# ============================================================================
print_header() {
clear
echo ""
echo -e " ${C1}██╗ ██╗${C2}██╗${C3}██████╗ ${C3}████████╗${C4}███╗ ██╗${C5}███████╗${C6}████████╗${NC}"
echo -e " ${C1}██║ ██║${C2}██║${C3}██╔══██╗${C3}╚══██╔══╝${C4}████╗ ██║${C5}██╔════╝${C6}╚══██╔══╝${NC}"
echo -e " ${C1}██║ ██║${C2}██║${C3}██████╔╝${C3} ██║ ${C4}██╔██╗ ██║${C5}█████╗ ${C6} ██║ ${NC}"
echo -e " ${C1}╚██╗ ██╔╝${C2}██║${C3}██╔══██╗${C3} ██║ ${C4}██║╚██╗██║${C5}██╔══╝ ${C6} ██║ ${NC}"
echo -e " ${C1} ╚████╔╝ ${C2}██║${C3}██║ ██║${C3} ██║ ${C4}██║ ╚████║${C5}███████╗${C6} ██║ ${NC}"
echo -e " ${C1} ╚═══╝ ${C2}╚═╝${C3}╚═╝ ╚═╝${C3} ╚═╝ ${C4}╚═╝ ╚═══╝${C5}╚══════╝${C6} ╚═╝ ${NC}"
echo -e " ${C6}${BOLD}.bond${NC}"
echo ""
echo -e " ${C4}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e " ${WHITE}${BOLD} Paymenter Load Balancer - Git Update & Apply${NC}"
echo -e " ${C4}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
}
# Spinner function - runs command with animated spinner
spinner() {
local pid=$1
local message="$2"
local msg=$2
local i=0
while kill -0 "$pid" 2>/dev/null; do
echo -ne "\r ${LBLUE}${SPINNER_FRAMES[$i]}${NC} ${message}"
i=$(( (i + 1) % ${#SPINNER_FRAMES[@]} ))
printf "\r ${C3}${SPIN[$i]}${NC} ${msg}"
i=$(( (i + 1) % 8 ))
sleep 0.1
done
wait "$pid"
return $?
}
# Progress bar function
progress_bar() {
local duration=$1
local width=30
local step=$(echo "scale=4; $duration / $width" | bc)
task_start() {
echo -e "\n${C4}┌─${NC} ${C5}${BOLD}$1${NC}"
}
echo -ne " ${LBLUE}[${NC}"
for ((i=0; i<width; i++)); do
echo -ne "${TEAL}█${NC}"
sleep "$step"
task_item() {
printf " ${C3}○${NC} $1"
}
task_done() {
printf "\r ${C6}●${NC} $1 ${GREEN}✓${NC}\n"
}
task_fail() {
printf "\r ${RED}●${NC} $1 ${RED}✗${NC}\n"
}
countdown() {
local secs=$1
for ((i=secs; i>0; i--)); do
printf "\r ${C3}◐${NC} Waiting ${C5}${BOLD}$i${NC}s "
sleep 0.25
printf "\r ${C3}◓${NC} Waiting ${C5}${BOLD}$i${NC}s "
sleep 0.25
printf "\r ${C3}◑${NC} Waiting ${C5}${BOLD}$i${NC}s "
sleep 0.25
printf "\r ${C3}◒${NC} Waiting ${C5}${BOLD}$i${NC}s "
sleep 0.25
done
echo -e "${LBLUE}]${NC} ${TEAL}${CHECK}${NC}"
printf "\r ${C6}●${NC} Ready! ${GREEN}✓${NC}\n"
}
# Animated box drawing
draw_box_top() {
echo -ne "${CYAN}"
echo -n "╔"
for ((i=0; i<58; i++)); do
echo -n "═"
sleep 0.005
done
echo -e "╗${NC}"
print_complete() {
echo ""
echo -e " ${C4}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo -e " ${C6}${BOLD}🚀 UPDATE COMPLETE${NC}"
echo ""
echo -e " ${GRAY}Paymenter has been updated and all services restarted.${NC}"
echo ""
echo -e " ${C4}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
}
draw_box_bottom() {
echo -ne "${CYAN}"
echo -n "╚"
for ((i=0; i<58; i++)); do
echo -n "═"
sleep 0.005
done
echo -e "╝${NC}"
}
# ============================================================================
# MAIN SCRIPT
# ============================================================================
# Fade in logo line by line
fade_in_logo() {
echo -e "${CYAN}║ ║${NC}"
sleep 0.08
echo -e "${CYAN}║ ${BLUE}██╗ ██╗${LBLUE}██╗${LCYAN}██████╗ ${LCYAN}████████╗${CYAN}███╗ ██╗${TEAL}███████╗${TEAL}████████╗${CYAN} ║${NC}"
sleep 0.08
echo -e "${CYAN}║ ${BLUE}██║ ██║${LBLUE}██║${LCYAN}██╔══██╗${LCYAN}╚══██╔══╝${CYAN}████╗ ██║${TEAL}██╔════╝${TEAL}╚══██╔══╝${CYAN} ║${NC}"
sleep 0.08
echo -e "${CYAN}║ ${BLUE}██║ ██║${LBLUE}██║${LCYAN}██████╔╝${LCYAN} ██║ ${CYAN}██╔██╗ ██║${TEAL}█████╗ ${TEAL} ██║ ${CYAN} ║${NC}"
sleep 0.08
echo -e "${CYAN}║ ${BLUE}╚██╗ ██╔╝${LBLUE}██║${LCYAN}██╔══██╗${LCYAN} ██║ ${CYAN}██║╚██╗██║${TEAL}██╔══╝ ${TEAL} ██║ ${CYAN} ║${NC}"
sleep 0.08
echo -e "${CYAN}║ ${BLUE} ╚████╔╝ ${LBLUE}██║${LCYAN}██║ ██║${LCYAN} ██║ ${CYAN}██║ ╚████║${TEAL}███████╗${TEAL} ██║ ${CYAN} ║${NC}"
sleep 0.08
echo -e "${CYAN}║ ${BLUE} ╚═══╝ ${LBLUE}╚═╝${LCYAN}╚═╝ ╚═╝${LCYAN} ╚═╝ ${CYAN}╚═╝ ╚═══╝${TEAL}╚══════╝${TEAL} ╚═╝ ${CYAN} ║${NC}"
sleep 0.08
echo -e "${CYAN}║ ${DTEAL}.bond${NC}${CYAN} ║${NC}"
sleep 0.08
echo -e "${CYAN}║ ║${NC}"
sleep 0.08
echo -e "${CYAN}║ ${BOLD}${YELLOW}Paymenter Load Balancer - Git Update & Apply${NC}${CYAN} ║${NC}"
sleep 0.08
echo -e "${CYAN}║ ║${NC}"
}
print_header
# Pulse effect for status messages
pulse_message() {
local message="$1"
local color="$2"
for i in {1..2}; do
echo -ne "\r ${color}${BOLD}${message}${NC}"
sleep 0.15
echo -ne "\r ${color}${DIM}${message}${NC}"
sleep 0.15
done
echo -ne "\r ${color}${message}${NC}"
}
clear
# Animated header
draw_box_top
fade_in_logo
draw_box_bottom
echo ""
# Animated repository info
echo -ne "${LBLUE}${ARROW}${NC} Repository: "
typewriter "https://gitea.virtnet.bond/Joseph.Rawlings/Virtnet.bond/" 0.02
echo -e "${NC}"
echo ""
echo -e " ${C3}→${NC} ${GRAY}Repository:${NC} ${C5}https://gitea.virtnet.bond/Joseph.Rawlings/Virtnet.bond/${NC}"
# Random delay
sleep_time=$((RANDOM % 5 + 1))
cd /var/www/paymenter
# Preparing update with animated countdown
echo -e "${TEAL}${GEAR}${NC} ${BOLD}Preparing update...${NC}"
echo -ne " ${LBLUE}⏳${NC} Waiting "
for ((i=sleep_time; i>0; i--)); do
echo -ne "${LCYAN}${BOLD}${i}${NC} "
for frame in "${SPINNER_FRAMES[@]}"; do
echo -ne "${LBLUE}${frame}${NC}"
sleep 0.1
echo -ne "\b"
done
done
echo -e "${TEAL}${CHECK}${NC} ${SPARKLE}"
echo ""
# Prepare
task_start "Preparing Update"
countdown "$sleep_time"
# Git pull with spinner
echo -e "${TEAL}${GEAR}${NC} ${BOLD}Pulling latest changes from Git...${NC}"
# Git Pull
task_start "Pulling Latest Changes"
task_item "Fetching from remote..."
git pull > /tmp/git_output.txt 2>&1 &
GIT_PID=$!
spinner $GIT_PID "Fetching from remote..."
spinner $! "Fetching from remote..."
GIT_STATUS=$?
if [ $GIT_STATUS -ne 0 ]; then
echo -e "\r ${RED}${CROSS}${NC} Git pull failed! "
task_fail "Git pull failed"
echo ""
cat /tmp/git_output.txt
echo ""
pulse_message "Restarting script..." "${YELLOW}"
echo ""
echo -e " ${YELLOW}↻${NC} ${YELLOW}Restarting script in 2 seconds...${NC}"
sleep 2
exec "$0" "$@"
fi
echo -e "\r ${TEAL}${CHECK}${NC} Git pull completed ${SPARKLE} "
cat /tmp/git_output.txt | head -3 | while read line; do
echo -e " ${DIM}${line}${NC}"
done
echo ""
# Cache clearing with progress
echo -e "${TEAL}${GEAR}${NC} ${BOLD}Clearing caches...${NC}"
echo -ne " ${LBLUE}${SPINNER_FRAMES[0]}${NC} View cache"
task_done "Git pull completed"
head -3 /tmp/git_output.txt | while IFS= read -r line; do
echo -e " ${DIM}$line${NC}"
done
# Clear Caches
task_start "Clearing Caches"
task_item "View cache..."
php artisan view:clear > /dev/null 2>&1 &
spinner $! "View cache"
echo -e "\r ${TEAL}${CHECK}${NC} View cache cleared ${SPARKLE} "
spinner $! "View cache..."
task_done "View cache cleared"
echo -ne " ${LBLUE}${SPINNER_FRAMES[0]}${NC} Application cache"
task_item "Application cache..."
php artisan cache:clear > /dev/null 2>&1 &
spinner $! "Application cache"
echo -e "\r ${TEAL}${CHECK}${NC} Application cache cleared ${SPARKLE} "
echo ""
spinner $! "Application cache..."
task_done "Application cache cleared"
# PHP-FPM restart with progress bar
echo -e "${TEAL}${GEAR}${NC} ${BOLD}Restarting PHP-FPM...${NC}"
# Restart PHP-FPM
task_start "Restarting Services"
task_item "PHP 8.3 FPM..."
systemctl restart php8.3-fpm &
RESTART_PID=$!
spinner $RESTART_PID "Restarting service..."
echo -e "\r ${TEAL}${CHECK}${NC} PHP 8.3 FPM restarted ${SPARKLE} "
echo ""
spinner $! "PHP 8.3 FPM..."
task_done "PHP 8.3 FPM restarted"
# Animated completion box
sleep 0.3
draw_box_top
echo -e "${CYAN}║ ║${NC}"
sleep 0.1
echo -ne "${CYAN}║ ${TEAL}${ROCKET} ${NC}"
typewriter "${BOLD}UPDATE COMPLETE!${NC}" 0.05
echo -e "${CYAN} ║${NC}"
sleep 0.1
echo -e "${CYAN}║ ║${NC}"
echo -e "${CYAN}║ ${NC}Paymenter has been updated and services restarted.${CYAN} ║${NC}"
echo -e "${CYAN}║ ║${NC}"
draw_box_bottom
# Final sparkle animation
echo ""
echo -ne " "
for i in {1..5}; do
echo -ne "${LCYAN}${SPARKLE}${NC} "
sleep 0.15
done
echo ""
echo ""
# Complete
print_complete