--- /dev/null
+[Unit]
+Description=Monitor temperature to throttle CPU if necessary
+
+[Service]
+Type=simple
+ExecStart=/root/throttle_cpu.sh
+Restart=always
+RestartSec=10
+User=root
+
+[Install]
+WantedBy=multi-user.target
#!/bin/sh
# see sway-bar(5) and swaybar-protocol(7)
+MEGA=1000
+GIGA=1000000
printf '{ "version": 1 }\n[\n'
while true; do
printf ' [\n'
printf ' {"full_text": "%s"},\n' "$(ip -4 addr show scope global | grep -oP '(?<=inet\s)\d+(\.\d+){3}')"
- printf ' {"full_text": "%d° C"},\n' $(calc "$(cat /sys/class/thermal/thermal_zone0/temp) // 1000")
- printf ' {"full_text": "%.1f GHz"},\n' $(calc "$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) / 1000000")
+ printf ' {"full_text": "%d° C"},\n' $(calc "$(cat /sys/class/thermal/thermal_zone0/temp) // ${MEGA}")
+ printf ' {"full_text": "%.1f/%.1f GHz"},\n' $(calc "$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) / ${GIGA}") $(calc "$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq) / ${GIGA}")
printf ' {"full_text": "%s"},\n' "$(date +'%Y-%m-%d %X')"
printf ' ],\n'
sleep 1
--- /dev/null
+#!/bin/sh
+set -e
+
+MED_TEMP=65000
+MAX_TEMP=80000
+
+MIN_FREQ=600000
+MED_FREQ=1000000
+MAX_FREQ=1500000
+
+PATH_TEMP='/sys/class/thermal/thermal_zone0/temp'
+
+set_max_freq() {
+ for cpu in /sys/devices/system/cpu/cpu[0-9]*; do
+ echo "$1" > "$cpu/cpufreq/scaling_max_freq"
+ done
+ echo "$1"
+}
+
+freq_set=$(set_max_freq "${MIN_FREQ}")
+while true; do
+ temp=$(cat "${PATH_TEMP}")
+ if [ "${temp}" -ge "${MAX_TEMP}" ]; then
+ if [ "${freq_set}" -gt "${MIN_FREQ}" ]; then
+ freq_set=$(set_max_freq "${MIN_FREQ}")
+ fi
+ elif [ "${temp}" -ge "${MED_TEMP}" ]; then
+ if [ "${freq_set}" -gt "${MED_FREQ}" ]; then
+ freq_set=$(set_max_freq "${MED_FREQ}")
+ fi
+ elif [ "${freq_set}" -lt "${MAX_FREQ}" ]; then
+ freq_set=$(set_max_freq "${MAX_FREQ}")
+ fi
+ sleep 1
+done
for root in "${PATH_MANY}" '..'; do
copy_dirtree "${root}${PATH_REL_HOME}" "${PATH_USER_HOME}" all desktop $@
done
- cp -a "${PATH_REPO}" "${PATH_USER_HOME}"
mkdir "${PATH_USER_SSH}"
cp "${PATH_AUTHORIZED_KEYS}" "${PATH_USER_SSH}"
chown -R "${USERNAME}:${USERNAME}" "${PATH_USER_HOME}"
# actual setup
setup_for_desktop raspi
+
+copy_dirtree "${PATH_MANY}${PATH_REL_HOME}" '/root' raspi_root
+# systemctl enable throttle_cpu.service
+# systemctl start throttle_cpu.service