feat(master : nicsensor.sh) update to 1.9.6

1.增加安全性检查内容
2.pmbus_cmd_list 引入版本号
This commit is contained in:
leimingsheng 2026-03-10 15:27:18 +08:00
parent f526fa8190
commit 04c0342367
2 changed files with 50 additions and 17 deletions

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
SCRIPT_VERSION="1.9.5" set -euo pipefail
trap 'echo "Script terminated as line $LINENO , Please Check with command: cat /tmp/nicsensor.log"' ERR
SCRIPT_VERSION="1.9.6"
# --------------------------------------------------------- # ---------------------------------------------------------
# Project Feature Varible (Change if need) # Project Feature Varible (Change if need)
# --------------------------------------------------------- # ---------------------------------------------------------
@ -158,6 +160,7 @@ log="/tmp/nicsensor_debug.log"
pmbus_op="get" pmbus_op="get"
hex_pmbus_cmd=0xff hex_pmbus_cmd=0xff
hex_pmbus_size=0 hex_pmbus_size=0
CONFIG_DIR="/tmp/ns/"
# --------------------------------------------------------- # ---------------------------------------------------------
# Script Function Defination # Script Function Defination
# --------------------------------------------------------- # ---------------------------------------------------------
@ -254,6 +257,29 @@ print_usage(){
fi fi
} }
systemtool_check(){
systemtool_exist_flag="${CONFIG_DIR}systemtool_exist_flag"
# Check system tools exist flag file, if exists, skip check
if [ -e $systemtool_exist_flag ];then
fmt_print "log" $INFO "System tools found in file system"
return
fi
# Check system tools exist
systemtool_list="i2ctransfer i2cdetect i2cget bc"
for tool in $systemtool_list;do
if ! command -v $tool &> /dev/null;then
fmt_print "console" $ERROR "System tool $tool not found in file system"
fmt_print "console" $INFO "Please Check BMC Version, Only Support on AMI BMC!"
exit 1
fi
done
# Create system tools exist flag file
touch $systemtool_exist_flag
}
# Convert a hexadecimal number to a decimal number # Convert a hexadecimal number to a decimal number
# @Param1 hex data # @Param1 hex data
hex_to_dec(){ hex_to_dec(){
@ -341,16 +367,16 @@ parse_nic_slot(){
get_set_properties(){ get_set_properties(){
if [ "$Param2" = "server" ];then if [ "$Param2" = "server" ];then
target_file="/tmp/ns_servertype" target_file="${CONFIG_DIR}ns_servertype"
default_data=$server_type default_data=$server_type
elif [ "$Param2" = "debug" ];then elif [ "$Param2" = "debug" ];then
target_file="/tmp/ns_debugmode" target_file="${CONFIG_DIR}ns_debugmode"
default_data=$DEBUG_MODE default_data=$DEBUG_MODE
elif [ "$Param2" = "n_detect" ];then elif [ "$Param2" = "n_detect" ];then
target_file="/tmp/ns_disabledetect" target_file="${CONFIG_DIR}ns_disabledetect"
default_data=$DISABLE_DETECT default_data=$DISABLE_DETECT
elif [ "$Param2" = "fru_size" ];then elif [ "$Param2" = "fru_size" ];then
target_file="/tmp/ns_frusize" target_file="${CONFIG_DIR}ns_frusize"
default_data=$fru_size default_data=$fru_size
else else
fmt_print "console" $ERROR "Invalid Property : $Param2" fmt_print "console" $ERROR "Invalid Property : $Param2"
@ -373,27 +399,27 @@ get_set_properties(){
} }
load_properties_from_cache(){ load_properties_from_cache(){
if [ -e "/tmp/ns_servertype" ];then if [ -e "${CONFIG_DIR}ns_servertype" ];then
server_type=`cat /tmp/ns_servertype` server_type=`cat ${CONFIG_DIR}ns_servertype`
fi fi
if [ -e "/tmp/ns_debugmode" ];then if [ -e "${CONFIG_DIR}ns_debugmode" ];then
DEBUG_MODE=`cat /tmp/ns_debugmode` DEBUG_MODE=`cat ${CONFIG_DIR}ns_debugmode`
fi fi
if [ -e "/tmp/ns_disabledetect" ];then if [ -e "${CONFIG_DIR}ns_disabledetect" ];then
DISABLE_DETECT=`cat /tmp/ns_disabledetect` DISABLE_DETECT=`cat ${CONFIG_DIR}ns_disabledetect`
fi fi
if [ -e "/tmp/ns_frusize" ];then if [ -e "${CONFIG_DIR}ns_frusize" ];then
fru_size=`cat /tmp/ns_frusize` fru_size=`cat ${CONFIG_DIR}ns_frusize`
fi fi
} }
# According to boardid, parse server_type # According to boardid, parse server_type
try_get_server_type(){ try_get_server_type(){
if [ -e "/tmp/ns_servertype" ];then if [ -e "${CONFIG_DIR}ns_servertype" ];then
server_type=`cat /tmp/ns_servertype` server_type=`cat ${CONFIG_DIR}ns_servertype`
else else
boardid=`cat /proc/cmdline | awk -F 'boardid=' '{split($2, a," "); print a[1]}'` boardid=`cat /proc/cmdline | awk -F 'boardid=' '{split($2, a," "); print a[1]}'`
@ -416,7 +442,7 @@ try_get_server_type(){
exit 1 exit 1
fi fi
echo $server_type > /tmp/ns_servertype echo $server_type > ${CONFIG_DIR}ns_servertype
fi fi
} }
@ -425,6 +451,11 @@ init_debuglog(){
rm $log rm $log
fi fi
# create config dir if not exists
if [ ! -d $CONFIG_DIR ];then
mkdir -p $CONFIG_DIR
fi
res_date=`date +%Y-%m-%dT%H:%M:%S` res_date=`date +%Y-%m-%dT%H:%M:%S`
fmt_print "log" $INFO "Start Time : $res_date" fmt_print "log" $INFO "Start Time : $res_date"
fmt_print "log" $INFO "Script Version : $SCRIPT_VERSION" fmt_print "log" $INFO "Script Version : $SCRIPT_VERSION"
@ -505,6 +536,7 @@ switch_pca9548_channel(){
# Function 4 : Implementation of Parameter Setting Function # Function 4 : Implementation of Parameter Setting Function
pre_exec_hook(){ pre_exec_hook(){
init_debuglog init_debuglog
systemtool_check
if [ "$Param1" = "help" ] && [ $param_num -eq 2 ];then if [ "$Param1" = "help" ] && [ $param_num -eq 2 ];then
print_usage $Param2 print_usage $Param2

@ -8,7 +8,7 @@
# How to use this pmbus plugin? # How to use this pmbus plugin?
# Copy this file to the dir as same as nicsensor.sh # Copy this file to the dir as same as nicsensor.sh
EXTENSION_VERSION="v1.0"
# --------------------------------------------------------- # ---------------------------------------------------------
# Varible Define # Varible Define
# --------------------------------------------------------- # ---------------------------------------------------------
@ -27,6 +27,7 @@ PMBUS_RAW=4
# --------------------------------------------------------- # ---------------------------------------------------------
pmbus_command_help(){ pmbus_command_help(){
echo " Extend Function - PMBUS command test" echo " Extend Function - PMBUS command test"
echo " Version : $EXTENSION_VERSION"
echo " 1) Command Format : ./nicsensor.sh [slot] pmbus [slave] [command]" echo " 1) Command Format : ./nicsensor.sh [slot] pmbus [slave] [command]"
echo " 2) Option Detail" echo " 2) Option Detail"
echo " - [slot] : 0 1 2 3 4 5 ..." echo " - [slot] : 0 1 2 3 4 5 ..."