From 263837f1e709ea821746f7deb9e8a29fa3dd52b3 Mon Sep 17 00:00:00 2001 From: arno Date: Wed, 7 Oct 2020 12:43:53 +0200 Subject: [PATCH] Detection of HDD/SSD (#1625) See #1621 --- home.admin/config.scripts/blitz.datadrive.sh | 45 ++++++++++++++------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/home.admin/config.scripts/blitz.datadrive.sh b/home.admin/config.scripts/blitz.datadrive.sh index d115805dc..1efeea20e 100755 --- a/home.admin/config.scripts/blitz.datadrive.sh +++ b/home.admin/config.scripts/blitz.datadrive.sh @@ -81,6 +81,8 @@ if [ "$1" = "status" ]; then # find the HDD (biggest single partition) hdd="" sizeDataPartition=0 + OSPartition=$(sudo df /usr | grep dev | cut -d " " -f 1) + lsblk -o NAME,SIZE -b | grep -P "[s|v]d[a-z][0-9]?" > .lsblk.tmp while read line; do @@ -88,24 +90,40 @@ if [ "$1" = "status" ]; then testname=$(echo $line | cut -d " " -f 1 | sed 's/[^a-z0-9]*//g') testdevice=$(echo $testname | sed 's/[^a-z]*//g') testpartition=$(echo $testname | grep -P '[a-z]{3,5}[0-9]{1}') - testsize=$(echo $line | sed "s/ */ /g" | cut -d " " -f 2 | sed 's/[^0-9]*//g') + if [ ${#testpartition} -gt 0 ]; then + testsize=$(echo $line | sed "s/ */ /g" | cut -d " " -f 2 | sed 's/[^0-9]*//g') + else + testsize=0 + fi #echo "# line($line)" #echo "# testname(${testname}) testdevice(${testdevice}) testpartition(${testpartition}) testsize(${testsize})" - # if no matching device found yet - take first for the beginning (just in case no partions at all) - if [ ${#hdd} -eq 0 ]; then - hdd="${testdevice}" - fi - - # if a partition was found - make sure to use the biggest - if [ ${#testpartition} -gt 0 ] && [ ${testsize} -gt ${sizeDataPartition} ]; then - sizeDataPartition=${testsize} - hddDataPartition="${testpartition}" - hdd="${testdevice}" + # count partitions + testpartitioncount=$(sudo fdisk -l | grep /dev/$testdevice | wc -l) + # do not count line with disk info + testpartitioncount=$((testpartitioncount-1)) + + if [ $testpartitioncount -gt 0 ]; then + # if a partition was found - make sure to skip OS partition + if [ "$testpartition" != "$OSPartition" ]; then + + # make sure to use the biggest + if [ ${testsize} -gt ${sizeDataPartition} ]; then + sizeDataPartition=${testsize} + hddDataPartition="${testpartition}" + hdd="${testdevice}" + fi + fi + else + # Partion to be created is smaller than disk so this is not correct (but close) + sizeDataPartition=$(sudo fdisk -l /dev/$testdevice | grep GiB | cut -d " " -f 5) + hddDataPartition="${testdevice}1" + hdd="${testdevice}" fi done < .lsblk.tmp rm -f .lsblk.tmp 1>/dev/null 2>/dev/null + if [ ${#hddDataPartition} -lt 4 ]; then echo "# WARNING: found invalid partition (${ddDataPartition}) - redacting" hddDataPartition="" @@ -124,7 +142,10 @@ if [ "$1" = "status" ]; then echo "hddGigaBytes=${hddDataPartitionGigaBytes}" # check if single drive with that size - hddCount=$(lsblk -o NAME,SIZE -b | grep -c ${hddDataPartition}) + hddCount=0 + if [ ${#hddDataPartition} -gt 0 ]; then + hddCount=1 + fi echo "hddCount=${hddCount}" # check format of devices partition