Created
December 31, 2017 07:17
-
-
Save coenraadhuman/9a87b8b13ef5c0e0a7a90d9152e0747e to your computer and use it in GitHub Desktop.
This is a simple script for changing fan speed on iMac running Linux (ensure applesmc is active)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Root? | |
if [ "$(id -u)" != "0" ]; then | |
exec sudo "$0" "$@" | |
fi | |
fan_speeds() | |
{ | |
echo "Available fan speeds on this iMac:" | |
echo "1) Fan speed: $1 - $2" | |
echo "2) Fan speed: $3 - $4" | |
echo "3) Fan speed: $5 - $6" | |
} | |
fan_check() | |
{ | |
if [ $1 > $2 ] | |
then | |
if [ $1 > $3 ] | |
then | |
echo "Fan is speed invalid, please set values between:" | |
echo "" | |
fan_speeds $one_min $one_max $two_min $two_max $three_min $three_max | |
exit | |
else | |
echo "Fan speed within range." | |
else | |
echo "Fan is speed invalid, please set values between:" | |
echo "" | |
fan_speeds $one_min $one_max $two_min $two_max $three_min $three_max | |
exit | |
fi | |
} | |
fan_manual() | |
{ | |
# Set fan control to manual | |
echo 1 > /sys/devices/platform/applesmc.768/fan1_manual | |
echo 1 > /sys/devices/platform/applesmc.768/fan2_manual | |
echo 1 > /sys/devices/platform/applesmc.768/fan3_manual | |
} | |
fan1_speed() | |
{ | |
# Set fan speed | |
echo $1 > /sys/devices/platform/applesmc.768/fan1_output | |
} | |
fan2_speed() | |
{ | |
# Set fan speed | |
echo $1 > /sys/devices/platform/applesmc.768/fan2_output | |
} | |
fan3_speed() | |
{ | |
# Set fan speed | |
echo $1 > /sys/devices/platform/applesmc.768/fan3_output | |
} | |
help_message() | |
{ | |
echo "fan_start.sh - a script to set fan speeds manually on an iMac in Linux" | |
echo "" | |
echo "How to use:" | |
echo "'fan_start.sh 3000' - This sets speed of all fans to entered value." | |
echo "'fan_start.sh 3000 3000 3000' - This individually sets speed of each fan to entered values (fan_1 fan_2 fan_3)." | |
echo "" | |
fan_speeds $one_min $one_max $two_min $two_max $three_min $three_max | |
echo "" | |
echo "To see this again use 'fan_start.sh help'." | |
} | |
# Variables | |
one_min=$(cat /sys/devices/platform/applesmc.768/fan1_min) | |
one_max=$(cat /sys/devices/platform/applesmc.768/fan1_max) | |
two_min=$(cat /sys/devices/platform/applesmc.768/fan2_min) | |
two_max=$(cat /sys/devices/platform/applesmc.768/fan2_max) | |
three_min=$(cat /sys/devices/platform/applesmc.768/fan3_min) | |
three_max=$(cat /sys/devices/platform/applesmc.768/fan3_max) | |
# Main | |
if [ $# = 0 ] | |
then | |
help_message | |
elif [ $# = 1 ] | |
then | |
if [ $1 = "help" ] | |
then | |
help_message | |
else | |
fan_manual | |
fan_check $1 $one_min $one_max | |
fan_check $2 $two_min $two_max | |
fan_check $3 $three_min $three_max | |
fan1_speed $1 | |
fan2_speed $1 | |
fan3_speed $1 | |
fi | |
elif [ $# = 2 ] | |
then | |
help_message | |
elif [ $# = 3 ] | |
then | |
fan_manual | |
fan_check $1 $one_min $one_max | |
fan_check $2 $two_min $two_max | |
fan_check $3 $three_min $three_max | |
fan1_speed $1 | |
fan2_speed $2 | |
fan3_speed $3 | |
else | |
help_message | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment