Refactor all scripts to use common.sh for consistent colored logging

- Update restore.sh to use common.sh instead of inline log function
- Update update.sh to use common.sh instead of inline log function
- Update recover.sh to use common.sh instead of inline log function
- Update check-health.sh to import colors from common.sh

Benefits:
- DRY principle: color definitions in one place
- Consistent logging across all scripts
- Easier maintenance: change log format once
- All scripts now have colored output in terminal
- Reduced code duplication (48 lines removed)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
BeauTroll
2025-12-17 19:26:47 +01:00
parent 58bc9a47cc
commit f3c74de015
4 changed files with 28 additions and 48 deletions

View File

@@ -8,39 +8,33 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT"
LOG_DIR="./logs"
LOG_FILE="$LOG_DIR/restore_$(date +%Y%m%d_%H%M%S).log"
TEMP_DIR=""
# Créer le dossier de logs
mkdir -p "$LOG_DIR"
# Fonction de logging
log() {
local level="$1"
shift
local message="$*"
local timestamp
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$timestamp] [$level] $message" | tee -a "$LOG_FILE"
}
# Charger les variables d'environnement
# Charger .env en premier
if [ ! -f .env ]; then
log "ERROR" "Fichier .env introuvable"
echo "ERROR: Fichier .env introuvable"
exit 1
fi
# Charger .env de manière sécurisée
set -a
# shellcheck disable=SC1091
source .env
set +a
# Configuration des logs
LOG_DIR="./logs"
LOG_FILE="$LOG_DIR/restore_$(date +%Y%m%d_%H%M%S).log"
TEMP_DIR=""
mkdir -p "$LOG_DIR"
# Charger les fonctions communes (log avec couleurs)
# shellcheck disable=SC1091
source "$SCRIPT_DIR/common.sh"
# Vérifier les variables requises
: "${MYSQL_USER:?Variable MYSQL_USER non définie}"
: "${MYSQL_PASSWORD:?Variable MYSQL_PASSWORD non définie}"
: "${MYSQL_DATABASE:?Variable MYSQL_DATABASE non définie}"
if [ -z "${MYSQL_USER:-}" ] || [ -z "${MYSQL_PASSWORD:-}" ] || [ -z "${MYSQL_DATABASE:-}" ]; then
log "ERROR" "Variables MySQL non définies dans .env"
exit 1
fi
# Vérifier les arguments
if [ -z "${1:-}" ]; then