diff --git a/scripts/check-health.sh b/scripts/check-health.sh index f8efff3..854df4a 100755 --- a/scripts/check-health.sh +++ b/scripts/check-health.sh @@ -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 diff --git a/scripts/recover.sh b/scripts/recover.sh index ee7562d..d9c5edf 100755 --- a/scripts/recover.sh +++ b/scripts/recover.sh @@ -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" diff --git a/scripts/restore.sh b/scripts/restore.sh index 1e86281..4be1e53 100755 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -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 diff --git a/scripts/update.sh b/scripts/update.sh index 0643cc4..142a8db 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -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() {