2023-09-12 23:47:49 +00:00
|
|
|
#!/bin/bash
|
2023-10-23 22:44:47 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2023-10-23 22:46:49 +00:00
|
|
|
# Copyright (C) 2023-present - The JELOS Project (https://github.com/JustEnoughLinuxOS) (https://github.com/fewtarius)
|
2023-09-12 23:47:49 +00:00
|
|
|
|
|
|
|
. /etc/profile
|
|
|
|
|
|
|
|
DEBUG=false
|
|
|
|
COOLING_PROFILE=$(get_setting "cooling.profile")
|
|
|
|
FAN_PWM="${DEVICE_PWM_FAN}"
|
|
|
|
|
|
|
|
log $0 "Setting profile to ${COOLING_PROFILE}"
|
|
|
|
|
2023-09-13 09:21:22 +00:00
|
|
|
function set_control() {
|
|
|
|
log $0 "Set fan control to ${1}"
|
|
|
|
if [ -e "${DEVICE_PWM_FAN}_enable" ]
|
|
|
|
then
|
|
|
|
echo ${1} >${DEVICE_PWM_FAN}_enable
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
trap "set_control 0 && exit 0" SIGHUP SIGINT SIGQUIT SIGABRT
|
2023-09-12 23:47:49 +00:00
|
|
|
|
|
|
|
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
|
2023-09-13 09:21:22 +00:00
|
|
|
WARN="Custom fan profile could not be loaded, defaulting to auto."
|
2023-09-12 23:47:49 +00:00
|
|
|
log $0 "${WARN}"
|
2023-09-13 09:21:22 +00:00
|
|
|
COOLING_PROFILE="auto"
|
|
|
|
set_setting cooling.profile auto
|
2023-09-12 23:47:49 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! "${COOLING_PROFILE}" = "custom" ]
|
|
|
|
then
|
|
|
|
if [ "${COOLING_PROFILE}" = "aggressive" ]
|
|
|
|
then
|
2023-09-17 15:48:47 +00:00
|
|
|
SPEEDS=(255 225 192)
|
|
|
|
TEMPS=(70000 65000 0)
|
2023-09-12 23:47:49 +00:00
|
|
|
elif [ "${COOLING_PROFILE}" = "moderate" ]
|
|
|
|
then
|
|
|
|
SPEEDS=(255 192 128 96)
|
2023-09-17 15:48:47 +00:00
|
|
|
TEMPS=(75000 70000 65000 0)
|
2023-09-13 09:21:22 +00:00
|
|
|
elif [ "${COOLING_PROFILE}" = "quiet" ]
|
|
|
|
then
|
2023-09-12 23:47:49 +00:00
|
|
|
# Quiet.
|
|
|
|
SPEEDS=(255 192 128 96 64 48 32)
|
2023-09-17 15:48:47 +00:00
|
|
|
TEMPS=(75000 70000 65000 60000 55000 50000 0)
|
2023-09-13 09:21:22 +00:00
|
|
|
else
|
|
|
|
# auto
|
|
|
|
set_control 0 >/dev/null 2>&1
|
|
|
|
exit 0
|
2023-09-12 23:47:49 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-09-13 09:21:22 +00:00
|
|
|
log $0 "Enabling fan control."
|
|
|
|
set_control 1 >/dev/null 2>&1
|
|
|
|
|
2023-09-12 23:47:49 +00:00
|
|
|
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
|
|
|
|
|
2023-09-13 09:21:22 +00:00
|
|
|
log $0 "Disabling fan control."
|
|
|
|
set_control 0 >/dev/null 2>&1
|