Put existing functionality into 'list' verb

master
BrainwreckedTech 3 years ago
parent 391ad63035
commit 40eeebb3da

@ -1,52 +1,44 @@
#!/bin/sh #!/bin/sh
# GET THE INITITAL OUTPUT OF `ls /sys/block` case "${1}" in
BLK_INFO="$(ls -l --color=never /sys/block | grep -v virtual | grep devices | sed 's/ \+/ /g' | cut -d\ -f9-)" list)
# GET THE INITITAL OUTPUT OF `ls /sys/block`
# STRIP OFF THE PCI BUS LOCATION INFORMATION BLK_INFO="$(ls -l --color=never /sys/block | grep -v virtual | grep devices | sed 's/ \+/ /g' | cut -d\ -f9-)"
BLK_INFO="$(echo "${BLK_INFO}" | sed 's|\.\.\/devices/pci[0-9a-f:]\{7\}\(/[0-9a-f:.]\{12\}\)\+/||g')" # STRIP OFF THE PCI BUS LOCATION INFORMATION
BLK_INFO="$(echo "${BLK_INFO}" | sed 's|\.\.\/devices/pci[0-9a-f:]\{7\}\(/[0-9a-f:.]\{12\}\)\+/||g')"
# STRIP OFF THE SUPERFLUOUS USB HOST INFORMATION # STRIP OFF THE SUPERFLUOUS USB HOST INFORMATION
BLK_INFO="$(echo "${BLK_INFO}" | sed 's|\(usb[0-9]\+\)/.*/host|\1/host|g')" BLK_INFO="$(echo "${BLK_INFO}" | sed 's|\(usb[0-9]\+\)/.*/host|\1/host|g')"
# STRIP OFF THE SUPERFLUOUS HOST AND TARGET INFORMATION
# STRIP OFF THE SUPERFLUOUS HOST AND TARGET INFORMATION BLK_INFO="$(echo "${BLK_INFO}" | sed 's|/host[0-9]\+/target\([0-9]\+\):\([0-9]\+\):\([0-9]\+\)/|/|g')"
BLK_INFO="$(echo "${BLK_INFO}" | sed 's|/host[0-9]\+/target\([0-9]\+\):\([0-9]\+\):\([0-9]\+\)/|/|g')" # NORMALIZE NVME INFO
BLK_INFO="$(echo "${BLK_INFO}" | sed 's|nvme/nvme\([0-9]\+\)/nvme\([0-9]\+\)n\([0-9]\+\)|nvme/N:\2:\3:1|g')"
# NORMALIZE NVME INFO # STRIP OFF BLOCKS
BLK_INFO="$(echo "${BLK_INFO}" | sed 's|nvme/nvme\([0-9]\+\)/nvme\([0-9]\+\)n\([0-9]\+\)|nvme/N:\2:\3:1|g')" BLK_INFO="$(echo "${BLK_INFO}" | sed 's|/block/.*||g')"
# CONVERT -> TO A SPACE
# STRIP OFF BLOCKS BLK_INFO="$(echo "${BLK_INFO}" | sed 's/ -> / /g')"
BLK_INFO="$(echo "${BLK_INFO}" | sed 's|/block/.*||g')" # CONVERT / TO A SPACE
BLK_INFO="$(echo "${BLK_INFO}" | sed 's|/| |g')"
# CONVERT -> TO A SPACE # NOW GET DEVICE IDs and SIZES
BLK_INFO="$(echo "${BLK_INFO}" | sed 's/ -> / /g')" echo "${BLK_INFO}" | while read -r BLOCKDEV DEV_PORT DEV_HCIL; do
DEVICE_ID="$(ls -l --color=never /dev/disk/by-id | sed 's/ \+/ /g' | grep -v 'nvme-eui\|wwn-' | grep "${BLOCKDEV}$" | cut -d\ -f9)"
# CONVERT / TO A SPACE DEV_BYTES="$(lsblk -bnPo NAME,SIZE | grep "\"${BLOCKDEV}\"" | cut -d\" -f 4)"
BLK_INFO="$(echo "${BLK_INFO}" | sed 's|/| |g')" if [ "${DEV_BYTES}" -ge $((1000**5)) ]; then
DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000^5}" | cut -b1-5)T"
# SWAP COLUMNS elif [ "${DEV_BYTES}" -ge $((1000**4)) ]; then
# BLK_INFO="$(echo "${BLK_INFO}" | awk '{t=$1; $1=$2; $2=t; print;}')" DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000^4}" | cut -b1-5)T"
elif [ "${DEV_BYTES}" -ge $((1000**3)) ]; then
# NOW GET DEVICE IDs and SIZES DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000^3}" | cut -b1-5)G"
elif [ "${DEV_BYTES}" -ge $((1000**2)) ]; then
echo "${BLK_INFO}" | while read -r BLOCKDEV DEV_PORT DEV_HCIL; do DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000^2}" | cut -b1-5)M"
DEVICE_ID="$(ls -l --color=never /dev/disk/by-id | sed 's/ \+/ /g' | grep -v 'nvme-eui\|wwn-' | grep "${BLOCKDEV}$" | cut -d\ -f9)" elif [ "${DEV_BYTES}" -ge 1000 ]; then
DEV_BYTES="$(lsblk -bnPo NAME,SIZE | grep "\"${BLOCKDEV}\"" | cut -d\" -f 4)" DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000}" | cut -b1-5)K"
if [ "${DEV_BYTES}" -ge $((1000**5)) ]; then else
DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000^5}" | cut -b1-5)T" DEVICE_SZ="${DEV_BYTES}B"
elif [ "${DEV_BYTES}" -ge $((1000**4)) ]; then fi
DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000^4}" | cut -b1-5)T" echo "${DEV_HCIL} ${DEV_PORT} ${BLOCKDEV} ${DEVICE_SZ} ${DEVICE_ID}" >> /tmp/bdmap
elif [ "${DEV_BYTES}" -ge $((1000**3)) ]; then done
DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000^3}" | cut -b1-5)G" column -N H:C:I:L,PORT,DEV,SIZE,NAME -t -R2,4 -o" " /tmp/bdmap
elif [ "${DEV_BYTES}" -ge $((1000**2)) ]; then rm /tmp/bdmap
DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000^2}" | cut -b1-5)M" ;;
elif [ "${DEV_BYTES}" -ge 1000 ]; then *) echo "Unknown verb '${1}' -- expected delete, list, or rescan"; exit 1;;
DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000}" | cut -b1-5)K" esac
else
DEVICE_SZ="${DEV_BYTES}B"
fi
echo "${DEV_HCIL} ${DEV_PORT} ${BLOCKDEV} ${DEVICE_SZ} ${DEVICE_ID}" >> /tmp/bdmap
done
column -N H:C:I:L,PORT,DEV,SIZE,NAME -t -R2,4 -o" " /tmp/bdmap
rm /tmp/bdmap

Loading…
Cancel
Save