Skip to content

Commit 094ecef

Browse files
committed
Fix script formatting
1 parent 87efee8 commit 094ecef

File tree

3 files changed

+118
-118
lines changed

3 files changed

+118
-118
lines changed

module/post-fs-data.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ sleep 2
44

55
# Check if BBR is available
66
if grep -qw bbr /proc/sys/net/ipv4/tcp_available_congestion_control; then
7-
CONG=bbr
7+
CONG=bbr
88
else
9-
CONG=cubic
9+
CONG=cubic
1010
fi
1111

1212
# Set congestion control
1313
if command -v sysctl >/dev/null 2>&1; then
14-
sysctl -w net.ipv4.tcp_congestion_control=$CONG
14+
sysctl -w net.ipv4.tcp_congestion_control=$CONG
1515
else
16-
echo "$CONG" > /proc/sys/net/ipv4/tcp_congestion_control 2>/dev/null
16+
echo "$CONG" > /proc/sys/net/ipv4/tcp_congestion_control 2>/dev/null
1717
fi
1818

1919
# IPv4 TCP optimizations

module/service.sh

Lines changed: 102 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,56 @@ congestion_algorithms=$(cat /proc/sys/net/ipv4/tcp_available_congestion_control)
1111

1212
# On startup, reset description to default
1313
if [ -f "$MODPATH/module.prop" ]; then
14-
default_desc="TCP Optimisations & update tcp_cong_algo based on interface"
15-
sed -i '/^description=/d' "$MODPATH/module.prop" && echo "description=$default_desc" >> "$MODPATH/module.prop"
14+
default_desc="TCP Optimisations & update tcp_cong_algo based on interface"
15+
sed -i '/^description=/d' "$MODPATH/module.prop" && echo "description=$default_desc" >> "$MODPATH/module.prop"
1616
fi
1717

1818
update_description() {
19-
local iface="$1"
20-
local algo="$2"
21-
local icon="⁉️"
19+
local iface="$1"
20+
local algo="$2"
21+
local icon="⁉️"
2222

23-
case "$iface" in
24-
Wi-Fi) icon="🛜" ;;
25-
Cellular) icon="📶" ;;
26-
esac
23+
case "$iface" in
24+
Wi-Fi) icon="🛜" ;;
25+
Cellular) icon="📶" ;;
26+
esac
2727

28-
local desc="TCP Optimisations & update tcp_cong_algo based on interface | iface: $iface $icon | algo: $algo"
29-
sed -i '/^description=/d' "$MODPATH/module.prop" && echo "description=$desc" >> "$MODPATH/module.prop"
28+
local desc="TCP Optimisations & update tcp_cong_algo based on interface | iface: $iface $icon | algo: $algo"
29+
sed -i '/^description=/d' "$MODPATH/module.prop" && echo "description=$desc" >> "$MODPATH/module.prop"
3030
}
3131

3232
kill_tcp_connections() {
33-
if [ -f "$MODPATH/kill_connections" ]; then
34-
log_print "Killing all TCP connections (IPv4 and IPv6) due to congestion change"
35-
36-
# Kill all connections
37-
ss -K
38-
fi
33+
if [ -f "$MODPATH/kill_connections" ]; then
34+
log_print "Killing all TCP connections (IPv4 and IPv6) due to congestion change"
35+
36+
# Kill all connections
37+
ss -K
38+
fi
3939
}
4040

4141
set_max_initcwnd_initrwnd() {
42-
local active_iface="$1"
43-
if [ -f "$MODPATH/initcwnd_initrwnd" ]; then
44-
maxBufferSize=$(cat /proc/sys/net/ipv4/tcp_rmem | awk '{print $3}')
45-
mtu=$(ip link show "$active_iface" | awk '/mtu/ {print $NF}')
46-
mtu=$((mtu - 40))
47-
maxInitrwndValue=$((maxBufferSize / mtu))
48-
local applied
49-
applied=0
50-
51-
while IFS= read -r line; do
52-
run_as_su "/system/bin/ip route change $line initcwnd 10 initrwnd $maxInitrwndValue"
53-
if [ $? -eq 0 ]; then
54-
applied=1
55-
fi
56-
done <<EOF
42+
local active_iface="$1"
43+
if [ -f "$MODPATH/initcwnd_initrwnd" ]; then
44+
maxBufferSize=$(cat /proc/sys/net/ipv4/tcp_rmem | awk '{print $3}')
45+
mtu=$(ip link show "$active_iface" | awk '/mtu/ {print $NF}')
46+
mtu=$((mtu - 40))
47+
maxInitrwndValue=$((maxBufferSize / mtu))
48+
local applied
49+
applied=0
50+
51+
while IFS= read -r line; do
52+
run_as_su "/system/bin/ip route change $line initcwnd 10 initrwnd $maxInitrwndValue"
53+
if [ $? -eq 0 ]; then
54+
applied=1
55+
fi
56+
done <<EOF
5757
$(run_as_su "/system/bin/ip route show | grep \"dev $active_iface\"")
5858
EOF
5959

60-
if [ "$applied" -eq 1 ]; then
61-
log_print "Setting initcwnd = 10; initrwnd = $maxInitrwndValue!"
62-
fi
63-
fi
60+
if [ "$applied" -eq 1 ]; then
61+
log_print "Setting initcwnd = 10; initrwnd = $maxInitrwndValue!"
62+
fi
63+
fi
6464
}
6565

6666
set_qdisc() {
@@ -74,56 +74,56 @@ set_qdisc() {
7474
}
7575

7676
set_congestion() {
77-
local algo="$1"
78-
local mode="$2"
79-
if echo "$congestion_algorithms" | grep -qw "$algo"; then
80-
echo "$algo" > /proc/sys/net/ipv4/tcp_congestion_control 2>/dev/null
81-
log_print "Applied congestion control: $algo ($mode)"
82-
kill_tcp_connections
83-
update_description "$mode" "$algo"
84-
else
85-
log_print "Unavailable algorithm: $algo"
86-
fi
77+
local algo="$1"
78+
local mode="$2"
79+
if echo "$congestion_algorithms" | grep -qw "$algo"; then
80+
echo "$algo" > /proc/sys/net/ipv4/tcp_congestion_control 2>/dev/null
81+
log_print "Applied congestion control: $algo ($mode)"
82+
kill_tcp_connections
83+
update_description "$mode" "$algo"
84+
else
85+
log_print "Unavailable algorithm: $algo"
86+
fi
8787
}
8888

8989
get_active_iface() {
90-
iface=$(ip route get 192.0.2.1 2>/dev/null | awk '/dev/ {for(i=1;i<=NF;i++) if($i=="dev") print $(i+1)}')
91-
echo "$iface"
90+
iface=$(ip route get 192.0.2.1 2>/dev/null | awk '/dev/ {for(i=1;i<=NF;i++) if($i=="dev") print $(i+1)}')
91+
echo "$iface"
9292
}
9393

9494
apply_wifi_settings() {
95-
local iface="$1"
96-
local applied=0
97-
for algo in $congestion_algorithms; do
98-
if [ -f "$MODPATH/wlan_$algo" ]; then
99-
set_congestion "$algo" "Wi-Fi"
95+
local iface="$1"
96+
local applied=0
97+
for algo in $congestion_algorithms; do
98+
if [ -f "$MODPATH/wlan_$algo" ]; then
99+
set_congestion "$algo" "Wi-Fi"
100100
if [ "$algo" = "bbr" ]; then
101101
set_qdisc "$iface" "fq_codel"
102102
fi
103-
set_max_initcwnd_initrwnd "$iface"
104-
applied=1
105-
break
106-
fi
107-
done
108-
[ "$applied" -eq 0 ] && set_congestion cubic "Wi-Fi" && set_max_initcwnd_initrwnd "$iface"
103+
set_max_initcwnd_initrwnd "$iface"
104+
applied=1
105+
break
106+
fi
107+
done
108+
[ "$applied" -eq 0 ] && set_congestion cubic "Wi-Fi" && set_max_initcwnd_initrwnd "$iface"
109109
return $applied
110110
}
111111

112112
apply_cellular_settings() {
113-
local iface="$1"
114-
local applied=0
115-
for algo in $congestion_algorithms; do
116-
if [ -f "$MODPATH/rmnet_data_$algo" ]; then
117-
set_congestion "$algo" "Cellular"
113+
local iface="$1"
114+
local applied=0
115+
for algo in $congestion_algorithms; do
116+
if [ -f "$MODPATH/rmnet_data_$algo" ]; then
117+
set_congestion "$algo" "Cellular"
118118
if [ "$algo" = "bbr" ]; then
119119
set_qdisc "$iface" "fq_codel"
120120
fi
121-
set_max_initcwnd_initrwnd "$iface"
122-
applied=1
123-
break
124-
fi
125-
done
126-
[ "$applied" -eq 0 ] && set_congestion cubic "Cellular" && set_max_initcwnd_initrwnd "$iface"
121+
set_max_initcwnd_initrwnd "$iface"
122+
applied=1
123+
break
124+
fi
125+
done
126+
[ "$applied" -eq 0 ] && set_congestion cubic "Cellular" && set_max_initcwnd_initrwnd "$iface"
127127
return $applied
128128
}
129129

@@ -157,47 +157,47 @@ vowifi_start_time=0
157157

158158
while true; do
159159
current_time=$(date +%s)
160-
iface=$(get_active_iface)
160+
iface=$(get_active_iface)
161161
[ -z "$iface" ] && sleep 5 && continue
162162

163-
new_mode="none"
164-
case "$iface" in
165-
wlan*) new_mode="Wi-Fi" ;;
166-
rmnet*|ccmni*) new_mode="Cellular" ;;
167-
*) new_mode="none" ;;
168-
esac
169-
170-
if [ "$new_mode" != "$last_mode" ] || [ -f "$MODPATH/force_apply" ]; then
171-
if [ "$((current_time - change_time))" -ge "$DEBOUNCE_TIME" ]; then
172-
applied=0
173-
if [ "$new_mode" = "Wi-Fi" ]; then
163+
new_mode="none"
164+
case "$iface" in
165+
wlan*) new_mode="Wi-Fi" ;;
166+
rmnet*|ccmni*) new_mode="Cellular" ;;
167+
*) new_mode="none" ;;
168+
esac
169+
170+
if [ "$new_mode" != "$last_mode" ] || [ -f "$MODPATH/force_apply" ]; then
171+
if [ "$((current_time - change_time))" -ge "$DEBOUNCE_TIME" ]; then
172+
applied=0
173+
if [ "$new_mode" = "Wi-Fi" ]; then
174174
# Start waiting for VoWiFi
175-
vowifi_pending=1
176-
vowifi_start_time="$current_time"
177-
elif [ "$new_mode" = "Cellular" ]; then
175+
vowifi_pending=1
176+
vowifi_start_time="$current_time"
177+
elif [ "$new_mode" = "Cellular" ]; then
178178
vowifi_pending=0
179-
apply_cellular_settings "$iface"
180-
fi
179+
apply_cellular_settings "$iface"
180+
fi
181181
last_mode="$new_mode"
182182
change_time="$current_time"
183183
rm -f "$MODPATH/force_apply"
184-
fi
185-
fi
184+
fi
185+
fi
186186

187187
# === Wi-Fi Pending Logic ===
188-
if [ "$new_mode" = "Wi-Fi" ] && [ "$vowifi_pending" -eq 1 ]; then
188+
if [ "$new_mode" = "Wi-Fi" ] && [ "$vowifi_pending" -eq 1 ]; then
189189
vowifi=$(get_wifi_calling_state)
190190
vowifi=${vowifi:-1}
191-
if [ "$((current_time - vowifi_start_time))" -ge "$VOWIFI_CONNECT_TIME" ]; then
192-
log_print "[INFO] VoWiFi timeout reached. Applying Wi-Fi settings..."
193-
vowifi_pending=0
194-
apply_wifi_settings "$iface"
195-
elif [ "$vowifi" -eq 0 ]; then
196-
log_print "[INFO] VoWiFi activated. Applying Wi-Fi settings..."
197-
vowifi_pending=0
198-
apply_wifi_settings "$iface"
199-
fi
200-
fi
201-
202-
sleep 5
191+
if [ "$((current_time - vowifi_start_time))" -ge "$VOWIFI_CONNECT_TIME" ]; then
192+
log_print "[INFO] VoWiFi timeout reached. Applying Wi-Fi settings..."
193+
vowifi_pending=0
194+
apply_wifi_settings "$iface"
195+
elif [ "$vowifi" -eq 0 ]; then
196+
log_print "[INFO] VoWiFi activated. Applying Wi-Fi settings..."
197+
vowifi_pending=0
198+
apply_wifi_settings "$iface"
199+
fi
200+
fi
201+
202+
sleep 5
203203
done

module/utils.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ if [ ! -f "$FLAGFILE" ]; then
1313
fi
1414

1515
log_print() {
16-
message="$1"
16+
message="$1"
1717

18-
timestamp=$(date +'%Y-%m-%d %H:%M:%S')
19-
echo "$timestamp - $message" >> "$LOGFILE"
18+
timestamp=$(date +'%Y-%m-%d %H:%M:%S')
19+
echo "$timestamp - $message" >> "$LOGFILE"
2020

21-
line_count=$(wc -l < "$LOGFILE" 2>/dev/null)
22-
if [ "$line_count" -gt "$MAX_LOG_LINES" ]; then
23-
tail -n "$((MAX_LOG_LINES / 2))" "$LOGFILE" > "${LOGFILE}.tmp"
24-
mv "${LOGFILE}.tmp" "$LOGFILE"
25-
fi
21+
line_count=$(wc -l < "$LOGFILE" 2>/dev/null)
22+
if [ "$line_count" -gt "$MAX_LOG_LINES" ]; then
23+
tail -n "$((MAX_LOG_LINES / 2))" "$LOGFILE" > "${LOGFILE}.tmp"
24+
mv "${LOGFILE}.tmp" "$LOGFILE"
25+
fi
2626
}
2727

2828
run_as_su() {
29-
local cmd="$*"
30-
su -c "$cmd"
31-
local status=$?
32-
return $status
29+
local cmd="$*"
30+
su -c "$cmd"
31+
local status=$?
32+
return $status
3333
}
3434

3535
get_wifi_calling_state() {

0 commit comments

Comments
 (0)