blob: 992e40a716afcdb474c3a8651043a0040a9e4b77 [file] [log] [blame]
George Hunga0ae66a2020-06-30 10:47:30 +08001#!/bin/bash
2
George Hung89f2ff22021-03-25 13:59:12 +08003MARGIN_TABLE_FILE_IN="/usr/share/read-margin-temp/config-margin.json.in"
4TEMP_FILE="$(mktemp)"
5cp "$MARGIN_TABLE_FILE_IN" "$TEMP_FILE"
George Hunga0ae66a2020-06-30 10:47:30 +08006
George Hung89f2ff22021-03-25 13:59:12 +08007target_num="$(cat $TEMP_FILE | grep '"target"' | wc -l)"
George Hunga0ae66a2020-06-30 10:47:30 +08008
9# wait target dbus
George Hung89f2ff22021-03-25 13:59:12 +080010for ((i = 0; i < ${target_num}; i++)); do
George Hunga0ae66a2020-06-30 10:47:30 +080011 line_num=$((i+1))
George Hung89f2ff22021-03-25 13:59:12 +080012 path="$(cat $TEMP_FILE | grep '"target"' | head -n ${line_num} | tail -n +${line_num} | cut -d '"' -f 4)"
George Hunga0ae66a2020-06-30 10:47:30 +080013 mapper wait $path
14done
15
George Hung027c0552021-03-08 16:45:06 +080016nvmePath="/xyz/openbmc_project/sensors/temperature/nvme"
17nvmeInventoryPath="/xyz/openbmc_project/inventory/system/chassis/motherboard/nvme"
George Hungb3464d02021-04-08 07:36:01 +080018nvmeList=""
George Hung027c0552021-03-08 16:45:06 +080019# Get and Set WCTEMP
20for ((i = 0; i < 16; i++)); do
George Hung89f2ff22021-03-25 13:59:12 +080021 name="@WCTemp$(printf "%02d" $i)@"
George Hung027c0552021-03-08 16:45:06 +080022 wcTemp=72000
George Hungb3464d02021-04-08 07:36:01 +080023 presentState="$(busctl get-property \
George Hung027c0552021-03-08 16:45:06 +080024 xyz.openbmc_project.Inventory.Manager \
25 ${nvmeInventoryPath}${i} \
26 xyz.openbmc_project.Inventory.Item \
George Hungb3464d02021-04-08 07:36:01 +080027 Present | awk '{print $2}')"
George Hung027c0552021-03-08 16:45:06 +080028
George Hungb3464d02021-04-08 07:36:01 +080029 if [[ "$presentState" == "true" ]]; then
30 wcTemp="$(
George Hung027c0552021-03-08 16:45:06 +080031 busctl get-property xyz.openbmc_project.nvme.manager \
32 ${nvmePath}${i} \
33 xyz.openbmc_project.Sensor.Threshold.Critical \
34 CriticalHigh | awk '{print $2}'
George Hungb3464d02021-04-08 07:36:01 +080035 )"
36 wcTemp="$((wcTemp * 1000))"
37 if [[ -z "$nvmeList" ]]; then
38 nvmeList="\"nvme"${i}"\""
39 else
40 nvmeList="${nvmeList}"", \"nvme"${i}"\""
41 fi
George Hung027c0552021-03-08 16:45:06 +080042 fi
43
George Hungb3464d02021-04-08 07:36:01 +080044 sed -i "s/$name/${wcTemp}/g" "$TEMP_FILE"
George Hung027c0552021-03-08 16:45:06 +080045done
46
George Hungb3464d02021-04-08 07:36:01 +080047sed -i "s/@nvmeList@/${nvmeList}/g" "$TEMP_FILE"
48
George Hung89f2ff22021-03-25 13:59:12 +080049# Use shell parameter expansion to trim the ".in" suffix
50mv "$TEMP_FILE" "${MARGIN_TABLE_FILE_IN%".in"}"
51
George Hunga0ae66a2020-06-30 10:47:30 +080052# start read margin temp
53/usr/bin/read-margin-temp &
54
55exit 0