Files
driveAtlas/driveAtlas.sh
2025-02-21 20:41:24 -05:00

197 lines
10 KiB
Bash

#!/bin/bash
# Define the ASCII art maps
large1='''
┌─────────────────────────────────────────────────────────────┐
│ large1 │
│ │
│ ┌──────────────────────────────────────────────┐ │
│ │ Motherboard │ │
│ │ │ │
│ │ ┌──┐┌──┐ │ │
│ │ │M1││M2│ │ │
│ │ └──┘└──┘ │ │
│ └──────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ │ │ │ │ │ │
│ │ 1 │ │ 2 │ │ 3 │ │
│ │ │ │ │ │ │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ │ │ │ │ │ │
│ │ 4 │ │ 5 │ │ 6 │ │
│ │ │ │ │ │ │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ │ │ │ │ │ │
│ │ 7 │ │ 8 │ │ 9 │ │
│ │ │ │ │ │ │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────┘
'''
medium1='''
┌─────────────────────────────────────────────────────────────┐
│ │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ 1 │ │ 2 │ │ 3 │ │ 4 │ │
│ └────────────┘ └────────────┘ └────────────┘ └────────────┘ │
│ │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ 5 │ │ 6 │ │ 7 │ │ 8 │ │
│ └────────────┘ └────────────┘ └────────────┘ └────────────┘ │
│ │
│ │
│ │
│ ┌─────────┐ │
│ medium1 │ 9 │ │
│ └─────────┘ │
│ ┌─────────┐ │
│ │ 10 │ │
│ └─────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
'''
medium2='''
┌──────────────────────────────────────────────────────────────┐
│ │
│ │
│ │
│ │
│ medium2 │
│ │
│ │
│ │
│ ┌────┐┌────┐┌────┐┌────┐┌────┐┌────┐┌────┐┌────┐┌────┐┌────┐ │
│ │ ││ ││ ││ ││ ││ ││ ││ ││ ││ │ │
│ │ ││ ││ ││ ││ ││ ││ ││ ││ ││ │ │
│ │ ││ ││ ││ ││ ││ ││ ││ ││ ││ │ │
│ │ 1 ││ 2 ││ 3 ││ 4 ││ 5 ││ 6 ││ 7 ││ 8 ││ 9 ││ 10 │ │
│ │ ││ ││ ││ ││ ││ ││ ││ ││ ││ │ │
│ │ ││ ││ ││ ││ ││ ││ ││ ││ ││ │ │
│ │ ││ ││ ││ ││ ││ ││ ││ ││ ││ │ │
│ └────┘└────┘└────┘└────┘└────┘└────┘└────┘└────┘└────┘└────┘ │
│ │
└──────────────────────────────────────────────────────────────┘
'''
microGeneric='''
┌─┐ ┌─┐
┌└─┘──└─┘┐
│ 1 2 │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└────────┘
'''
# Get the hostname
HOSTNAME=$(hostname)
# ASCII art based on hostname
case "$HOSTNAME" in
"large1")
echo -e "$large1"
;;
"medium1")
echo -e "$medium1"
;;
"medium2")
echo -e "$medium2"
;;
"micro1" | "micro2")
echo -e "$microGeneric"
;;
*)
echo -e "No ASCII map defined for this hostname."
;;
esac
map_drives_to_layout() {
local server_type=$1
case $server_type in
"large1")
for i in {1..9}; do
local drive_info=$(get_drive_info_for_position $i)
echo "Position $i: $drive_info"
done
;;
esac
}
# Enhanced Drive Information Function
get_drives_info() {
local path="/dev/disk/by-path"
for drive in "$path"/*; do
if [ -L "$drive" ]; then
echo "$(basename "$drive") $(readlink -f "$drive")"
fi
done
}
DRIVE_PATHS=$(get_drives_info | awk '{print $1, $2}')
# Initialize array for "not found" messages
not_found=()
# Show NVMe Drives only if present
nvme_drives=$(sudo nvme list | grep "^/dev")
if [ -n "$nvme_drives" ]; then
echo -e "\n=== NVMe Drives ===\n"
printf "%-15s %-10s %-10s %-20s\n" "DEVICE" "SIZE" "TYPE" "MODEL"
echo "------------------------------------------------------------"
echo "$nvme_drives" | awk '{printf "%-15s %-10s %-10s %-20s\n", $1, $6, "NVMe", $3}'
else
not_found+=("NVMe drives")
fi
# Show MMC Drives only if present
mmc_output=$(lsblk -o NAME,SIZE,TYPE,MOUNTPOINT | grep "mmcblk" | sort)
if [ -n "$mmc_output" ]; then
echo -e "\n=== MMC Drives ===\n"
printf "%-15s %-10s %-10s %-20s\n" "DEVICE" "SIZE" "TYPE" "MOUNTPOINT"
echo "------------------------------------------------------------"
echo "$mmc_output"
fi
# Show SATA Drives only if present
sata_output=$(lsblk -d -o NAME,SIZE,TYPE,MOUNTPOINT | grep "disk" | grep -v "nvme" | grep -v "rbd" | sort | column -t)s
if [ -n "$sata_output" ]; then
echo -e "\n=== SATA Drives ===\n"
printf "%-15s %-10s %-10s %-20s\n" "DEVICE" "SIZE" "TYPE" "MOUNTPOINT"
echo "------------------------------------------------------------"
echo "$sata_output"
fi
# Show Ceph RBD Devices only if present
rbd_output=$(lsblk -o NAME,SIZE,TYPE,MOUNTPOINT | grep "rbd" | sort -V)
if [ -n "$rbd_output" ]; then
echo -e "\n=== Ceph RBD Devices ===\n"
printf "%-15s %-10s %-10s %-20s\n" "DEVICE" "SIZE" "TYPE" "MOUNTPOINT"
echo "------------------------------------------------------------"
echo "$rbd_output"
else
not_found+=("RBD devices")
fi
# Check RAID
if ! [ -f /proc/mdstat ] || ! grep -q "active" /proc/mdstat; then
not_found+=("Software RAID")
fi
# Check ZFS
if ! command -v zpool >/dev/null 2>&1 || [ -z "$(sudo zpool status 2>/dev/null)" ]; then
not_found+=("ZFS pools")
fi
# Display consolidated "not found" messages at the end
if [ ${#not_found[@]} -gt 0 ]; then
echo -e "\n=== Not Found ===\n"
printf "%s\n" "${not_found[@]}"
fi