Compare commits

...

2 Commits

Author SHA1 Message Date
Joshua Boniface 5a9d44511e Add nicer output for detects 2021-12-28 00:53:17 -05:00
Joshua Boniface c0fde2a3bb Modify detect match to 3%
This will handle corner cases of RAID devices that are a little smaller
than expected (300GB -> 293GB), which were a little outside the 2%
range, while still being close enough.
2021-12-24 15:39:10 -05:00
1 changed files with 11 additions and 10 deletions

View File

@ -225,20 +225,19 @@ seed_config() {
# detect:INTEL:800GB:1 # detect:INTEL:800GB:1
# detect:DELLBOSS:240GB:0 # detect:DELLBOSS:240GB:0
# detect:PERC H330 Mini:200GB:0 # detect:PERC H330 Mini:200GB:0
echo "Attempting to find disk for detect string '${o_target_disk}'"
IFS=: read detect b_name b_size b_id <<<"${target_disk}" IFS=: read detect b_name b_size b_id <<<"${target_disk}"
# Get the lsscsi output (exclude NVMe) # Get the lsscsi output (exclude NVMe)
lsscsi_data_all="$( lsscsi -s -N )" lsscsi_data_all="$( lsscsi -s -N )"
# Get the available sizes, and match to within +/- 2% # Get the available sizes, and match to within +/- 3%
lsscsi_sizes=( $( awk '{ print $NF }' <<<"${lsscsi_data_all}" | sort | uniq ) ) lsscsi_sizes=( $( awk '{ print $NF }' <<<"${lsscsi_data_all}" | sort | uniq ) )
# For each size... # For each size...
for size in ${lsscsi_sizes[@]}; do for size in ${lsscsi_sizes[@]}; do
# Get whether we match +2% and -2% sizes to handle human -> real deltas # Get whether we match +3% and -3% sizes to handle human -> real deltas
# The break below is pretty safe. I can think of no two classes of disks # The break below is pretty safe. I can think of no two classes of disks
# where the difference is within 2% of each other. Even the common # where the difference is within 3% of each other. Even the common
# 120GB -> 128GB and 240GB -> 256GB size deltas are well outside of 2%, # 120GB -> 128GB and 240GB -> 256GB size deltas are well outside of 3%,
# so this should be safe in all cases. 1% would be narrower but has more # so this should be safe in all cases.
# chance of mis-identifying due to rounding, while 3% gets into more
# contentious differences, so 2% seems like the best option.
# We use Python for this due to BASH's problematic handling of floating- # We use Python for this due to BASH's problematic handling of floating-
# point numbers. # point numbers.
is_match="$( is_match="$(
@ -249,9 +248,9 @@ try:
t_size = float(sub(r'\D.','','${size}')) t_size = float(sub(r'\D.','','${size}'))
except ValueError: except ValueError:
exit(0) exit(0)
plustwopct = t_size * 1.02 plusthreepct = t_size * 1.03
minustwopct = t_size * 0.98 minusthreepct = t_size * 0.97
if b_size > minustwopct and b_size < plustwopct: if b_size > minusthreepct and b_size < plusthreepct:
print("match") print("match")
EOF EOF
)" )"
@ -275,6 +274,8 @@ EOF
if [[ ! -b ${target_disk} ]]; then if [[ ! -b ${target_disk} ]]; then
echo "Invalid disk or disk not found for '${o_target_disk}'!" echo "Invalid disk or disk not found for '${o_target_disk}'!"
exit 1 exit 1
else
echo "Found target disk '${target_disk}'"
fi fi
echo echo