From 04c034236701dde80b759c3dce72babe23544e9a Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Tue, 10 Mar 2026 15:27:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(master=20:=20nicsensor.sh)=20update=20to?= =?UTF-8?q?=201.9.6=201.=E5=A2=9E=E5=8A=A0=E5=AE=89=E5=85=A8=E6=80=A7?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=86=85=E5=AE=B9=202.pmbus=5Fcmd=5Flist=20?= =?UTF-8?q?=E5=BC=95=E5=85=A5=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nicsensor.sh | 64 +++++++++++++++++++++++++++++++++++------------ pmbus_cmd_list.sh | 3 ++- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/nicsensor.sh b/nicsensor.sh index c622537..31ae222 100755 --- a/nicsensor.sh +++ b/nicsensor.sh @@ -1,5 +1,7 @@ #!/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) # --------------------------------------------------------- @@ -158,6 +160,7 @@ log="/tmp/nicsensor_debug.log" pmbus_op="get" hex_pmbus_cmd=0xff hex_pmbus_size=0 +CONFIG_DIR="/tmp/ns/" # --------------------------------------------------------- # Script Function Defination # --------------------------------------------------------- @@ -254,6 +257,29 @@ print_usage(){ 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 # @Param1 hex data hex_to_dec(){ @@ -341,16 +367,16 @@ parse_nic_slot(){ get_set_properties(){ if [ "$Param2" = "server" ];then - target_file="/tmp/ns_servertype" + target_file="${CONFIG_DIR}ns_servertype" default_data=$server_type elif [ "$Param2" = "debug" ];then - target_file="/tmp/ns_debugmode" + target_file="${CONFIG_DIR}ns_debugmode" default_data=$DEBUG_MODE elif [ "$Param2" = "n_detect" ];then - target_file="/tmp/ns_disabledetect" + target_file="${CONFIG_DIR}ns_disabledetect" default_data=$DISABLE_DETECT elif [ "$Param2" = "fru_size" ];then - target_file="/tmp/ns_frusize" + target_file="${CONFIG_DIR}ns_frusize" default_data=$fru_size else fmt_print "console" $ERROR "Invalid Property : $Param2" @@ -373,27 +399,27 @@ get_set_properties(){ } load_properties_from_cache(){ - if [ -e "/tmp/ns_servertype" ];then - server_type=`cat /tmp/ns_servertype` + if [ -e "${CONFIG_DIR}ns_servertype" ];then + server_type=`cat ${CONFIG_DIR}ns_servertype` fi - if [ -e "/tmp/ns_debugmode" ];then - DEBUG_MODE=`cat /tmp/ns_debugmode` + if [ -e "${CONFIG_DIR}ns_debugmode" ];then + DEBUG_MODE=`cat ${CONFIG_DIR}ns_debugmode` fi - if [ -e "/tmp/ns_disabledetect" ];then - DISABLE_DETECT=`cat /tmp/ns_disabledetect` + if [ -e "${CONFIG_DIR}ns_disabledetect" ];then + DISABLE_DETECT=`cat ${CONFIG_DIR}ns_disabledetect` fi - if [ -e "/tmp/ns_frusize" ];then - fru_size=`cat /tmp/ns_frusize` + if [ -e "${CONFIG_DIR}ns_frusize" ];then + fru_size=`cat ${CONFIG_DIR}ns_frusize` fi } # According to boardid, parse server_type try_get_server_type(){ - if [ -e "/tmp/ns_servertype" ];then - server_type=`cat /tmp/ns_servertype` + if [ -e "${CONFIG_DIR}ns_servertype" ];then + server_type=`cat ${CONFIG_DIR}ns_servertype` else boardid=`cat /proc/cmdline | awk -F 'boardid=' '{split($2, a," "); print a[1]}'` @@ -416,7 +442,7 @@ try_get_server_type(){ exit 1 fi - echo $server_type > /tmp/ns_servertype + echo $server_type > ${CONFIG_DIR}ns_servertype fi } @@ -425,6 +451,11 @@ init_debuglog(){ rm $log 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` fmt_print "log" $INFO "Start Time : $res_date" fmt_print "log" $INFO "Script Version : $SCRIPT_VERSION" @@ -505,6 +536,7 @@ switch_pca9548_channel(){ # Function 4 : Implementation of Parameter Setting Function pre_exec_hook(){ init_debuglog + systemtool_check if [ "$Param1" = "help" ] && [ $param_num -eq 2 ];then print_usage $Param2 diff --git a/pmbus_cmd_list.sh b/pmbus_cmd_list.sh index 5be4c34..46602a2 100644 --- a/pmbus_cmd_list.sh +++ b/pmbus_cmd_list.sh @@ -8,7 +8,7 @@ # How to use this pmbus plugin? # Copy this file to the dir as same as nicsensor.sh - +EXTENSION_VERSION="v1.0" # --------------------------------------------------------- # Varible Define # --------------------------------------------------------- @@ -27,6 +27,7 @@ PMBUS_RAW=4 # --------------------------------------------------------- pmbus_command_help(){ echo " Extend Function - PMBUS command test" + echo " Version : $EXTENSION_VERSION" echo " 1) Command Format : ./nicsensor.sh [slot] pmbus [slave] [command]" echo " 2) Option Detail" echo " - [slot] : 0 1 2 3 4 5 ..."