103 lines
2.9 KiB
Django/Jinja
103 lines
2.9 KiB
Django/Jinja
#!/bin/bash
|
|
|
|
# distribution information
|
|
if [ -f /etc/os-release ]; then
|
|
. /etc/os-release
|
|
if [ "$ID" = "ubuntu" ]; then
|
|
linux_distribution="\e[33m$PRETTY_NAME\e[0m"
|
|
elif [ "$ID" = "debian" ]; then
|
|
if [ -f /etc/pve/version ] || [ -f /usr/bin/pveversion ]; then
|
|
linux_distribution="\e[38;5;208mProxmox VE $(cat /etc/pve/version 2>/dev/null || pveversion 2>/dev/null | cut -d'/' -f2)\e[0m"
|
|
else
|
|
linux_distribution="\e[91m$PRETTY_NAME\e[0m"
|
|
fi
|
|
else
|
|
linux_distribution="\e[94m$NAME\e[0m"
|
|
fi
|
|
else
|
|
linux_distribution="\e[94mUnknown Linux Distribution\e[0m"
|
|
fi
|
|
|
|
# disk usage
|
|
disk_usage=$(df -h / | awk 'NR==2 {print $3 " / " $2 " (" $5 ")"}')
|
|
|
|
# memory usage
|
|
memory_usage=$(free -m | awk 'NR==2 {print $3 " MB / " $2 " MB (" int($3/$2*100) "%)"}')
|
|
|
|
# pending updates
|
|
pending_updates=$(apt list --upgradable 2>/dev/null | grep -c 'upgradable')
|
|
|
|
# proxmox information
|
|
proxmox_info=""
|
|
if [ -f /etc/pve/version ] || [ -f /usr/bin/pveversion ]; then
|
|
|
|
# get vms
|
|
if command -v qm >/dev/null 2>&1; then
|
|
running_vms=$(qm list 2>/dev/null | grep -c "running" || echo "0")
|
|
total_vms=$(qm list 2>/dev/null | tail -n +2 | wc -l || echo "0")
|
|
else
|
|
running_vms="0"
|
|
total_vms="0"
|
|
fi
|
|
|
|
# get lxcs
|
|
if command -v pct >/dev/null 2>&1; then
|
|
running_containers=$(pct list 2>/dev/null | grep -c "running" || echo "0")
|
|
total_containers=$(pct list 2>/dev/null | tail -n +2 | wc -l || echo "0")
|
|
else
|
|
running_containers="0"
|
|
total_containers="0"
|
|
fi
|
|
|
|
# get cluster status
|
|
cluster_status=""
|
|
if [ -f /etc/pve/corosync.conf ]; then
|
|
cluster_name=$(grep "cluster_name" /etc/pve/corosync.conf 2>/dev/null | awk '{print $2}' | tr -d '"' || echo "Unknown")
|
|
if command -v pvecm >/dev/null 2>&1; then
|
|
cluster_nodes=$(pvecm nodes 2>/dev/null | grep -c "^[[:space:]]*[0-9]" || echo "1")
|
|
cluster_status="Cluster: $cluster_name ($cluster_nodes nodes)"
|
|
fi
|
|
fi
|
|
|
|
# get storage
|
|
storage_usage=""
|
|
if command -v pvesm >/dev/null 2>&1; then
|
|
storage_usage=$(pvesm status 2>/dev/null | awk 'NR==2 {if($4>0) printf "%.1f%% of %.1fGB", ($5/$4)*100, $4/1024/1024}')
|
|
fi
|
|
|
|
proxmox_info="VMs: $running_vms/$total_vms running
|
|
LXC Containers: $running_containers/$total_containers running"
|
|
|
|
if [ -n "$cluster_status" ]; then
|
|
proxmox_info="$proxmox_info
|
|
$cluster_status"
|
|
fi
|
|
|
|
if [ -n "$storage_usage" ]; then
|
|
proxmox_info="$proxmox_info
|
|
Storage Usage: $storage_usage"
|
|
fi
|
|
fi
|
|
|
|
# display motd
|
|
echo "Welcome to $(hostname)!"
|
|
echo ""
|
|
echo -e "$linux_distribution"
|
|
echo "Disk Usage: $disk_usage"
|
|
echo "Memory Usage: $memory_usage"
|
|
|
|
# display proxmox info
|
|
if [ -n "$proxmox_info" ]; then
|
|
echo ""
|
|
echo -e "\e[38;5;208mProxmox Status:\e[0m"
|
|
echo "$proxmox_info"
|
|
fi
|
|
|
|
echo ""
|
|
if [ "$pending_updates" -eq 1 ]; then
|
|
echo "There is $pending_updates pending update."
|
|
elif [ "$pending_updates" -gt 1 ]; then
|
|
echo "There are $pending_updates pending updates."
|
|
else
|
|
echo "No pending updates."
|
|
fi
|