#!/bin/bash # BlackRoad OS - Time Machine Dashboard # Travel through your infrastructure's history source ~/blackroad-dashboards/themes.sh load_theme HISTORY_FILE=~/blackroad-dashboards/.time_machine_history CURRENT_TIME=$(date +%s) TIME_POSITION=$CURRENT_TIME PLAYBACK_SPEED=1 # Initialize history touch "$HISTORY_FILE" # Add historical events init_history() { if [ ! -s "$HISTORY_FILE" ]; then local now=$(date +%s) # Generate 30 days of history for ((i=30; i>=0; i--)); do local timestamp=$((now - i * 86400)) local cpu=$((30 + RANDOM % 40)) local memory=$((4 + RANDOM % 3)) local containers=$((20 + RANDOM % 8)) echo "$timestamp|cpu:$cpu|memory:${memory}.${RANDOM:0:1}|containers:$containers|deployments:$((RANDOM % 5))" >> "$HISTORY_FILE" done fi } # Format timestamp format_time() { local timestamp=$1 date -r "$timestamp" "+%Y-%m-%d %H:%M:%S" } # Get data at specific time get_historical_data() { local target_time=$1 # Find closest historical record local closest_line=$(awk -F'|' -v target="$target_time" ' BEGIN { min_diff=999999999; closest="" } { diff = ($1 > target) ? $1 - target : target - $1 if (diff < min_diff) { min_diff = diff closest = $0 } } END { print closest } ' "$HISTORY_FILE") echo "$closest_line" } # Show time machine dashboard show_time_machine() { clear echo "" echo -e "${BOLD}${GOLD}╔════════════════════════════════════════════════════════════════════════╗${RESET}" echo -e "${BOLD}${GOLD}║${RESET} ${PURPLE}⏰${RESET} ${BOLD}TIME MACHINE DASHBOARD${RESET} ${BOLD}${GOLD}║${RESET}" echo -e "${BOLD}${GOLD}╚════════════════════════════════════════════════════════════════════════╝${RESET}" echo "" local current_data=$(get_historical_data "$TIME_POSITION") local time_str=$(format_time "$TIME_POSITION") # Time indicator echo -e "${TEXT_MUTED}╭─ TIME TRAVEL ─────────────────────────────────────────────────────────╮${RESET}" echo "" local time_diff=$((CURRENT_TIME - TIME_POSITION)) local days_ago=$((time_diff / 86400)) if [ $days_ago -eq 0 ]; then echo -e " ${BOLD}${GREEN}◉ LIVE${RESET} ${CYAN}$time_str${RESET}" else echo -e " ${BOLD}${ORANGE}◉ $days_ago days ago${RESET} ${CYAN}$time_str${RESET}" fi echo "" # Timeline echo -e "${TEXT_MUTED}╭─ TIMELINE ────────────────────────────────────────────────────────────╮${RESET}" echo "" local total_days=30 local position_days=$(( (CURRENT_TIME - TIME_POSITION) / 86400 )) local bar_position=$((50 - position_days * 50 / total_days)) echo -n " ${TEXT_MUTED}30d ago${RESET} " for ((i=0; i<50; i++)); do if [ $i -eq $bar_position ]; then echo -n "${GOLD}◆${RESET}" else echo -n "${TEXT_MUTED}─${RESET}" fi done echo " ${GREEN}NOW${RESET}" echo "" # Historical metrics echo -e "${TEXT_MUTED}╭─ METRICS AT THIS TIME ────────────────────────────────────────────────╮${RESET}" echo "" if [ -n "$current_data" ]; then local cpu=$(echo "$current_data" | grep -o 'cpu:[0-9]*' | cut -d: -f2) local memory=$(echo "$current_data" | grep -o 'memory:[0-9.]*' | cut -d: -f2) local containers=$(echo "$current_data" | grep -o 'containers:[0-9]*' | cut -d: -f2) local deployments=$(echo "$current_data" | grep -o 'deployments:[0-9]*' | cut -d: -f2) echo -e " ${BOLD}${TEXT_PRIMARY}CPU Usage:${RESET}" echo -n " ${ORANGE}" for ((i=0; i