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:
@@ -8,11 +8,9 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Couleurs pour l'output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
# Charger les couleurs depuis common.sh
|
||||
# shellcheck disable=SC1091
|
||||
source "$SCRIPT_DIR/common.sh"
|
||||
|
||||
# Compteurs
|
||||
CHECKS_PASSED=0
|
||||
|
||||
@@ -8,21 +8,15 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Configuration des logs
|
||||
LOG_DIR="./logs"
|
||||
LOG_FILE="$LOG_DIR/recover_$(date +%Y%m%d_%H%M%S).log"
|
||||
|
||||
# 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 fonctions communes (log avec couleurs)
|
||||
# shellcheck disable=SC1091
|
||||
source "$SCRIPT_DIR/common.sh"
|
||||
|
||||
log "INFO" "=== Script de récupération Nextcloud ==="
|
||||
log "INFO" "Log file: $LOG_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
|
||||
|
||||
@@ -8,23 +8,17 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Configuration des logs
|
||||
LOG_DIR="./logs"
|
||||
LOG_FILE="$LOG_DIR/update_$(date +%Y%m%d_%H%M%S).log"
|
||||
MAINTENANCE_ENABLED=false
|
||||
COMPOSE_BACKUP=""
|
||||
|
||||
# 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 fonctions communes (log avec couleurs)
|
||||
# shellcheck disable=SC1091
|
||||
source "$SCRIPT_DIR/common.sh"
|
||||
|
||||
# Fonction de nettoyage en cas d'erreur
|
||||
cleanup() {
|
||||
|
||||
Reference in New Issue
Block a user