#!/bin/bash # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2021-present Fewtarius (https://github.com/fewtarius) . /etc/profile DEBUG=false COOLING_PROFILE=$(get_setting "cooling.profile") FAN_PWM="${DEVICE_PWM_FAN}" log $0 "Setting profile to ${COOLING_PROFILE}" log $0 "Enabling fan control." if [ -e "${DEVICE_PWM_FAN}_enable" ] then echo 1 >${DEVICE_PWM_FAN}_enable fi if [ -e "/storage/.config/fancontrol.conf" ] && [ "${COOLING_PROFILE}" = "custom" ] then log $0 "Loading configuration file" 2>/dev/null source /storage/.config/fancontrol.conf if [ ! $? = 0 ] then WARN="Custom fan profile could not be loaded, defaulting to quiet." log $0 "${WARN}" COOLING_PROFILE="quiet" set_setting cooling.profile quiet fi fi if [ ! "${COOLING_PROFILE}" = "custom" ] then if [ "${COOLING_PROFILE}" = "aggressive" ] then SPEEDS=(255 225 195) TEMPS=(55000 45000 0) elif [ "${COOLING_PROFILE}" = "moderate" ] then SPEEDS=(255 192 128 96) TEMPS=(65000 55000 45000 0) else # Quiet. SPEEDS=(255 192 128 96 64 48 32) TEMPS=(70000 60000 55000 50000 49000 47000 0) fi fi while true do INDEX=0 CPU_TEMP=$(printf "%.0f" $(awk '{ total += $1; count++ } END { print total/count }' ${DEVICE_TEMP_SENSOR})) $DEBUG && log $0 "CPU TEMP: ${CPU_TEMP}" 2>/dev/null for TEMP in "${TEMPS[@]}" do if (( "${CPU_TEMP}" > "${TEMP}" )) && \ [ ! "${LASTSPEED}" = "${SPEEDS[${INDEX}]}" ] then $DEBUG && log $0 "Setting PWM FAN to ${SPEEDS[${INDEX}]} (${TEMP})" 2>/dev/null echo ${SPEEDS[${INDEX}]} >${FAN_PWM} LASTSPEED=${SPEEDS[${INDEX}]} break fi INDEX=$(( $INDEX + 1 )) done sleep 2 done if [ -e "${DEVICE_PWM_FAN}_enable" ] then log $0 "Disabling fan control." echo 0 >${DEVICE_PWM_FAN}_enable fi