functions: fix random serial

Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
AuxXxilium 2024-05-11 16:25:53 +02:00
parent 0331738af9
commit 7bd80d8e47

View File

@ -72,17 +72,17 @@ function genRandomValue() {
# 1 - Model
# Returns serial number
function generateSerial() {
PREFIX="$(readConfigArray "${1}.prefix" "${S_FILE}" | sort -R | tail -1)"
MIDDLE="$(readConfigArray "${1}.middle" "${S_FILE}" | sort -R | tail -1)"
SUFFIX="$(readConfigKey "${1}.suffix" "${S_FILE}")"
PREFIX="$(readConfigArray "${1}.prefix" "${S_FILE}" 2>/dev/null | sort -R | tail -1)"
MIDDLE="$(readConfigArray "${1}.middle" "${S_FILE}" 2>/dev/null | sort -R | tail -1)"
SUFFIX="$(readConfigKey "${1}.suffix" "${S_FILE}" 2>/dev/null)"
SERIAL="${PREFIX:-"0000"}${MIDDLE:-"XXX"}"
case "${SUFFIX}" in
case "${SUFFIX:-"alpha"}" in
numeric)
SUFFIX="$(random)"
SERIAL+="$(random)"
;;
alpha)
SUFFIX="$(genRandomLetter)$(genRandomValue)$(genRandomValue)$(genRandomValue)$(genRandomValue)$(genRandomLetter)"
SERIAL+="$(genRandomLetter)$(genRandomValue)$(genRandomValue)$(genRandomValue)$(genRandomValue)$(genRandomLetter)"
;;
esac