#!/usr/bin/env bash # fan-ctl — root-side actions for the daemon-sec.fans bar widget (run via # pkexec; the shell's polkit plugin presents the auth dialog). Thin dispatcher # over ~/.local/bin/fanfix, except `cap`, which re-applies the clock cap # without fanfix's built-in 20 s stress test so a panel click stays instant. set -uo pipefail FANFIX=/home/daemon-sec/.local/bin/fanfix CONF=/etc/tmpfiles.d/99-cpu-freq-cap.conf CPU0=/sys/devices/system/cpu/cpu0/cpufreq [ "$(id -u)" = 0 ] || { echo "fan-ctl must run as root (pkexec)" >&2; exit 1; } case "${1:-}" in auto|max) exec "$FANFIX" fan "$1" ;; set) pct="${2:?usage: fan-ctl set <30-100>}" exec "$FANFIX" fan "$pct" ;; curve) case "${2:-}" in on|off) exec "$FANFIX" fan curve "$2" ;; *) echo "usage: fan-ctl curve on|off" >&2; exit 2 ;; esac ;; drivers) exec "$FANFIX" fans --persist ;; cap) mhz="${2:-3200}" [[ "$mhz" =~ ^[0-9]+$ ]] || { echo "cap must be a number (MHz)" >&2; exit 2; } khz=$(( mhz < 100000 ? mhz * 1000 : mhz )) hwmax=$(cat "$CPU0/cpuinfo_max_freq") { [ "$khz" -ge 1500000 ] && [ "$khz" -le "$hwmax" ]; } \ || { echo "cap out of range (1500-$(( hwmax / 1000 )) MHz)" >&2; exit 2; } cat > "$CONF" < EC pins CPU at 399 MHz at ~79 C. Cap every core so it never gets there. # Remove with: fanfix uninstall (after the fan is replaced) w /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq - - - - ${khz} EOF systemd-tmpfiles --create "$CONF" powerprofilesctl set performance 2>/dev/null || true systemd-tmpfiles --create "$CONF" # profile switches toggle boost; re-assert echo "cap = $(( $(cat "$CPU0/scaling_max_freq") / 1000 )) MHz, persisted in $CONF" ;; uncap) # Full boost. The EC's fan-abnormal policy still stalls the CPU at ~79 C, # so sustained all-core loads may hit the 400 MHz clamp — deliberate choice. rm -f "$CONF" echo 1 > /sys/devices/system/cpu/cpufreq/boost for f in /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq; do cat "${f%scaling_max_freq}cpuinfo_max_freq" > "$f" done echo "uncapped: max = $(( $(cat "$CPU0/scaling_max_freq") / 1000 )) MHz, turbo boost on" ;; *) echo "usage: fan-ctl auto|max|set |curve on|off|drivers|cap [MHz]|uncap" >&2 exit 2 ;; esac