#!/bin/bash
# Copyright (C) 2024 MOXA Inc. All rights reserved.
# This software is distributed under the terms of the MOXA SOFTWARE NOTICE.
# See the file LICENSE for details.
#
# Name:
#       MOXA Common Library
# Authors:
#       2024    Wilson Huang <WilsonYS.Huang@moxa.com>
#

function is_module_loaded() {
        local mod_name
        mod_name=${1}

        lsmod | grep -w $mod_name &>/dev/null
}

function check_leading_zero_digit() {
        local digit
        digit=${1}

        [[ "$digit" =~ ^([1-9][0-9]*|0)$ ]]
}

function get_model_name_from_dmi_type12() {
        /usr/sbin/dmidecode -t 12 |
                grep "Option " |
                awk -F ':' '{print substr($2,1,11)}' |
                sed 's/ //g'
}

function get_model_name_from_dmi_type1() {
        /usr/sbin/dmidecode -t 1 |
                grep "Product Name" |
                awk -F ':' '{print $2}' |
                sed 's/ //g'
}
