diff --git a/backup-media.sh b/backup-media.sh index ee759c8..c014630 100755 --- a/backup-media.sh +++ b/backup-media.sh @@ -170,35 +170,35 @@ log_message() { local message="$1" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "${CYAN}[${timestamp}]${NC} ${message}" - echo "[$(date '+%Y-%m-%d %H:%M:%S')] $message" >> "${LOG_FILE}" 2>/dev/null || true + echo "[${timestamp}] $message" >> "${LOG_FILE}" 2>/dev/null || true } log_error() { local message="$1" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "${RED}[${timestamp}] ERROR:${NC} ${message}" >&2 - echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: $message" >> "${LOG_FILE}" 2>/dev/null || true + echo "[${timestamp}] ERROR: $message" >> "${LOG_FILE}" 2>/dev/null || true } log_success() { local message="$1" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "${GREEN}[${timestamp}] SUCCESS:${NC} ${message}" - echo "[$(date '+%Y-%m-%d %H:%M:%S')] SUCCESS: $message" >> "${LOG_FILE}" 2>/dev/null || true + echo "[${timestamp}] SUCCESS: $message" >> "${LOG_FILE}" 2>/dev/null || true } log_warning() { local message="$1" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "${YELLOW}[${timestamp}] WARNING:${NC} ${message}" - echo "[$(date '+%Y-%m-%d %H:%M:%S')] WARNING: $message" >> "${LOG_FILE}" 2>/dev/null || true + echo "[${timestamp}] WARNING: $message" >> "${LOG_FILE}" 2>/dev/null || true } log_info() { local message="$1" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "${BLUE}[${timestamp}] INFO:${NC} ${message}" - echo "[$(date '+%Y-%m-%d %H:%M:%S')] INFO: $message" >> "${LOG_FILE}" 2>/dev/null || true + echo "[${timestamp}] INFO: $message" >> "${LOG_FILE}" 2>/dev/null || true } # Performance tracking functions diff --git a/backup-plex.sh b/backup-plex.sh index 4af5992..63e224e 100755 --- a/backup-plex.sh +++ b/backup-plex.sh @@ -105,35 +105,35 @@ log_message() { local message="$1" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "${CYAN}[${timestamp}]${NC} ${message}" - echo "[$(date '+%Y-%m-%d %H:%M:%S')] $message" >> "${LOG_ROOT}/plex-backup-$(date '+%Y-%m-%d').log" 2>/dev/null || true + echo "[${timestamp}] $message" >> "${LOG_ROOT}/plex-backup-$(date '+%Y-%m-%d').log" 2>/dev/null || true } log_error() { local message="$1" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "${RED}[${timestamp}] ERROR:${NC} ${message}" - echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: $message" >> "${LOG_ROOT}/plex-backup-$(date '+%Y-%m-%d').log" 2>/dev/null || true + echo "[${timestamp}] ERROR: $message" >> "${LOG_ROOT}/plex-backup-$(date '+%Y-%m-%d').log" 2>/dev/null || true } log_success() { local message="$1" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "${GREEN}[${timestamp}] SUCCESS:${NC} ${message}" - echo "[$(date '+%Y-%m-%d %H:%M:%S')] SUCCESS: $message" >> "${LOG_ROOT}/plex-backup-$(date '+%Y-%m-%d').log" 2>/dev/null || true + echo "[${timestamp}] SUCCESS: $message" >> "${LOG_ROOT}/plex-backup-$(date '+%Y-%m-%d').log" 2>/dev/null || true } log_warning() { local message="$1" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "${YELLOW}[${timestamp}] WARNING:${NC} ${message}" - echo "[$(date '+%Y-%m-%d %H:%M:%S')] WARNING: $message" >> "${LOG_ROOT}/plex-backup-$(date '+%Y-%m-%d').log" 2>/dev/null || true + echo "[${timestamp}] WARNING: $message" >> "${LOG_ROOT}/plex-backup-$(date '+%Y-%m-%d').log" 2>/dev/null || true } log_info() { local message="$1" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "${BLUE}[${timestamp}] INFO:${NC} ${message}" - echo "[$(date '+%Y-%m-%d %H:%M:%S')] INFO: $message" >> "${LOG_ROOT}/plex-backup-$(date '+%Y-%m-%d').log" 2>/dev/null || true + echo "[${timestamp}] INFO: $message" >> "${LOG_ROOT}/plex-backup-$(date '+%Y-%m-%d').log" 2>/dev/null || true } # Performance tracking functions diff --git a/setup/test-setup.sh b/setup/test-setup.sh index 999c287..65be382 100755 --- a/setup/test-setup.sh +++ b/setup/test-setup.sh @@ -17,7 +17,19 @@ MAX_INSTALL_ATTEMPTS=3 CURRENT_ATTEMPT=1 # Log file -# Create logs directory if it doesn't exist and is writable +# C log_both "\n${BLUE}Debugging lolcat package:${NC}" "Debugging lolcat package:" + if [ -f "/usr/games/lolcat" ]; then + log_both "- Lolcat found at /usr/games/lolcat" + ls -la /usr/games/lolcat >> "$LOG_FILE" + else + log_both "- Lolcat not found at /usr/games/lolcat" + fi + if check_command lolcat; then + log_both "- Lolcat found in PATH" + command -v lolcat >> "$LOG_FILE" + else + log_both "- Lolcat not found in PATH" + firectory if it doesn't exist and is writable # First, try creating the logs directory in case it doesn't exist if [ -d "/logs" ] || mkdir -p /logs 2>/dev/null; then if [ -w "/logs" ]; then @@ -52,6 +64,23 @@ echo "Starting setup test at $(date)" > "$LOG_FILE" || { echo "Starting setup test at $(date)" > "$LOG_FILE" } +# Helper function to log colored output to terminal and clean output to file +log_both() { + local colored_message="$1" + local clean_message="$2" + + # Display colored message to terminal + echo -e "$colored_message" + + # Log clean message to file + if [ -n "$clean_message" ]; then + echo "$clean_message" >> "$LOG_FILE" + else + # Strip ANSI escape codes for file logging + echo "$colored_message" | sed 's/\x1b\[[0-9;]*m//g' >> "$LOG_FILE" + fi +} + # Identify the system echo -e "${BLUE}=== System Information ===${NC}" if [ -f /etc/os-release ]; then @@ -423,18 +452,18 @@ while [ $CURRENT_ATTEMPT -le $MAX_INSTALL_ATTEMPTS ]; do ;; "cowsay") # Extra debugging for cowsay - echo -e "\n${BLUE}Debugging cowsay package:${NC}" | tee -a "$LOG_FILE" + log_both "\n${BLUE}Debugging cowsay package:${NC}" "Debugging cowsay package:" if [ -f "/usr/games/cowsay" ]; then - echo -e "- Cowsay found at /usr/games/cowsay" | tee -a "$LOG_FILE" - ls -la /usr/games/cowsay | tee -a "$LOG_FILE" + log_both "- Cowsay found at /usr/games/cowsay" + ls -la /usr/games/cowsay >> "$LOG_FILE" else - echo -e "- Cowsay not found at /usr/games/cowsay" | tee -a "$LOG_FILE" + log_both "- Cowsay not found at /usr/games/cowsay" fi if check_command cowsay; then - echo -e "- Cowsay found in PATH" | tee -a "$LOG_FILE" - command -v cowsay | tee -a "$LOG_FILE" + log_both "- Cowsay found in PATH" + command -v cowsay >> "$LOG_FILE" else - echo -e "- Cowsay not found in PATH" | tee -a "$LOG_FILE" + log_both "- Cowsay not found in PATH" fi if ! test_package "cowsay" "cowsay"; then diff --git a/validate-plex-backups.sh b/validate-plex-backups.sh index c7cbdf5..d4d479f 100755 --- a/validate-plex-backups.sh +++ b/validate-plex-backups.sh @@ -26,23 +26,34 @@ EXPECTED_FILES=( log_message() { local message="$1" - echo -e "$(date '+%H:%M:%S') $message" | tee -a "$REPORT_FILE" + local clean_message="$2" + + # Display colored message to terminal + echo -e "$(date '+%H:%M:%S') $message" + + # Strip ANSI codes and log clean version to file + if [ -n "$clean_message" ]; then + echo "$(date '+%H:%M:%S') $clean_message" >> "$REPORT_FILE" + else + # Strip ANSI escape codes for file logging + echo "$(date '+%H:%M:%S') $message" | sed 's/\x1b\[[0-9;]*m//g' >> "$REPORT_FILE" + fi } log_error() { - log_message "${RED}ERROR: $1${NC}" + log_message "${RED}ERROR: $1${NC}" "ERROR: $1" } log_success() { - log_message "${GREEN}SUCCESS: $1${NC}" + log_message "${GREEN}SUCCESS: $1${NC}" "SUCCESS: $1" } log_warning() { - log_message "${YELLOW}WARNING: $1${NC}" + log_message "${YELLOW}WARNING: $1${NC}" "WARNING: $1" } log_info() { - log_message "${BLUE}INFO: $1${NC}" + log_message "${BLUE}INFO: $1${NC}" "INFO: $1" } # Check backup directory structure