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