@@ -107,17 +107,26 @@ else
107
107
fi
108
108
echo " SYSFS parse model/serial from wwid_raw:'${wwid_raw} '" >&2
109
109
if [ -n " ${wwid_raw} " ]; then
110
- wwid_raw=$( echo " ${wwid_raw} " | sed ' s/^ *//;s/ *$//' ) # Remove leading and trailing spaces
111
- wwid_prefix=$( echo " ${wwid_raw} " | awk ' {print $1}' ) # Extract the wwid_prefix (first field)
112
- rest=$( echo " ${wwid_raw} " | sed " s/^${wwid_prefix} *//" ) # Remove the wwid_prefix from the wwid string
113
- wwid_serial=$( echo " ${rest} " | awk ' {print $NF}' ) # Extract the serial (last field)
114
- rest=$( echo " ${rest} " | sed " s/ ${wwid_serial} $//" ) # Remove the serial from the rest of the string
115
- wwid_model=$( echo " ${rest} " | tr ' ' ' _' ) # Replace any remaining spaces in the rest part with underscores
116
- wwid_model=$( echo " ${wwid_model} " | sed ' s/__*/_/g' ) # Remove consecutive underscores
117
- wwid_model=$( echo " ${wwid_model} " | sed ' s/^_//;s/_$//' ) # Remove leading and trailing underscores
118
- wwid_prefix=$( echo " ${wwid_prefix} " | sed ' s/\./-/g' ) # Replace periods in the wwid_prefix with dashes
119
- unset rest
120
- echo " WWID parsing came up with wwid_prefix='${wwid_prefix} ' wwid_model='${wwid_model} ', wwid_serial='${wwid_serial} '" >&2
110
+ wwid_raw=$( echo " ${wwid_raw} " | sed ' s/^ *//;s/ *$//' ) # Remove leading and trailing spaces
111
+ wwid_prefix=$( echo " ${wwid_raw} " | awk ' {print $1}' ) # Extract the wwid_prefix (first field)
112
+ rest=$( echo " ${wwid_raw} " | sed " s/^${wwid_prefix} *//" ) # Remove the wwid_prefix from the wwid string
113
+ wwid_serial=$( echo " ${rest} " | awk ' {print $NF}' ) # Extract the serial (last field)
114
+ wwid_model=$( echo " ${rest} " | sed " s/ ${wwid_serial} $//" ) # Remove the serial from the rest of the string
115
+ : # sanitize model ----------------------------------------------------------------------
116
+ wwid_model=$( echo " ${wwid_model} " | tr ' ' ' _' | tr ' .' ' _' | tr ' /' ' _' ) # Replace any remaining spaces, dots, slashes in the rest part with underscores
117
+ wwid_model=$( echo " ${wwid_model} " | sed ' s/\\0//g' ) # Remove all instances of literal backslash-zero "\0" (not really nulls)
118
+ wwid_model=$( echo " ${wwid_model} " | sed ' s/\\/_/g' ) # replace any remaining backslashes with underscores
119
+ wwid_model=$( echo " ${wwid_model} " | sed ' s/__*/_/g' ) # Remove consecutive underscores
120
+ wwid_model=$( echo " ${wwid_model} " | sed ' s/^_//;s/_$//' ) # Remove leading and trailing underscores
121
+ : # sanitize serial ---------------------------------------------------------------------
122
+ wwid_serial=$( echo " ${wwid_serial} " | tr ' ' ' _' | tr ' .' ' _' | tr ' /' ' _' ) # Replace any remaining spaces, dots, slashes in the rest part with underscores
123
+ wwid_serial=$( echo " ${wwid_serial} " | sed ' s/\\0//g' ) # Remove all instances of literal backslash-zero "\0" (not really nulls)
124
+ wwid_serial=$( echo " ${wwid_serial} " | sed ' s/\\/_/g' ) # replace any remaining backslashes with underscores
125
+ wwid_serial=$( echo " ${wwid_serial} " | sed ' s/__*/_/g' ) # Remove consecutive underscores
126
+ wwid_serial=$( echo " ${wwid_serial} " | sed ' s/^_//;s/_$//' ) # Remove leading and trailing underscores
127
+
128
+ unset rest wwid_prefix
129
+ echo " WWID parsing came up with wwid_model='${wwid_model} ', wwid_serial='${wwid_serial} '" >&2
121
130
else
122
131
echo " WWID is empty or not found" >&2
123
132
fi
0 commit comments