blob: b2907003346d7211f89f229645b8590029854966 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/usr/bin/env bash
## It would be nice to check the system and dynamically figure out which fan controller
## is being used...but I don't need that right now.
# echo "1" > /sys/devices/platform/applesmc.768/fan1_manual
# echo "9000" > /sys/devices/platform/applesmc.768/fan1_output
# cat /sys/devices/platform/applesmc.768/fan1_output
FAN_DIR=/sys/devices/platform/applesmc.768
FAN_OUT=$FAN_DIR/fan1_output
FAN_MANUAL=$FAN_DIR/fan1_manual
MAX_FAN=$(cat $FAN_DIR/fan1_max)
MIN_FAN=$(cat $FAN_DIR/fan1_min)
function toggle_mbpfan() {
SHOULD_DEACTIVE=$1
IS_ACTIVE=$(systemctl is-active mbpfan)
if [[ "$SHOULD_DEACTIVE" == "false" ]]; then
echo "force deactive!"
echo "0" > "$FAN_MANUAL"
sudo systemctl start mbpfan
return
elif [[ "$IS_ACTIVE" == "active" || "$SHOULD_DEACTIVE" == "true" ]]; then
sudo systemctl stop mbpfan
echo "force active!"
echo "1" > "$FAN_MANUAL"
return
else
echo "force deactive and start mbpfan"
echo "there!"
echo "0" > "$FAN_MANUAL"
sudo systemctl start mbpfan
return
fi
}
function increase_fan() {
CURR_SPEED=$(cat $FAN_DIR/fan1_output)
NEXT_SPEED=$(echo - | awk -v curr="$CURR_SPEED" '{printf "%1.0f", (curr + 500)}')
# deactivate mbpfan
toggle_mbpfan "true"
if [[ $NEXT_SPEED -lt $MAX_FAN ]]; then
echo $NEXT_SPEED > "$FAN_OUT"
else
echo $MAX_FAN > "$FAN_OUT"
fi
}
function decrease_fan() {
CURR_SPEED=$(cat $FAN_DIR/fan1_output)
NEXT_SPEED=$(echo - | awk -v curr="$CURR_SPEED" '{printf "%1.0f", (curr - 500)}')
# deactivate mbpfan
toggle_mbpfan "true"
if [[ $NEXT_SPEED -gt $MIN_FAN ]]; then
echo $NEXT_SPEED > "$FAN_OUT"
else
# no reason to ever this low.
# let the system take back over, since the user probably forgot
toggle_mbpfan "false"
fi
}
while getopts ":idt" opt; do
case ${opt} in
t) toggle_mbpfan
;;
i) increase_fan
;;
d) decrease_fan
;;
\? )
;;
esac
done
|