Files
DynastyRevolution-Scripts/modules/system-pulse

55 lines
2.1 KiB
Bash

#!/bin/bash
# DYNR Module: System Pulse
run_system_pulse() {
BLUE='\033[38;5;45m'; PURPLE='\033[38;5;127m'; GOLD='\033[38;5;178m'; NC='\033[0m'
# 1. Dependency Check
if ! command -v watch &> /dev/null; then
echo -e "${GOLD}Requirement Missing: 'watch' is needed for live mode.${NC}"
echo -e "Would you like to install 'procps'? (y/n)"
read -p "> " inst_proc
[[ "$inst_proc" == "y" ]] && sudo apt-get update && sudo apt-get install -y procps
fi
# 2. Mode Selection
echo -e "${BLUE}🐉 How would you like to read the Dynasty's Pulse?${NC}"
echo "1) One-time Snapshot"
echo "2) Live Readout (Updates every 2s)"
read -p "Selection [1-2]: " PULSE_MODE
# Function to generate the actual stats string
generate_stats() {
CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4}')
RAM_T=$(free -m | awk '/Mem:/ { print $2 }')
RAM_U=$(free -m | awk '/Mem:/ { print $3 }')
DISK=$(df -h / | awk 'NR==2 {print $5}')
UP=$(uptime -p)
echo -e "${PURPLE}=================================================${NC}"
echo -e "${BLUE} 🐉 DYNASTY REVOLUTION: SYSTEM PULSE 🐉 ${NC}"
echo -e "${PURPLE}=================================================${NC}"
echo -e "${GOLD}CPU LOAD: ${NC}${CPU}%"
echo -e "${GOLD}RAM USAGE: ${NC}${RAM_U}MB / ${RAM_T}MB"
echo -e "${GOLD}DISK USAGE: ${NC}${DISK}"
echo -e "${GOLD}UPTIME: ${NC}${UP}"
echo -e "${PURPLE}=================================================${NC}"
}
if [ "$PULSE_MODE" == "2" ]; then
echo -e "${BLUE}Entering Live Mode. Press Ctrl+C to exit...${NC}"
sleep 1
# Use watch to repeat the function.
# Note: export -f doesn't work well here, so we use a subshell trick or call a simple loop
while true; do
clear
generate_stats
echo -e "${BLUE}Refreshing... (Ctrl+C to Stop)${NC}"
sleep 2
done
else
clear
generate_stats
read -p "Press Enter to return to the Dynasty..."
fi
}