-
Notifications
You must be signed in to change notification settings - Fork 0
/
stratux_opts
executable file
·215 lines (186 loc) · 4.63 KB
/
stratux_opts
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
# V1.4 by Stefan Fischer 2023-04-23
# idle pwr usage for rpi 3B 230 mA
# idle pwr usage for rpi 3B+ 450 mA
function fil_bck {
if [ "$1" != "" ] && [ -f "$1" ]; then
if [ "$2" != "" ]; then _fil="$1.$2"; else _fil="$1.old"; fi
cp "$1" "$_fil"
fi
}
function setup_swinst {
apt-get -qy update
apt-get -qy install cpufrequtils
return 0
}
function setup_cfg {
fn="/boot/config.txt"
tm="# define minimum freq. for energy saving (used by cpu governor)"
grep -Fq "$tm" "$fn"
_ret=$?
if [ "$_ret" != "0" ]; then
# modify config file only once, by checking tm entry
fil_bck "$fn" "$bckext"
echo " " >> $fn
echo "# Disable the ACT and PWR LED (save energy)" >> $fn
echo "dtparam=act_led_trigger=none" >> $fn
echo "dtparam=act_led_activelow=off" >> $fn
echo "dtparam=pwr_led_trigger=none" >> $fn
echo "dtparam=pwr_led_activelow=off" >> $fn
echo "$tm" >> $fn
echo "# use turbo speed for 20sec to speed up boot process" >> $fn
echo "initial_turbo=20" >> $fn
echo "force_turbo=0" >> $fn
echo "arm_freq_min=250" >> $fn
echo "core_freq_min=100" >> $fn
echo "sdram_freq_min=150" >> $fn
echo "over_voltage_min=0" >> $fn
echo " " >> $fn
echo "# Disable Bluetooth" >> $fn
echo "dtoverlay=pi3-disable-bt" >> $fn
echo " " >> $fn
echo "hdmi_blanking=2" >> $fn
echo "# fan control via PWM, use GPIO18 / HWpin 12" >> $fn
echo "# fan control via dtoverlay gpio-fan, use e.g. GPIO17" >> $fn
echo "#dtoverlay=gpio-fan,gpiopin=17,temp=60000" >> $fn
fi
return 0
}
function disable_svcfil {
systemctl disable $snam.service
_ret=$?
return $_ret
}
function setup_svcfil {
# create service file for automatic startup
fil="/lib/systemd/system/$snam.service"
cat <<EOF > "$fil"
[Unit]
Description=$snam
[Service]
Type=oneshot
WorkingDirectory=/usr/local/sbin
ExecStart=/usr/local/sbin/$snam start
[Install]
WantedBy=multi-user.target
EOF
chmod 644 "$fil"
systemctl daemon-reload
systemctl enable $snam.service
_ret=$?
return $_ret
}
function disable_bt {
# will save: ~10mA for Blutooth
systemctl disable hciuart.service
systemctl disable bluealsa.service
systemctl disable bluetooth.service
_ret=$?
return $_ret
}
function enable_bt {
systemctl enable hciuart.service
systemctl enable bluealsa.service
systemctl enable bluetooth.service
_ret=$?
return $_ret
}
function enable_pwrsave {
# enable pwr save, LEDs off, HDMI port off, set cpu to lower freq
# will save: ~5mA per LED and ~25mA HDMI
_ret=0
if [ "$1" == "" ] || [ "$1" == "led" ]; then
echo 0 | tee /sys/class/leds/ACT/brightness > /dev/null
echo 0 | tee /sys/class/leds/PWR/brightness > /dev/null
fi
if [ "$1" == "" ] || [ "$1" == "hdmi" ]; then
/usr/bin/tvservice -o > /dev/null
_ret=$?
fi
if [ "$1" == "" ] || [ "$1" == "eth" ]; then
ifconfig eth0 down
_ret=$?
fi
if [ "$1" == "" ] || [ "$1" == "gov" ]; then
/usr/bin/cpufreq-set -g powersave
_ret=$?
fi
return $_ret
}
function disable_pwrsave {
# disable pwr save
_ret=0
if [ "$1" == "" ] || [ "$1" == "led" ]; then
echo 1 | tee /sys/class/leds/ACT/brightness > /dev/null
echo 1 | tee /sys/class/leds/PWR/brightness > /dev/null
fi
if [ "$1" == "" ] || [ "$1" == "hdmi" ]; then
/usr/bin/tvservice -p > /dev/null
_ret=$?
fi
if [ "$1" == "" ] || [ "$1" == "eth" ]; then
ifconfig eth0 up
_ret=$?
fi
if [ "$1" == "" ] || [ "$1" == "gov" ]; then
/usr/bin/cpufreq-set -g performance
_ret=$?
fi
return $_ret
}
function script_update {
cd /usr/local/sbin
wget -qN https://raw.githubusercontent.com/rudiratlos/stratux/master/$snam
_ret=$?
chmod +x $snam
return $_ret
}
snam="${0##*/}"
bckext=`date +"%Y%m%d%H%M%S"`
ret=0
case "$1" in
setup)
if [ "$2" == "" ] || [ "$2" == "sw" ]; then
setup_swinst "$2"
ret=$?
fi
if [ "$2" == "" ] || [ "$2" == "svc" ]; then
setup_svcfil "$2"
ret=$?
fi
if [ "$2" == "" ] || [ "$2" == "bt" ]; then
disable_bt "$2"
ret=$?
fi
if [ "$2" == "" ] || [ "$2" == "cfg" ]; then
setup_cfg "$2"
ret=$?
fi
;;
remove)
disable_svcfil
enable_bt
disable_pwrsave
;;
start)
enable_pwrsave "$2"
ret=$?
;;
stop)
disable_pwrsave "$2"
ret=$?
;;
update)
script_update "$2"
ret=$?
;;
status)
/usr/bin/tvservice -s
/usr/bin/cpufreq-info "$2"
ret=$?
;;
*)
echo "Usage: $snam start | stop | status | setup [sw|svc|bt|cfg] | remove | update"
echo " setup or remove option can only be run, if stratux filesystem is writeable"
esac
exit $ret