Skip to content

Instantly share code, notes, and snippets.

@ljm42
Last active July 26, 2023 06:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljm42/d3132eab72661d0fd725f86f3ed13f65 to your computer and use it in GitHub Desktop.
Save ljm42/d3132eab72661d0fd725f86f3ed13f65 to your computer and use it in GitHub Desktop.
Fixes an issue with the "Dynamix System Temperature" plugin, adding "bus" line to sensors.conf
#!/bin/bash
#
# version 1.0
# latest version: https://gist.github.com/ljm42/d3132eab72661d0fd725f86f3ed13f65
#
# This is a user script that modifies the "Dynamix System Temperature" plugin version 2020.06.20
# so that it works on systems that require a "bus" line to be added to sensors.conf
#
# NOTE: Once the plugin itself has been updated to generate the "bus" line, you should uninstall this script
#
# To Install:
# * Install the "Dynamix System Temperature" plugin
# * Install the "User Scripts" plugin
# * Go to Settings -> Userscripts
# * Add New Script with name "fix_dynamix_temp"
# * Click on the cog/wheel next to "fix_dynamix_temp" and choose Edit Script
# * Copy/paste this into the box, replacing whatever is there. Hit Save Changes
# * Set the script to run "At First Array Start Only" and press Apply
# * Press Run Script to run it now
# * Go to Settings -> System Temp
# * Press Detect, then Save
# * Press Rescan, configure your sensors and Apply.
# Note: You MUST hit apply, so if needed make a dummy change and change it back to enable the Apply button
#
# To Uninstall:
# * You should do this after upgrading to a version of the "Dynamix System Temperature" plugin that handles the "bus" line
# * Go to Settings -> Userscripts
# * Click on the cog/wheel next to "fix_dynamix_temp" and choose Delete Script
# * Note: If you did not upgrade to a newer version of "Dynamix System Temperature" plugin
# but just want to undo this script, you need to reboot now to get back to the default plugin
# * Go to Settings -> System Temp
# * Press Detect, then Save
# * Now configure your sensors and Apply. This will remove any customizations from this user script.
# Note: You MUST hit apply, so if needed make a dummy change and change it back to enable the Apply button
#
### BEGIN SCRIPT ###
# calculate the "bus" line for sensors.conf per man file: https://linux.die.net/man/5/sensors3.conf
# NOTE: if multiple exist this will only pick up the last one.
for FILE in /sys/class/i2c-adapter/i2c-*; do
BUSNUM=${FILE##*/}
ADAPTER=$(cat "${FILE}/name")
LINE="bus \"${BUSNUM}\" \"${ADAPTER}\""
# echo $LINE
done
# bail if we couldn't determine the bus
[[ -z "$LINE" ]] && echo "nothing to do, bus was not found" && exit 1
echo "bus found: ${LINE}"
echo "---"
# Ensure "Dynamix System Temperature" plugin version 2020.06.20 is installed
[[ ! -e "/boot/config/plugins/dynamix.system.temp.plg" ]] && echo "nothing to do, 'Dynamix System Temperature' plugin not installed" && exit 1
if ! ( grep -q '!ENTITY version "2020.06.20"' "/boot/config/plugins/dynamix.system.temp.plg" ); then
echo "This user script only works with the 2020.06.20 version of the 'Dynamix System Temperature' plugin"
exit 1
fi
echo '"Dynamix System Temperature" plugin version 2020.06.20 found'
echo "---"
# Modify the "Dynamix System Temperature" plugin, customizing it for this particular system
# Once the plugin is modified, any new sesnsors.conf file it generates will include the "bus" line
#
PAGE="/usr/local/emhttp/plugins/dynamix.system.temp/TempSettings.page"
if [[ -f "$PAGE" ]]; then
# dynamix.system.temp is installed
if ! ( grep -q "${LINE}" ${PAGE} ); then
# only modify this file once
# add "bus" to script that generates sensors.conf
echo "editing ${PAGE}"
FINDLINE='\$content = "# sensors\\n"'
NEWLINE='\$content .= "# bus added by fix_dynamix_temp user script\\n";\n'
NEWLINE+="\$content .= '${LINE}'.\"\\\n\";"
sed -i "/${FINDLINE}/a ${NEWLINE}" $PAGE
fi
echo "${PAGE} contains:"
grep -A 2 "# sensors" $PAGE
echo "---"
fi
# If there is an existing sensors.conf file, modify it
#
PAGE="/etc/sensors.d/sensors.conf"
if [[ -f "$PAGE" ]]; then
# there is an existing sensors.conf file
if ! ( grep -q "${LINE}" ${PAGE} ); then
# only modify this file once
# add "bus" to existing sensors.conf
echo "editing ${PAGE}"
FINDLINE='\# sensors'
NEWLINE="# bus added directly by fix_dynamix_temp user script\n${LINE}"
sed -i "/${FINDLINE}/a ${NEWLINE}" $PAGE
fi
echo "${PAGE} contains:"
grep -A 2 "# sensors" $PAGE
echo "---"
fi
output=$(sensors -A 2>&1)
echo "sensors -A"
echo "${output}"
echo "---"
if [[ "${output}" =~ "Error" ]]; then
echo "something still isn't right, investigate the error above" && exit 1
fi
echo "No errors detected, go to Settings -> System Temp and configure your settings"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment