feat(master : nicsensor.sh) update to 1.9.6
1.增加安全性检查内容 2.pmbus_cmd_list 引入版本号
This commit is contained in:
parent
f526fa8190
commit
04c0342367
64
nicsensor.sh
64
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
|
||||
|
||||
@ -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 ..."
|
||||
|
||||
Loading…
Reference in New Issue
Block a user