Files
DynastyRevolution-Scripts/modules/system-info
Asainte Bueno-Villanueva 16feb6955a
All checks were successful
Update Dispatches / refresh-news (push) Successful in 3s
add used memory to memory section
2026-02-08 00:03:22 -05:00

60 lines
2.1 KiB
Bash

#!/bin/bash
# -----------------------------------------------------------------------
# Dynasty Module: Universal Pulse (v1.1 Dual-Native UI)
# -----------------------------------------------------------------------
# --- 1. OS Detection & Metrics ---
if [[ "$OSTYPE" == "darwin"* ]]; then
OS="macOS"
# CPU: Get 1-minute load average
CPU_LOAD=$(sysctl -n vm.loadavg | awk '{print $2}')
# MEMORY: Mac math (Total - Free = Used)
MEM_TOTAL_GB=$(($(sysctl -n hw.memsize) / 1024 / 1024 / 1024))
PAGESIZE=$(pagesize)
PAGE_FREE=$(vm_stat | grep "Pages free" | awk '{print $3}' | sed 's/\.//')
MEM_FREE_GB=$((PAGE_FREE * PAGESIZE / 1024 / 1024 / 1024))
MEM_USED_GB=$((MEM_TOTAL_GB - MEM_FREE_GB))
# OTHER
UPTIME=$(uptime | sed -E 's/.*up ([^,]+),.*/\1/' | xargs)
DISK=$(df -h / | awk 'NR==2 {print $5}')
else
OS="Linux"
# CPU: Percentage of non-idle time
CPU_LOAD=$(top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4}')"%"
# MEMORY: Using free in Gigabytes
MEM_TOTAL_GB=$(free -g | awk '/^Mem:/{print $2}')
MEM_USED_GB=$(free -g | awk '/^Mem:/{print $3}')
# OTHER
UPTIME=$(uptime -p | sed 's/up //')
DISK=$(df -h / | awk 'NR==2 {print $5}')
fi
# --- 2. Build the Dashboard ---
# Using standard dashes to prevent Gitea encoding warnings
DASHBOARD="🐉 DYNASTY SYSTEM PULSE ($OS)
-------------------------------------
🕒 UPTIME: $UPTIME
🚀 CPU LOAD: $CPU_LOAD
🧠 MEMORY: ${MEM_USED_GB}GB / ${MEM_TOTAL_GB}GB
💾 DISK: $DISK Used
-------------------------------------"
# --- 3. Dual-Native Display ---
if [[ "$OS" == "macOS" ]]; then
# Native macOS Popup Window (Appears over all apps)
osascript -e "display dialog \"$DASHBOARD\" with title \"Dynasty Diagnostics\" buttons {\"Close\"} default button \"Close\"" >/dev/null 2>&1
else
# Native Linux Terminal Box (Whiptail with fallback)
if command -v whiptail >/dev/null 2>&1; then
whiptail --title "Dynasty Diagnostics" --msgbox "$DASHBOARD" 15 50
else
clear
echo -e "$DASHBOARD"
echo ""
read -p "Press Enter to return to Dynasty..." < /dev/tty
fi
fi