Last active
October 28, 2025 23:09
-
-
Save dorktoast/8c897a9c3396c4037082bff011d0de69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Busy Console emulator | |
| # by dorktoast | |
| # A script to make your linux terminal look active, busy, interesting, and cool. | |
| # Busy split-screen terminal with faux prompt and ANSI scrolling region. | |
| # Controls: | |
| # Tab -> prompt (pause logs) | |
| # \ -> prompt (keep logs running) | |
| # G -> output a block of garbage data | |
| # | |
| # Save as: busyconsole.sh | |
| # chmod +x busyconsole.sh | |
| # ./busyconsole.sh | |
| print_help() { | |
| cat <<EOF | |
| Usage: $(basename "$0") [OPTIONS] | |
| Simulates activity in a terminal. | |
| Options: | |
| --colorful Add additional colorful ANSI color codes. | |
| --no-color Strips all color in the output. | |
| --help Show this help message and exit. | |
| Controls during runtime: | |
| = Exit the program immediately. | |
| EOF | |
| } | |
| # Fail on unset vars; catch pipeline errors | |
| set -u | |
| set -o pipefail | |
| # Options | |
| COLOR_MODE=1 | |
| for arg in "$@"; do | |
| case "$arg" in | |
| --colorful ) | |
| COLOR_MODE=2 | |
| ;; | |
| --no-color ) | |
| COLOR_MODE=0 | |
| ;; | |
| --help|-h ) | |
| print_help | |
| exit 0 | |
| ;; | |
| * ) | |
| echo "Unknown argument: $arg" | |
| echo "Try: $(basename "$0") --help" | |
| exit 1 | |
| ;; | |
| esac | |
| done | |
| # Seed for randomness (useful for deterministic runs if wanted) | |
| RANDOM_SEED=${RANDOM_SEED:-$(date +%s)} | |
| ############################ | |
| # Globals / Config | |
| ############################ | |
| SERVICES=(nginx sshd postgresql redis kubelet containerd dnsmasq consul vault etcd traefik envoy haproxy) | |
| COMPONENTS=(scheduler worker authz authn jwtverifier sidecar ingress egress controller operator webhook) | |
| FILES=(/etc/passwd /etc/shadow /var/log/syslog /var/log/kern.log /var/lib/docker/overlay2 /etc/hosts \ | |
| /etc/ssl/certs/ca-certificates.crt /var/lib/containers/storage/overlay-containers/index.json) | |
| ACTIONS=(quarantined throttled isolated evicted restarted rescheduled cordoned drained) | |
| REASONS=(checksum_mismatch signature_invalid lease_timeout rate_limited dns_timeout tls_handshake \ | |
| mount_failure deadlock detected_loop oom_kill disk_pressure) | |
| REGISTRIES=(repo1.example.com registry.example.com artifacts.local mirror01.internal cdn.edge.net) | |
| TAILACTIONS=( | |
| "installing" "downloading" "unpacking" "extracting" "configuring" "compiling" | |
| "linking" "staging" "verifying" "signing" "scanning" "patching" "optimizing" | |
| "pruning" "migrating" "seeding" "hydrating cache" "warming cache" "draining queue" | |
| "rebalancing shards" "updating schema" "rolling restart" "generating manifests" | |
| "resolving deps" "pinning versions" "garbage collecting" | |
| ) | |
| PKGS=(coreutils openssl curl systemd glibc zlib sqlite3 libuv ca-certificates tzdata iproute2 iptables procps-ng | |
| bash-completion python3 libffi libssl ncurses util-linux llvm clang make cmake pkg-config jq) | |
| if [ "$COLOR_MODE" = 2 ]; then | |
| COLORS=('1;31m' '1;32m' '1;33m' '1;34m' '1;35m' '1;36m') | |
| else | |
| COLORS=("") # no escape codes | |
| fi | |
| USER_NAME="${USER:-toast}" | |
| HOST="${HOSTNAME:-needland}" | |
| PAUSED=0 # read by noise() via traps | |
| LOG_BOTTOM=0 # last row of the log region (rows-1) | |
| COLS=0 # terminal width (updated on resize) | |
| BAR_WIDTH=60 # will be recalculated from COLS | |
| NOISE_PID= # background PID | |
| ## Help Command | |
| ############################ | |
| # Terminal helpers | |
| ############################ | |
| c() { # SGR/color helper | |
| if [ "$COLOR_MODE" != 0 ]; then | |
| printf '\033[%b' "$1" | |
| else | |
| printf "" | |
| fi | |
| } | |
| csr() { printf '\033[%d;%dH' "$1" "$2"; } # move cursor (row, col) | |
| clear_full() { printf '\033[2J\033[H'; } # clear + home | |
| set_region() { printf '\033[%d;%dr' "$1" "$2"; } # DECSTBM (top;bottom) scroll region | |
| save_cursor() { printf '\0337'; } # save cursor | |
| restore_cursor() { printf '\0338'; } # restore cursor | |
| reset_tty() { | |
| printf '\033[0m' | |
| set_region 1 "$(tput lines 2>/dev/null || echo 24)" | |
| stty sane 2>/dev/null || true | |
| } | |
| die() { reset_tty; exit "${1:-0}"; } | |
| trap 'die 0' EXIT | |
| trap 'die 130' INT TERM | |
| update_geometry() { | |
| local rows cols | |
| rows="$(tput lines 2>/dev/null || echo 24)" | |
| cols="$(tput cols 2>/dev/null || echo 80)" | |
| COLS=$cols | |
| LOG_BOTTOM=$((rows-1)) | |
| BAR_WIDTH=$(( cols>18 ? cols-18 : 60 )) | |
| set_region 1 "$LOG_BOTTOM" # top pane scrolls | |
| # footer / status line | |
| save_cursor | |
| csr $((LOG_BOTTOM+1)) 1 | |
| printf '\033[0m\033[2K' | |
| printf -- '-- Faux Shell Ready -- Tab: prompt (pause logs) | \\: prompt (keep logs) ' | |
| restore_cursor | |
| } | |
| trap 'update_geometry' WINCH | |
| ############################ | |
| # Random helpers | |
| ############################ | |
| ts() { date +"%H:%M:%S"; } | |
| randf() { awk -v m="$1" -v M="$2" 'BEGIN{srand(); printf "%.2f\n", m+rand()*(M-m)}'; } | |
| rand_from() { # rand_from item1 item2 ... | |
| local a=("$@"); printf '%s' "${a[RANDOM%${#a[@]}]}" | |
| } | |
| rand_int() { awk -v a="$1" -v b="$2" 'BEGIN{srand();printf "%d\n", a+int(rand()*(b-a+1))}'; } | |
| gen_ip() { printf '10.%d.%d.%d' "$(rand_int 0 255)" "$(rand_int 0 255)" "$(rand_int 10 220)"; } | |
| gen_port() { printf '%d' "$(rand_int 20 65535)"; } | |
| gen_pid() { printf '%d' "$(rand_int 100 65000)"; } | |
| gen_hex() { tr -dc 'a-f0-9' </dev/urandom | head -c 8; } | |
| gen_cve() { printf 'CVE-%d-%04d' "$(rand_int 2016 2025)" "$(rand_int 1 9999)"; } | |
| gen_stacktrace() { | |
| # prints multiple log_line entries; caller controls color | |
| local svc=$(rand_from "${SERVICES[@]}") | |
| local hex=$(gen_hex) | |
| log_line "$(ts) x $svc crashed: panic: runtime exception (signal 11)" | |
| log_line " at /opt/$svc/main.go:$(rand_int 10 200) → goroutine $(rand_int 1 200)" | |
| log_line " at /opt/$svc/router.go:$(rand_int 10 200)" | |
| log_line " at /opt/$svc/db.go:$(rand_int 10 200)" | |
| log_line " error-id=$hex" | |
| } | |
| gen_json_event() { | |
| # prints JSON-ish multi-line event | |
| local svc=$(rand_from "${SERVICES[@]}") | |
| local comp=$(rand_from "${COMPONENTS[@]}") | |
| local pid=$(gen_pid) | |
| local ip=$(gen_ip) | |
| local port=$(gen_port) | |
| local ev=$(rand_from "ACCEPT" "DENY" "DROP" "QUARANTINE") | |
| log_line "$(ts) i event: {" | |
| log_line " \"service\": \"$svc\"," | |
| log_line " \"component\": \"$comp\"," | |
| log_line " \"pid\": $pid," | |
| log_line " \"src\": \"$ip:$port\"," | |
| log_line " \"action\": \"$ev\"" | |
| log_line " }" | |
| } | |
| human_size() { # e.g., 312KB, 4.7MB, 1.2GB | |
| local n unit; n=$(awk 'BEGIN{srand(); printf "%.2f\n", 0.05 + rand()*9000}') | |
| if awk -v v="$n" 'BEGIN{exit !(v<1)}'; then | |
| printf '%dKB' "$(awk -v v="$n" 'BEGIN{printf "%d\n", v*1024}')" | |
| elif awk -v v="$n" 'BEGIN{exit !(v<1024)}'; then | |
| printf '%.1fMB' "$n" | |
| else | |
| printf '%.1fGB' "$(awk -v v="$n" 'BEGIN{printf "%.1f\n", v/1024}')" | |
| fi | |
| } | |
| detail_tail() { | |
| # Randomized parenthetical details to make lines look richer | |
| case $((RANDOM%8)) in | |
| 0) printf '(v%s)' "$1" ;; # version | |
| 1) printf '(sha256:%s)' "$(tr -dc 'a-f0-9' </dev/urandom | head -c 12)" ;; | |
| 2) printf '(delta %s)' "$(human_size)" ;; | |
| 3) printf '(cached=%s)' "$(rand_from yes no)" ;; | |
| 4) printf '(took %dms)' $((50+RANDOM%1200)) ;; | |
| 5) printf '(signature=%s)' "$(rand_from valid expired revoked unknown)" ;; | |
| 6) printf '(mirror=%s)' "$(rand_from repo1 mirror cdn registry updates)" ;; | |
| 7) printf '(inode=%d)' $((10000+RANDOM%900000)) ;; | |
| esac | |
| } | |
| ############################ | |
| # Log printing (top region) | |
| ############################ | |
| log_line() { | |
| # Commit a line into the log (scrolls inside top region) | |
| save_cursor | |
| csr "$LOG_BOTTOM" 1 | |
| printf '%s\n' "$1" | |
| restore_cursor | |
| } | |
| # Transient status line (no newline): used for spinners/bars | |
| log_status() { | |
| save_cursor | |
| csr "$LOG_BOTTOM" 1 | |
| printf '\033[2K%s' "$1" | |
| restore_cursor | |
| } | |
| log_status_c() { | |
| local fg="$1"; shift | |
| c "$fg"; log_status "$*"; c '0m' | |
| } | |
| ############################ | |
| # Visual effects | |
| ############################ | |
| progress_bar_line() { | |
| local pct="$1" fg="$2" w fill hashes spaces | |
| w=$BAR_WIDTH; (( w<10 )) && w=10 | |
| fill=$(( pct*w/100 )) | |
| hashes=$(printf '%*s' "$fill" '' | tr ' ' '#') | |
| spaces=$(printf '%*s' "$((w-fill))" '' | tr ' ' ' ') | |
| log_status_c "$fg" "[$hashes$spaces] $(printf '%3d' "$pct")%%" | |
| } | |
| bar_sequence() { | |
| local fg="$1" | |
| # ---------- Tunables ---------- | |
| local steps=30 # smoothness (higher = smoother) | |
| local min_total=0.8 max_total=4.5 # total animation window in seconds (pre-events) | |
| local p_rollback=25 # % chance of rollback event | |
| local p_midspin=30 # % chance of a mid-progress spinner | |
| local p_fastfwd=12 # % chance to jump to 100% after >=60% | |
| local rollback_amt_min=10 rollback_amt_max=35 # rollback size in % | |
| # -------------------------------- | |
| # Random total duration; per-step sleep derived from it | |
| local total_duration | |
| total_duration=$(awk -v a="$min_total" -v b="$max_total" 'BEGIN{srand(); printf "%.2f\n", a + rand()*(b-a)}') | |
| local step_sleep | |
| step_sleep=$(awk -v t="$total_duration" -v n="$steps" 'BEGIN{printf "%.3f\n", t/n}') | |
| # Event flags and trigger points | |
| local do_rollback=0 do_midspin=0 do_fastfwd=0 | |
| (( RANDOM%100 < p_rollback )) && do_rollback=1 | |
| (( RANDOM%100 < p_midspin )) && do_midspin=1 | |
| (( RANDOM%100 < p_fastfwd )) && do_fastfwd=1 | |
| # Choose random trigger steps (expressed as step indices) | |
| local trig_rollback=$(( 5 + RANDOM % (steps-10) )) # avoid edges | |
| local trig_midspin=$(( 8 + RANDOM % (steps-16) )) | |
| local trig_fastfwd=$(( steps*60/100 + RANDOM % (steps - steps*60/100) )) # somewhere >=60% | |
| local rollback_done=0 midspin_done=0 fastfwd_done=0 | |
| # Optional spinner labels to add variety | |
| local spin_labels=("validating chunks" "re-indexing blocks" "merging delta" "optimizing tables" "compacting segments") | |
| # Drive the bar | |
| local s=0 pct | |
| while (( s <= steps )); do | |
| (( PAUSED==1 )) && { sleep 0.05; continue; } | |
| pct=$(( s*100/steps )) | |
| progress_bar_line "$pct" "$fg" | |
| # --- Fast-forward event (>=60%) --- | |
| if (( do_fastfwd==1 && fastfwd_done==0 && s >= trig_fastfwd )); then | |
| c "$fg"; log_line "$(ts) i cache restored — fast-forwarding"; c '0m' | |
| s=$steps | |
| # show final bar state one last time before commit | |
| pct=100 | |
| progress_bar_line "$pct" "$fg" | |
| break | |
| fi | |
| # --- Mid-progress spinner (short) --- | |
| if (( do_midspin==1 && midspin_done==0 && s == trig_midspin )); then | |
| # small transient spinner, then continue | |
| local lbl="${spin_labels[RANDOM%${#spin_labels[@]}]}" | |
| spinner_task "$lbl" $(( 1 + RANDOM % 2 )) "$fg" # 1–2 seconds | |
| midspin_done=1 | |
| fi | |
| # --- Rollback event --- | |
| if (( do_rollback==1 && rollback_done==0 && s == trig_rollback )); then | |
| local back=$(( rollback_amt_min + RANDOM % (rollback_amt_max - rollback_amt_min + 1) )) | |
| c "$fg"; log_line "$(ts) ! rollback detected — reverting ${back}%%"; c '0m' | |
| # convert % back to steps; ensure non-negative | |
| local back_steps=$(( back*steps/100 )) | |
| (( back_steps<1 )) && back_steps=1 | |
| s=$(( s - back_steps )) | |
| (( s<0 )) && s=0 | |
| rollback_done=1 | |
| # redraw the bar at the rolled-back position | |
| pct=$(( s*100/steps )) | |
| progress_bar_line "$pct" "$fg" | |
| fi | |
| # advance and sleep | |
| (( s++ )) | |
| sleep "$step_sleep" | |
| done | |
| # Commit final bar as a real log line | |
| c "$fg"; log_line "[$(printf '%*s' "$BAR_WIDTH" '' | tr ' ' '#')] 100%"; c '0m' | |
| } | |
| spinner_task() { | |
| local label="$1" secs="$2" fg="$3" | |
| local chars='|/-\\' i=0 end=$((SECONDS+secs)) | |
| while (( SECONDS < end )); do | |
| log_status_c "$fg" "$(printf '%s [%c]' "$label" "${chars:i++%4:1}")" | |
| sleep 0.12 | |
| done | |
| log_line "$label [done]" | |
| } | |
| print_activity_line() { | |
| # args: color pkg ver | |
| local fg="$1" pkg="$2" ver="$3" | |
| local verb="${TAILACTIONS[RANDOM%${#ACTIONS[@]}]}" | |
| local padded; padded=$(printf '%-18s' "$pkg") | |
| # 60% chance to append a detail tail | |
| local tail="" | |
| if (( RANDOM%100 < 60 )); then tail=" $(detail_tail "$ver")"; fi | |
| c "$fg"; log_line "$(ts) · ${verb} ${padded} (${ver})${tail}"; c '0m' | |
| } | |
| fake_checksum() { | |
| local fg="$1" | |
| log_status_c "$fg" "$(ts) · verifying checksums..." | |
| sleep 0.20 | |
| log_line "$(ts) · verifying checksums... ok" | |
| } | |
| fake_network() { | |
| local fg="$1" h ip | |
| local hosts=(repo1 mirror cdn registry updates keys index) | |
| h="${hosts[RANDOM%${#hosts[@]}]}" | |
| ip=$(printf '10.%d.%d.%d' $((RANDOM%256)) $((RANDOM%256)) $((10+RANDOM%200))) | |
| c "$fg"; log_line "$(ts) · connecting to ${h}.example.com (${ip}):443 ... connected"; c '0m' | |
| } | |
| fake_warn_or_info() { | |
| local mood=$((RANDOM%14)) # expanded range (previously 0..9) | |
| local fg_warn='1;33m' # yellow | |
| local fg_err='1;31m' # red | |
| local fg_info='1;36m' # cyan | |
| local fg_note='1;35m' # magenta | |
| case "$mood" in | |
| # ─── existing single-line WARN/INFO/ERROR cases ───────────────────────────── | |
| 0|1) | |
| c "$fg_warn"; log_line "$(ts) ! $(rand_from "${SERVICES[@]}")/$(rand_from "${COMPONENTS[@]}"): $(rand_from "${REASONS[@]}") on pid=$(gen_pid) host=$(gen_ip)"; c '0m' | |
| ;; | |
| 2) | |
| c "$fg_warn"; log_line "$(ts) ! policy: $(rand_from enforce audit permissive) — $(rand_from access_denied access_granted) on $(rand_from "${FILES[@]}")"; c '0m' | |
| ;; | |
| 3) | |
| c "$fg_err"; log_line "$(ts) x $(rand_from "${SERVICES[@]}") failed: $(rand_from handshake_failed backoff_exceeded lock_contention txn_abort) (code=$(rand_int 1 255))"; c '0m' | |
| ;; | |
| 4) | |
| c "$fg_err"; log_line "$(ts) x scanner: potential $(gen_cve) in $(rand_from "${SERVICES[@]}")@$(gen_hex) (confidence=$(rand_int 41 93)%%)"; c '0m' | |
| ;; | |
| 5) | |
| c "$fg_info"; log_line "$(ts) i pulling image: $(rand_from "${REGISTRIES[@]}")/$(rand_from "${SERVICES[@]}")@sha256:$(tr -dc 'a-f0-9' </dev/urandom | head -c 12) (cached=$(rand_from yes no))"; c '0m' | |
| ;; | |
| 6) | |
| c "$fg_info"; log_line "$(ts) i autoscaler: $(rand_from scaled_up scaled_down rebalanced) $(rand_int 1 6) replicas for $(rand_from "${SERVICES[@]}")"; c '0m' | |
| ;; | |
| 7) | |
| c "$fg_note"; log_line "$(ts) · node $(gen_ip): cpu=$(rand_int 1 97)%% mem=$(rand_int 8 98)%% io=$(rand_int 0 100)%% net=$(rand_int 10 900)Mbps"; c '0m' | |
| ;; | |
| 8) | |
| c "$fg_warn"; log_line "$(ts) ! $(rand_from "${FILES[@]}") $(rand_from locked rotated truncated quarantined) (reason=$(rand_from "${REASONS[@]}"))"; c '0m' | |
| ;; | |
| 9) | |
| c "$fg_info"; log_line "$(ts) i connection $(gen_ip):$(gen_port) → $(gen_ip):443 via $(rand_from tls12 tls13 h2 alpn) RTT=$(randf 2 90)ms"; c '0m' | |
| ;; | |
| # ─── NEW: multi-line “stack trace” ────────────────────────────────────────── | |
| 10) | |
| c "$fg_err" | |
| gen_stacktrace | |
| c '0m' | |
| ;; | |
| # ─── NEW: multi-line structured JSON event ───────────────────────────────── | |
| 11) | |
| c "$fg_info" | |
| gen_json_event | |
| c '0m' | |
| ;; | |
| # ─── NEW: weird “kernel message” flavor ──────────────────────────────────── | |
| 12) | |
| c "$fg_warn" | |
| log_line "$(ts) ! kernel: soft lockup — CPU$(rand_int 0 7) stuck for $(rand_int 3 12)s [$(rand_from "${SERVICES[@]}"):$(gen_pid)]" | |
| log_line " watchdog: attempting forced thread migration" | |
| c '0m' | |
| ;; | |
| # ─── NEW: sudden red-flag outage message ─────────────────────────────────── | |
| 13) | |
| c "$fg_err" | |
| log_line "$(ts) x cluster state inconsistent: quorum lost (leader=$(gen_ip))" | |
| log_line " attempting emergency leader election…" | |
| log_line " result: $(rand_from success failure timed_out)" | |
| c '0m' | |
| ;; | |
| esac | |
| } | |
| ############################ | |
| # Background noise (top pane) | |
| ############################ | |
| noise() { | |
| # Explicit control signals | |
| trap 'PAUSED=1' USR1 # pause | |
| trap 'PAUSED=0' HUP # resume | |
| trap 'update_geometry' WINCH | |
| while :; do | |
| (( PAUSED==1 )) && { sleep 0.05; continue; } | |
| local fg="${COLORS[$RANDOM%${#COLORS[@]}]}" | |
| fake_network "$fg" | |
| local burst=$((3+RANDOM%6)) j | |
| for ((j=0;j<burst;j++)); do | |
| (( PAUSED==1 )) && break | |
| local pkg="${PKGS[$RANDOM%${#PKGS[@]}]}" | |
| local ver="$((1+RANDOM%3)).$((RANDOM%10)).$((RANDOM%20))" | |
| print_activity_line "$fg" "$pkg" "$ver" | |
| sleep 0.05 | |
| done | |
| (( PAUSED==1 )) || fake_checksum "$fg" | |
| (( PAUSED==1 )) || bar_sequence "$fg" | |
| (( PAUSED==1 )) || spinner_task "syncing package index" $((1+RANDOM%2)) "$fg" | |
| (( PAUSED==1 )) || spinner_task "linking shared objects" $((1+RANDOM%2)) "$fg" | |
| (( PAUSED==1 )) || fake_warn_or_info | |
| if (( RANDOM%3==0 )); then | |
| c "$fg" | |
| local mod; mod=$(tr -dc 'a-z' </dev/urandom | head -c 6) | |
| log_line "$(ts) · compiling module ${mod}.c ... ok" | |
| c '0m' | |
| fi | |
| # Occasionally emit a garbage block (skip if paused) | |
| if (( PAUSED==0 )) && (( RANDOM%100 < 15 )); then # ~15% chance per cycle | |
| emit_garbage_block | |
| fi | |
| sleep 0.05 | |
| done | |
| } | |
| ## Garbage Block generators (multi-line noise) | |
| # bounded printable junk | |
| _gen_printable_line() { | |
| tr -dc 'A-Za-z0-9+/=._-:@#[]{}()<>!$%^&*~ ' </dev/urandom | head -c "$1" | |
| } | |
| gen_garbage_hexdump() { | |
| local lines=$((8 + RANDOM%16)) i | |
| local off=0 | |
| for ((i=0;i<lines;i++)); do | |
| # 16 bytes per line, 00-ff pairs (fake—doesn't matter) | |
| local bytes; bytes=$(od -An -t x1 -N 16 </dev/urandom 2>/dev/null | sed 's/^ *//;s/ */ /g') | |
| local ascii; ascii=$(_gen_printable_line 16) | |
| log_line "$(printf '%08x %s |%s|' "$off" "$bytes" "$ascii")" | |
| off=$((off+16)) | |
| done | |
| } | |
| gen_garbage_base64() { | |
| local lines=$((6 + RANDOM%10)) i | |
| for ((i=0;i<lines;i++)); do | |
| log_line "$(_gen_printable_line $((64 + RANDOM%16)))" | |
| done | |
| } | |
| gen_garbage_memmap() { | |
| local rows=$((6 + RANDOM%8)) i | |
| for ((i=0;i<rows;i++)); do | |
| local start=$((0x400000 + (RANDOM%0x100000))) | |
| local end=$((start + (0x1000 * (1 + RANDOM%8)))) | |
| local perm=$(printf '%s' "$(tr -dc 'rwxp-' </dev/urandom | head -c 4)") | |
| local inode=$((10000 + RANDOM%900000)) | |
| local name=$(rand_from "[anon]" "[stack]" "[heap]" "/usr/lib/libc.so.6" "/usr/bin/bash" "/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2") | |
| printf -v line "%016x-%016x %s %08x %02x:%02x %-9d %s" "$start" "$end" "$perm" $((RANDOM%0xffffffff)) $((RANDOM%256)) $((RANDOM%256)) "$inode" "$name" | |
| log_line "$line" | |
| done | |
| } | |
| gen_garbage_json() { | |
| local items=$((4 + RANDOM%6)) i | |
| log_line "{" | |
| for ((i=1;i<=items;i++)); do | |
| local k; k=$(tr -dc 'a-z' </dev/urandom | head -c $((4+RANDOM%6))) | |
| local v; v=$(tr -dc 'a-f0-9' </dev/urandom | head -c 8) | |
| local n=$((RANDOM%1000)) | |
| local b=$(rand_from true false) | |
| log_line " \"${k}\": { \"id\": \"${v}\", \"n\": ${n}, \"ok\": ${b} }," | |
| done | |
| log_line " \"summary\": \"$(tr -dc 'A-Za-z ' </dev/urandom | head -c 24)\"" | |
| log_line "}" | |
| } | |
| gen_garbage_sql() { | |
| log_line "EXPLAIN ANALYZE SELECT * FROM events WHERE tenant_id=$(rand_int 1 999) AND hash='$(gen_hex)' LIMIT 100;" | |
| log_line "Seq Scan on events (cost=$(rand_int 1 200).$(rand_int 0 99)..$(rand_int 201 1200).$(rand_int 0 99) rows=$(rand_int 100 50000) width=$(rand_int 64 512))" | |
| log_line "Filter: (tenant_id = $(rand_int 1 999) AND hash = '$(gen_hex)')" | |
| log_line "Rows Removed by Filter: $(rand_int 0 500000)" | |
| log_line "Planning Time: $(randf 0.1 3.5) ms" | |
| log_line "Execution Time: $(randf 1.2 98.7) ms" | |
| } | |
| emit_garbage_block() { | |
| # choose one style at random | |
| case $((RANDOM%5)) in | |
| 0) log_line "$(ts) i dump: hexdump"; gen_garbage_hexdump ;; | |
| 1) log_line "$(ts) i dump: base64"; gen_garbage_base64 ;; | |
| 2) log_line "$(ts) i dump: memory map"; gen_garbage_memmap ;; | |
| 3) log_line "$(ts) i dump: json event"; gen_garbage_json ;; | |
| 4) log_line "$(ts) i dump: query plan"; gen_garbage_sql ;; | |
| esac | |
| } | |
| ############################ | |
| # Faux prompt (bottom line) | |
| ############################ | |
| status_line() { | |
| save_cursor | |
| csr $((LOG_BOTTOM+1)) 1 | |
| printf '\033[2K' # clear | |
| printf '%s@%s:~$ ' "$USER_NAME" "$HOST" | |
| restore_cursor | |
| } | |
| fake_command_response() { | |
| local cmd="$1" | |
| case "$cmd" in | |
| '' ) ;; | |
| exit|quit ) log_line "-- session closed --"; die 0 ;; | |
| clear ) clear_full; update_geometry ;; | |
| ls* ) log_line 'docs downloads src bin etc var tmp .cache .config' ;; | |
| pwd ) log_line "/home/$USER_NAME" ;; | |
| whoami ) log_line "$USER_NAME" ;; | |
| uname* ) log_line "Linux $HOST 6.$((RANDOM%10)).$((RANDOM%20)) #1 SMP PREEMPT x86_64 GNU/Linux" ;; | |
| top*|htop* ) | |
| log_line "top - $(date +%H:%M:%S) up 3 days, 4 users, load average: 1.42, 0.97, 0.78" | |
| log_line "Tasks: 230 total, 1 running, 229 sleeping, 0 stopped, 0 zombie" | |
| log_line "%Cpu(s): 17.6 us, 3.2 sy, 0.1 wa, 79.0 id" | |
| log_line " PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND" | |
| log_line " 1234 $USER_NAME 20 0 834520 76228 52840 S 9.3 1.0 0:14.59 busy.sh" | |
| ;; | |
| ping* ) | |
| local host arg2 | |
| arg2=$(awk '{print $2}' <<<"${cmd}") | |
| host="${arg2:-8.8.8.8}" | |
| log_line "PING $host ($host) 56(84) bytes of data." | |
| for i in {1..4}; do | |
| log_line "$(printf '64 bytes from %s: icmp_seq=%d ttl=57 time=%.2f ms' "$host" "$i" "$(randf 5 25)")" | |
| done | |
| log_line "--- $host ping statistics ---" | |
| log_line "4 packets transmitted, 4 received, 0% packet loss" | |
| ;; | |
| nmap* ) | |
| log_line "Starting Nmap 7.93 ( https://nmap.org ) at $(date)" | |
| log_line "Nmap scan report for localhost (127.0.0.1)" | |
| log_line "PORT STATE SERVICE" | |
| log_line "22/tcp open ssh" | |
| log_line "80/tcp open http" | |
| log_line "443/tcp open https" | |
| ;; | |
| * ) | |
| log_line "bash: $(awk '{print $1}' <<<"$cmd"): command not found" | |
| ;; | |
| esac | |
| } | |
| read_prompt_line() { | |
| # Read with line editing; echo only on bottom line | |
| local line | |
| csr $((LOG_BOTTOM+1)) 1 | |
| printf '\033[2K' | |
| # temporarily cooked for this read | |
| stty echo icanon icrnl -inlcr -igncr min 1 time 0 2>/dev/null || true | |
| read -er -p "${USER_NAME}@${HOST}:~$ " line | |
| # back to raw-ish | |
| stty -echo -icanon -icrnl -inlcr -igncr min 0 time 1 2>/dev/null || true | |
| printf '\r\033[2K' | |
| fake_command_response "$line" | |
| } | |
| ## Cleanup on exit | |
| cleanup() { | |
| # restore terminal state: show cursor, reset color and regions | |
| # restore cursor and attributes if helper functions exist | |
| tput cnorm 2>/dev/null || printf '\033[?25h' # show cursor | |
| tput sgr0 2>/dev/null || printf '\033[0m' # reset attributes | |
| # if you set alternate screen or region, attempt to disable it: | |
| printf '\033[?47l' 2>/dev/null || true | |
| # Move cursor to a fresh line so prompt returns nicely | |
| printf '\n' | |
| } | |
| # ensure cleanup runs on normal exit and signals | |
| trap cleanup EXIT INT TERM HUP | |
| ############################ | |
| # Key watcher & main | |
| ############################ | |
| #arguments | |
| for arg in "$@"; do | |
| case "$arg" in | |
| --no-color ) | |
| USE_COLOR=false | |
| ;; | |
| esac | |
| done | |
| main() { | |
| clear_full | |
| update_geometry | |
| # Start background noise | |
| noise & NOISE_PID=$! | |
| # Open controlling TTY for key reads | |
| exec 3</dev/tty | |
| # Raw-ish, nonblocking input (affects the TTY) | |
| stty -echo -icanon -icrnl -inlcr -igncr min 0 time 1 2>/dev/null || true | |
| status_line | |
| while :; do | |
| IFS= read -r -n 1 -t 0.1 -u 3 key | |
| case "${key-}" in | |
| $'\t' ) # Tab: pause logs, prompt, resume | |
| kill -USR1 "$NOISE_PID" 2>/dev/null || true | |
| sleep 0.02 | |
| read_prompt_line | |
| while IFS= read -r -n 1 -t 0 -u 3 _ch; do :; done | |
| kill -HUP "$NOISE_PID" 2>/dev/null || true | |
| status_line | |
| ;; | |
| "\\" ) # Backslash: prompt without pausing | |
| read_prompt_line | |
| status_line | |
| ;; | |
| [Gg] ) # NEW: emit a garbage block on demand | |
| emit_garbage_block | |
| status_line | |
| ;; | |
| "" ) sleep 0.05 ;; | |
| * ) sleep 0.01 ;; | |
| esac | |
| done | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment