feat: add proxmox to motd
This commit is contained in:
parent
abb854ebee
commit
b41fa3bdaa
1 changed files with 72 additions and 11 deletions
|
|
@ -2,16 +2,20 @@
|
||||||
|
|
||||||
# distribution information
|
# distribution information
|
||||||
if [ -f /etc/os-release ]; then
|
if [ -f /etc/os-release ]; then
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
if [ "$ID" = "ubuntu" ]; then
|
if [ "$ID" = "ubuntu" ]; then
|
||||||
linux_distribution="\e[33m$PRETTY_NAME\e[0m"
|
linux_distribution="\e[33m$PRETTY_NAME\e[0m"
|
||||||
elif [ "$ID" = "debian" ]; then
|
elif [ "$ID" = "debian" ]; then
|
||||||
linux_distribution="\e[91m$PRETTY_NAME\e[0m"
|
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
|
else
|
||||||
linux_distribution="\e[94m$NAME\e[0m"
|
linux_distribution="\e[91m$PRETTY_NAME\e[0m"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
linux_distribution="\e[94m$NAME\e[0m"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
linux_distribution="\e[94mUnknown Linux Distribution\e[0m"
|
linux_distribution="\e[94mUnknown Linux Distribution\e[0m"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# disk usage
|
# disk usage
|
||||||
|
|
@ -23,20 +27,77 @@ memory_usage=$(free -m | awk 'NR==2 {print $3 " MB / " $2 " MB (" int($3/$2*100)
|
||||||
# pending updates
|
# pending updates
|
||||||
pending_updates=$(apt list --upgradable 2>/dev/null | grep -c 'upgradable')
|
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
|
# display motd
|
||||||
echo "Welcome to $(hostname)!"
|
echo "Welcome to $(hostname)!"
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "$linux_distribution"
|
echo -e "$linux_distribution"
|
||||||
echo "Disk Usage: $disk_usage"
|
echo "Disk Usage: $disk_usage"
|
||||||
echo "Memory Usage: $memory_usage"
|
echo "Memory Usage: $memory_usage"
|
||||||
echo ""
|
|
||||||
|
|
||||||
|
# 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
|
if [ "$pending_updates" -eq 1 ]; then
|
||||||
echo "There is $pending_updates pending update."
|
echo "There is $pending_updates pending update."
|
||||||
|
|
||||||
elif [ "$pending_updates" -gt 1 ]; then
|
elif [ "$pending_updates" -gt 1 ]; then
|
||||||
echo "There are $pending_updates pendinging updates."
|
echo "There are $pending_updates pending updates."
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "No pending updates."
|
echo "No pending updates."
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue