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,11 +8,9 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT" cd "$PROJECT_ROOT"
# Couleurs pour l'output # Charger les couleurs depuis common.sh
RED='\033[0;31m' # shellcheck disable=SC1091
GREEN='\033[0;32m' source "$SCRIPT_DIR/common.sh"
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Compteurs # Compteurs
CHECKS_PASSED=0 CHECKS_PASSED=0

View File

@@ -8,21 +8,15 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT" cd "$PROJECT_ROOT"
# Configuration des logs
LOG_DIR="./logs" LOG_DIR="./logs"
LOG_FILE="$LOG_DIR/recover_$(date +%Y%m%d_%H%M%S).log" LOG_FILE="$LOG_DIR/recover_$(date +%Y%m%d_%H%M%S).log"
# Créer le dossier de logs
mkdir -p "$LOG_DIR" mkdir -p "$LOG_DIR"
# Fonction de logging # Charger les fonctions communes (log avec couleurs)
log() { # shellcheck disable=SC1091
local level="$1" source "$SCRIPT_DIR/common.sh"
shift
local message="$*"
local timestamp
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$timestamp] [$level] $message" | tee -a "$LOG_FILE"
}
log "INFO" "=== Script de récupération Nextcloud ===" log "INFO" "=== Script de récupération Nextcloud ==="
log "INFO" "Log file: $LOG_FILE" log "INFO" "Log file: $LOG_FILE"

View File

@@ -8,39 +8,33 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT" cd "$PROJECT_ROOT"
LOG_DIR="./logs" # Charger .env en premier
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
if [ ! -f .env ]; then if [ ! -f .env ]; then
log "ERROR" "Fichier .env introuvable" echo "ERROR: Fichier .env introuvable"
exit 1 exit 1
fi fi
# Charger .env de manière sécurisée
set -a set -a
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source .env source .env
set +a 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 # Vérifier les variables requises
: "${MYSQL_USER:?Variable MYSQL_USER non définie}" if [ -z "${MYSQL_USER:-}" ] || [ -z "${MYSQL_PASSWORD:-}" ] || [ -z "${MYSQL_DATABASE:-}" ]; then
: "${MYSQL_PASSWORD:?Variable MYSQL_PASSWORD non définie}" log "ERROR" "Variables MySQL non définies dans .env"
: "${MYSQL_DATABASE:?Variable MYSQL_DATABASE non définie}" exit 1
fi
# Vérifier les arguments # Vérifier les arguments
if [ -z "${1:-}" ]; then if [ -z "${1:-}" ]; then

View File

@@ -8,23 +8,17 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT" cd "$PROJECT_ROOT"
# Configuration des logs
LOG_DIR="./logs" LOG_DIR="./logs"
LOG_FILE="$LOG_DIR/update_$(date +%Y%m%d_%H%M%S).log" LOG_FILE="$LOG_DIR/update_$(date +%Y%m%d_%H%M%S).log"
MAINTENANCE_ENABLED=false MAINTENANCE_ENABLED=false
COMPOSE_BACKUP="" COMPOSE_BACKUP=""
# Créer le dossier de logs
mkdir -p "$LOG_DIR" mkdir -p "$LOG_DIR"
# Fonction de logging # Charger les fonctions communes (log avec couleurs)
log() { # shellcheck disable=SC1091
local level="$1" source "$SCRIPT_DIR/common.sh"
shift
local message="$*"
local timestamp
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$timestamp] [$level] $message" | tee -a "$LOG_FILE"
}
# Fonction de nettoyage en cas d'erreur # Fonction de nettoyage en cas d'erreur
cleanup() { cleanup() {