Skip to content

Instantly share code, notes, and snippets.

@real-or-random
Created June 19, 2024 22:49
Show Gist options
  • Save real-or-random/0c543b50b629c2b306c30877b712bc18 to your computer and use it in GitHub Desktop.
Save real-or-random/0c543b50b629c2b306c30877b712bc18 to your computer and use it in GitHub Desktop.
Framework Fan Settings
[Unit]
Description=Sets fan parameters on Framework
# Try to avoid multiple ectool instances running at the same time
Before=fw-charge-limiter.service
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/etc/systemd/system/fw-fan-settings.sh start
ExecStop=/etc/systemd/system/fw-fan-settings.sh stop
[Install]
WantedBy=basic.target
#!/bin/bash
# From https://stackoverflow.com/a/35977896
#
# Retries a command on failure.
# $1 - the max number of attempts
# $2... - the command to run
retry() {
local -r -i max_attempts="$1"; shift
local -r cmd="$@"
local -i attempt_num=1
until $cmd
do
if (( attempt_num == max_attempts ))
then
echo "Attempt $attempt_num failed and there are no more attempts left!"
return 1
else
echo "Attempt $attempt_num failed! Trying again in $attempt_num seconds..."
sleep $(( attempt_num++ ))
fi
done
}
case "$1" in
start)
retry 5 fw-ectool thermalset 0 0 361 371 334 352
retry 5 fw-ectool thermalset 1 0 361 371 334 352
retry 5 fw-ectool thermalset 5 0 361 371 334 352
retry 5 fw-ectool thermalset 2 0 360 370 329 348
;;
stop)
retry 5 fw-ectool thermalset 0 0 361 371 324 342
retry 5 fw-ectool thermalset 1 0 361 371 324 342
retry 5 fw-ectool thermalset 5 0 361 371 324 342
retry 5 fw-ectool thermalset 2 0 360 370 313 342
;;
*)
echo 'Missing action, pass "start" or "stop".'
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment