Files
Virtnet.bond/gitapply.sh

165 lines
5.6 KiB
Bash
Executable File

#!/bin/bash
# ============================================================================
# Virtnet.bond - Paymenter Load Balancer Git Update Script
# ============================================================================
# 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
# 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'
# 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 ""
echo -e " ${C4}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e " ${WHITE}${BOLD} Paymenter Load Balancer - Git Update & Apply${NC}"
echo -e " ${C4}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
}
spinner() {
local pid=$1
local msg=$2
local i=0
while kill -0 "$pid" 2>/dev/null; do
printf "\r ${C3}${SPIN[$i]}${NC} ${msg}"
i=$(( (i + 1) % 8 ))
sleep 0.1
done
wait "$pid"
return $?
}
task_start() {
echo -e "\n${C4}┌─${NC} ${C5}${BOLD}$1${NC}"
}
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
printf "\r ${C6}●${NC} Ready! ${GREEN}✓${NC}\n"
}
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 ""
}
# ============================================================================
# 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))
cd /var/www/paymenter
# Prepare
task_start "Preparing Update"
countdown "$sleep_time"
# Git Pull
task_start "Pulling Latest Changes"
task_item "Fetching from remote..."
git pull > /tmp/git_output.txt 2>&1 &
spinner $! "Fetching from remote..."
GIT_STATUS=$?
if [ $GIT_STATUS -ne 0 ]; then
task_fail "Git pull failed"
echo ""
cat /tmp/git_output.txt
echo ""
echo -e " ${YELLOW}↻${NC} ${YELLOW}Restarting script in 2 seconds...${NC}"
sleep 2
exec "$0" "$@"
fi
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..."
task_done "View cache cleared"
task_item "Application cache..."
php artisan cache:clear > /dev/null 2>&1 &
spinner $! "Application cache..."
task_done "Application cache cleared"
# Restart PHP-FPM
task_start "Restarting Services"
task_item "PHP 8.3 FPM..."
systemctl restart php8.3-fpm &
spinner $! "PHP 8.3 FPM..."
task_done "PHP 8.3 FPM restarted"
# Complete
print_complete