blob: 23742a6872dbe15703d93c7b2734a63b54dab430 [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"
18# Get and Set WCTEMP
19for ((i = 0; i < 16; i++)); do
George Hung89f2ff22021-03-25 13:59:12 +080020 name="@WCTemp$(printf "%02d" $i)@"
George Hung027c0552021-03-08 16:45:06 +080021 wcTemp=72000
22 presentState=$(busctl get-property \
23 xyz.openbmc_project.Inventory.Manager \
24 ${nvmeInventoryPath}${i} \
25 xyz.openbmc_project.Inventory.Item \
26 Present | awk '{print $2}')
27
28 if [[ $presentState == "true" ]]; then
29 wcTemp=$(
30 busctl get-property xyz.openbmc_project.nvme.manager \
31 ${nvmePath}${i} \
32 xyz.openbmc_project.Sensor.Threshold.Critical \
33 CriticalHigh | awk '{print $2}'
34 )
35 wcTemp=$((wcTemp * 1000))
36 fi
37
George Hung89f2ff22021-03-25 13:59:12 +080038 sed -i "s/$name/${wcTemp}/g" $TEMP_FILE
George Hung027c0552021-03-08 16:45:06 +080039done
40
George Hung89f2ff22021-03-25 13:59:12 +080041# Use shell parameter expansion to trim the ".in" suffix
42mv "$TEMP_FILE" "${MARGIN_TABLE_FILE_IN%".in"}"
43
George Hunga0ae66a2020-06-30 10:47:30 +080044# start read margin temp
45/usr/bin/read-margin-temp &
46
47exit 0