From ef6a89042f06a07aa2ac28da1c7cb7ef39b74b57 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 25 Nov 2022 19:30:22 -0500 Subject: [PATCH] Add a waybar script for reading temperature in Linux. --- .../waybar_temperature_linux.bash | 56 +++++++++++++++++++ ansible/roles/waybar/tasks/linux.yaml | 2 + 2 files changed, 58 insertions(+) create mode 100644 ansible/roles/waybar/files/waybar_scripts/waybar_temperature_linux.bash diff --git a/ansible/roles/waybar/files/waybar_scripts/waybar_temperature_linux.bash b/ansible/roles/waybar/files/waybar_scripts/waybar_temperature_linux.bash new file mode 100644 index 0000000..2522257 --- /dev/null +++ b/ansible/roles/waybar/files/waybar_scripts/waybar_temperature_linux.bash @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# +# Read temperature status in Linux +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +SLEEP_INTERVAL=${SLEEP_INTERVAL:-30} + +function print_all_x86_pkg_temps { + for thermal_zone in /sys/class/thermal/thermal_zone*; do + local thermal_zone_type=$(cat "$thermal_zone/type") + if [ "$thermal_zone_type" != "x86_pkg_temp" ]; then + continue + fi + local thermal_zone_temperature=$(cat "$thermal_zone/temp") + echo "$thermal_zone_temperature" + done +} + +while true; do + sum_temperature=0 + num_temperature=0 + max_temperature=0 + while read temp; do + numeric_temp=$(bc -s <<<"$temp / 1000.0") + sum_temperature=$(bc -s <<<"$sum_temperature + $numeric_temp") + num_temperature=$((num_temperature + 1)) + max_temperature=$(bc <b) + { + return(a) + }else{ + return(b) + } +} +max($max_temperature,$numeric_temp) +EOF + ) + done<<<$(print_all_x86_pkg_temps) + avg_temperature=$(bc -s <<<"$sum_temperature / $num_temperature") + tooltip="" + class="" + icon="🌡" + + jq --unbuffered --compact-output <