Skip to content
This repository was archived by the owner on Feb 28, 2023. It is now read-only.

Commit b6979ae

Browse files
author
llycoris
committed
fix: if failed 'cgroup_limit', can't run iptables, rebase scripts
1 parent 9b4bc61 commit b6979ae

13 files changed

Lines changed: 239 additions & 100 deletions

CHANGELOG.md

100644100755
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
## Changelog v1.13.1
2-
- Update Kernel (opsional) free you can change other Clash kernel
3-
- Remove unused scripts
4-
- Fix Auto-Update Kernel Clash
1+
## Changelog v1.13.2
2+
- fix: if failed 'cgroup_limit', can't run iptables, rebase scripts
3+
- add: mosdns
54

65
[![API](https://img.shields.io/badge/API-19%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=19)
76
[![RELEASES](https://img.shields.io/github/downloads/taamarin/ClashforMagisk/total.svg)](https://github.com/taamarin/ClashforMagisk/releases)

customize.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ tar -xjf ${MODPATH}/binary/${ARCH}.tar.bz2 -C ${clash_data_dir_kernel}/&& echo "
109109
mv ${clash_data_dir_kernel}/setcap ${MODPATH}${bin_path}/
110110
mv ${clash_data_dir_kernel}/getpcaps ${MODPATH}${bin_path}/
111111
mv ${clash_data_dir_kernel}/getcap ${MODPATH}${bin_path}/
112-
mv ${clash_data_dir}/scripts/config.yaml ${clash_data_dir}/
113112
mv ${clash_data_dir}/scripts/clash.config ${clash_data_dir}/
114-
mv ${clash_data_dir}/scripts/proxy-provider ${clash_data_dir}/
113+
mv ${clash_data_dir}/scripts/mosdns ${clash_data_dir}/
114+
mv ${clash_data_dir}/mosdns/mosdns ${clash_data_dir_kernel}/
115115

116116
if [ ! -f "${bin_path}/ss" ] ; then
117117
mv ${clash_data_dir_kernel}/ss ${MODPATH}${bin_path}/

module.prop

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
id=ClashForMagisk
22
name=Clash for Magisk
3-
version=v1.13.1
4-
versionCode=20220920
3+
version=v1.13.2
4+
versionCode=20220922
55
author=t🍀amarin
66
description= Use iptables to support Clash's transparent proxy. Hey, damn half-crippled Android!!!
77
updateJson=https://github.com/taamarin/ClashforMagisk/raw/master/update.json

scripts/clash.config

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ busybox_path="/data/adb/magisk/busybox"
99
# IPV6
1010
ipv6=$(grep "ipv6" /data/clash/template | ${busybox_path} awk -F ': ' '{print $2}' | head -1)
1111

12-
#0 is to start only clash, 1 is clash+mosdns
13-
run_mode="0"
14-
1512
# ID
1613
pref_id="5000"
1714
mark_id="233"
@@ -28,6 +25,8 @@ nat_kernel="false"
2825
filter_local="false"
2926
monitor_local_ip="true"
3027

28+
#0 is to start only clash, 1 is clash+mosdns
29+
run_mode="0"
3130
# SELECT META OR PREMIUM
3231
use_premium="false"
3332
# DOWNLOAD LANGGANAN/CONFIG
@@ -56,47 +55,48 @@ Cgroup_memory_limit="20M"
5655
Clash_bin_name="clash"
5756
Clash_data_dir="/data/clash"
5857
# DIRECTORY TEMPLATE
59-
Clash_dns="/data/clash/template"
60-
# CMD
61-
cmd_run="/data/clash/run/cmdRunning"
58+
Clash_template="$Clash_data_dir/template"
6259
# DIRECTORY LOG/SERVICE
63-
Clash_run_path="/data/clash/run"
64-
logs_service="/data/clash/run/service.log"
65-
CFM_logs_file="/data/clash/run/run.logs"
66-
CFM_logs_service="/data/clash/run/service.log"
60+
Clash_run_path="$Clash_data_dir/run"
61+
logs_service="$Clash_run_path/service.log"
62+
CFM_logs_file="$Clash_run_path/run.logs"
63+
# CMD
64+
cmd_run="$Clash_run_path/cmdRunning"
6765
# DIRECTORY PID
68-
Clash_pid_file="/data/clash/run/clash.pid"
66+
Clash_pid_file="$Clash_run_path/clash.pid"
6967
# DIRECTORY KERNEL CLASH
70-
Clash_bin_path="/data/clash/kernel/${Clash_bin_name}"
68+
Clash_bin="$Clash_data_dir/kernel"
69+
Clash_lib="$Clash_bin/lib"
70+
Clash_bin_path="$Clash_bin/${Clash_bin_name}"
7171
# LIB KERNEL
72-
Clash_Premium="/data/clash/kernel/lib/Clash.Premium"
73-
Clash_Meta="/data/clash/kernel/lib/Clash.Meta"
72+
Clash_Premium="$Clash_lib/Clash.Premium"
73+
Clash_Meta="$Clash_lib/Clash.Meta"
7474
# DIRECTORY SCRIPTS
75-
Clash_scripts_dir="/data/clash/scripts"
75+
Clash_scripts_dir="$Clash_data_dir/scripts"
7676

7777
# CUSTOM CONFIG.YAML
7878
use_config="false"
7979
if [ "${use_config}" == "false" ]; then
80-
Clash_config_file="/data/clash/config.yaml"
80+
Clash_config_file="$Clash_data_dir/config.yaml"
8181
else
82-
Clash_config_file="/data/clash/${use_config}"
82+
Clash_config_file="$Clash_data_dir/${use_config}"
8383
fi
8484
# TEMPORARY CONFIG.YAML
85-
temporary_config_file="/data/clash/run/config.yaml"
85+
temporary_config_file="$Clash_run_path/config.yaml"
8686
# DIRECTORY PACKAGE
87-
appuid_file="/data/clash/run/appuid.list"
88-
filter_packages_file="/data/clash/packages.list"
87+
appuid_file="$Clash_run_path/appuid.list"
88+
filter_packages_file="$Clash_data_dir/packages.list"
8989
system_packages_file="/data/system/packages.list"
9090

9191
#MOSDNS
9292
# moddns is a plug-in DNS forwarder. Users can splicing plug-ins as needed to customize their own DNS processing logic.
93-
mosdns_data_dir="/data/clash/mosdns"
94-
mosdns_bin_path="${mosdns_data_dir}/mosdns"
93+
mosdns_data_dir="$Clash_data_dir/mosdns"
94+
mosdns_bin_path="$Clash_bin/mosdns"
9595
mosdns_config_file="${mosdns_data_dir}/config.yaml"
9696

9797
# AUTO UPDATE KERNEL
9898
schedule_update_core="false"
99-
url_meta="https://cdn.githubjs.cf/MetaCubeX/Clash.Meta/releases"
99+
url_meta="https://cdn.githubjs.cf/taamarin/Clash.Meta/releases"
100100
url_premium="https://cdn.githubjs.cf/Dreamacro/clash/releases"
101101
arm=$(uname -m)
102102
if [ "${use_premium}" == "false" ]; then
@@ -122,15 +122,15 @@ else
122122
fi
123123
# SETTING UPDATE GEOX
124124
auto_updateGeoX="true"
125-
Clash_geodata_mode=$(grep "geodata-mode" ${Clash_dns} | ${busybox_path} awk -F ': ' '{print $2}')
125+
Clash_geodata_mode=$(grep "geodata-mode" ${Clash_template} | ${busybox_path} awk -F ': ' '{print $2}')
126126
if [ "${Clash_geodata_mode}" == "false" ]; then
127-
Clash_GeoIP_file="/data/clash/Country.mmdb"
127+
Clash_GeoIP_file="$Clash_data_dir/Country.mmdb"
128128
GeoIP_dat_url="https://cdn.githubjs.cf/Hackl0us/GeoIP2-CN/raw/release/Country.mmdb"
129129
else
130-
Clash_GeoIP_file="/data/clash/GeoIP.dat"
130+
Clash_GeoIP_file="$Clash_data_dir/GeoIP.dat"
131131
GeoIP_dat_url="https://cdn.githubjs.cf/v2fly/geoip/releases/latest/download/geoip-only-cn-private.dat"
132132
fi
133-
Clash_GeoSite_file="/data/clash/GeoSite.dat"
133+
Clash_GeoSite_file="$Clash_data_dir/GeoSite.dat"
134134
GeoSite_url="https://cdn.githubjs.cf/taamarin/v2ray-rules-dat/raw/release/GeoSite.dat"
135135
# CLASH PERMISSIONS
136136
Clash_permissions="6755"
@@ -152,14 +152,14 @@ fi
152152
# GREP FILE/PORT
153153
Clash_user=$(echo ${Clash_user_group} | ${busybox_path} awk -F ':' '{print $1}')
154154
Clash_group=$(echo ${Clash_user_group} | ${busybox_path} awk -F ':' '{print $2}')
155-
Clash_tproxy_port=$(grep "tproxy-port" ${Clash_dns} | ${busybox_path} awk -F ': ' '{print $2}')
156-
Clash_dns_port=$(grep "listen" ${Clash_dns} | ${busybox_path} awk -F ':' '{print $3}')
157-
Clash_tun_status=$(${busybox_path} awk -F ': ' '/^tun: *$/{getline; print $2}' ${Clash_dns})
158-
Clash_auto_route=$(grep "auto-route" ${Clash_dns} | ${busybox_path} awk -F ': ' '{print $2}')
159-
Clash_auto_detect_interface=$(grep "auto-detect-interface" ${Clash_dns} | ${busybox_path} awk -F ': ' '{print $2}')
160-
Clash_tcp_concurrent=$(grep "tcp-concurrent" ${Clash_dns} | ${busybox_path} awk -F ':' '{print $2}')
161-
Clash_enhanced_mode=$(grep "enhanced-mode" ${Clash_dns} | ${busybox_path} awk -F ': ' '{print $2}')
162-
Clash_stack_mode=$(grep "stack" ${Clash_dns} | ${busybox_path} awk -F ': ' '{print $2}')
155+
Clash_tproxy_port=$(grep "tproxy-port" ${Clash_template} | ${busybox_path} awk -F ': ' '{print $2}')
156+
Clash_dns_port=$(grep "listen" ${Clash_template} | ${busybox_path} awk -F ':' '{print $3}')
157+
Clash_tun_status=$(${busybox_path} awk -F ': ' '/^tun: *$/{getline; print $2}' ${Clash_template})
158+
Clash_auto_route=$(grep "auto-route" ${Clash_template} | ${busybox_path} awk -F ': ' '{print $2}')
159+
Clash_auto_detect_interface=$(grep "auto-detect-interface" ${Clash_template} | ${busybox_path} awk -F ': ' '{print $2}')
160+
Clash_tcp_concurrent=$(grep "tcp-concurrent" ${Clash_template} | ${busybox_path} awk -F ':' '{print $2}')
161+
Clash_enhanced_mode=$(grep "enhanced-mode" ${Clash_template} | ${busybox_path} awk -F ': ' '{print $2}')
162+
Clash_stack_mode=$(grep "stack" ${Clash_template} | ${busybox_path} awk -F ': ' '{print $2}')
163163

164164
# INTERNET IPV4 & IPV6
165165
reserved_ip=(0.0.0.0/8 10.0.0.0/8 100.64.0.0/10 127.0.0.0/8 169.254.0.0/16 172.16.0.0/12 192.0.0.0/24 192.0.2.0/24 192.88.99.0/24 192.168.0.0/16 198.51.100.0/24 203.0.113.0/24 224.0.0.0/4 233.252.0.0/24 240.0.0.0/4 255.255.255.255/32)

scripts/clash.iptables

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ while getopts ":sk" signal ; do
374374
rm -rf /data/clash/run/config.logs
375375
echo $date_log"info: Clash service is running (PID: `cat ${Clash_pid_file}`)" >> ${CFM_logs_file}
376376
echo $date_log"info: Connect" >> ${CFM_logs_file}
377+
378+
# svc data disable && sleep 2
379+
# svc data enable
377380
;;
378381
k)
379382
if [ "${Clash_tun_status}" == "false" ]; then

scripts/clash.iptables.bak

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -451,43 +451,42 @@ while getopts ":sk" signal ; do
451451
case ${signal} in
452452
s)
453453
if [ "${Clash_tun_status}" == "false" ]; then
454-
flush_rule_rules && flush_rules &>> /data/clash/run/service.log
454+
flush_rule_rules && flush_rules &>> $logs_service
455455
echo $date_log"warn: scripts refresh Iptables tproxy" >> ${CFM_logs_file}
456456
sleep 0.5
457-
create_rule_rules && apply_rules &>> /data/clash/run/service.log
457+
create_rule_rules && apply_rules &>> $logs_service
458458
echo $date_log"info: scripts Iptables tproxy diterapkan" >> ${CFM_logs_file}
459459
else
460460
rm -rf /data/clash/run/lastwifi
461461
rm -rf /data/clash/run/lastmobile
462462
if [ "${Clash_auto_detect_interface}" == "true" ]; then
463-
stop_tun_portabel &>> /data/clash/run/service.log
463+
stop_tun_portabel &>> $logs_service
464464
echo $date_log"warn: refresh tun diterapkan" >> ${CFM_logs_file}
465465
sleep 0.5
466-
start_tun_portabel &>> /data/clash/run/service.log
466+
start_tun_portabel &>> $logs_service
467467
echo $date_log"info: tun diterapkan" >> ${CFM_logs_file}
468468
else
469-
stop_tun &>> /data/clash/run/service.log
469+
stop_tun &>> $logs_service
470470
echo $date_log"warn: refresh scripts Iptables tun" >> ${CFM_logs_file}
471471
sleep 0.5
472-
start_tun &>> /data/clash/run/service.log
472+
start_tun &>> $logs_service
473473
echo $date_log"info: scripts Iptables tun diterapkan" >> ${CFM_logs_file}
474474
fi
475475
fi
476476
rm -rf /data/clash/run/config.logs
477-
rm -rf /data/clash/run/cmdRunning
478477
echo $date_log"info: Clash service is running (PID: `cat ${Clash_pid_file}`)" >> ${CFM_logs_file}
479478
echo $date_log"info: Connect" >> ${CFM_logs_file}
480479
;;
481480
k)
482481
if [ "${Clash_tun_status}" == "false" ]; then
483-
flush_rule_rules && flush_rules &>> /data/clash/run/service.log
482+
flush_rule_rules && flush_rules &>> $logs_service
484483
echo $date_log"warn: scripts Iptables tproxy dihapus" >> ${CFM_logs_file}
485484
else
486485
if [ "${Clash_auto_detect_interface}" == "true" ]; then
487-
stop_tun_portabel &>> /data/clash/run/service.log
486+
stop_tun_portabel &>> $logs_service
488487
echo $date_log"warn: tun dihapus," >> ${CFM_logs_file}
489488
else
490-
stop_tun &>> /data/clash/run/service.log
489+
stop_tun &>> $logs_service
491490
echo $date_log"warn: scripts Iptables tun dihapus," >> ${CFM_logs_file}
492491
fi
493492
fi

scripts/clash.service

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ dow_config() {
2121

2222
date_clash() {
2323
echo -n "" > ${CFM_logs_file} && echo "${date_day}" >> ${CFM_logs_file}
24-
echo "Clash for Magisk v1.13.1" > /dev/null
24+
echo "Clash for Magisk v1.13.2" >> ${CFM_logs_file}
2525
}
2626

2727
replace_kernel() {
28-
chmod 0755 /data/clash/kernel/lib/*
29-
rm -rf /data/clash/kernel/clash
28+
chmod 0755 ${Clash_lib}/*
29+
rm -rf ${Clash_bin}/clash
3030
err="failed to replace kernel。"
3131
if [ "${use_premium}" == "true" ]; then
32-
cp -f ${Clash_Premium} /data/clash/kernel/clash \
32+
cp -f ${Clash_Premium} ${Clash_bin}/clash \
3333
&& echo "" || echo $date_log"err: ${err}" >> ${CFM_logs_file}
3434
else
35-
cp -f ${Clash_Meta} /data/clash/kernel/clash \
35+
cp -f ${Clash_Meta} ${Clash_bin}/clash \
3636
&& echo "" || echo $date_log"err: ${err}" >> ${CFM_logs_file}
3737
fi
3838
}
@@ -56,17 +56,17 @@ use_clash() {
5656
}
5757

5858
temporary_config_file() {
59-
if [ -f "${Clash_dns}" ] ; then
59+
if [ -f "${Clash_template}" ] ; then
6060
if [ -f "${Clash_config_file}" ] ; then
61-
cp -f ${Clash_dns} ${temporary_config_file}.swp && echo "\n" >> ${temporary_config_file}.swp
61+
cp -f ${Clash_template} ${temporary_config_file}.swp && echo "\n" >> ${temporary_config_file}.swp
6262
sed -n -E '/^proxies:$/,$p' ${Clash_config_file} >> ${temporary_config_file}.swp
6363
sed -i '/^[ ]*$/d' ${temporary_config_file}.swp
6464
else
6565
echo $date_log"err: files ${Clash_config_file} not found !!!" >> ${CFM_logs_file}
6666
exit 1
6767
fi
6868
else
69-
echo $date_log"err: files ${Clash_dns} not found !!!" >> ${CFM_logs_file}
69+
echo $date_log"err: files ${Clash_template} not found !!!" >> ${CFM_logs_file}
7070
exit 1
7171
fi
7272

@@ -126,7 +126,7 @@ start_mosdns () {
126126
fi
127127
}
128128

129-
if ! [ -f "/data/clash/mosdns/mosdns" ] ; then
129+
if ! [ -f $mosdns_bin_path ] ; then
130130
echo ${date_log}"err: mosdns kernel is missing." >> ${CFM_logs_file}
131131
exit 1
132132
fi
@@ -184,28 +184,27 @@ start_clash() {
184184
fi
185185

186186
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" >> ${CFM_logs_file}
187+
directory_net="/proc/sys/net/ipv6/conf"
187188
if [ "${ipv6}" == "false" ] ; then
188-
echo 1 > /proc/sys/net/ipv6/conf/lo/disable_ipv6
189-
echo 1 > /proc/sys/net/ipv6/conf/default/disable_ipv6
189+
echo 1 > ${directory_net}/lo/disable_ipv6
190+
echo 1 > ${directory_net}/default/disable_ipv6
190191

191-
echo 0 > /proc/sys/net/ipv6/conf/all/accept_ra
192-
echo 0 > /proc/sys/net/ipv6/conf/wlan0/accept_ra
192+
echo 0 > ${directory_net}/all/accept_ra
193+
echo 0 > ${directory_net}/wlan0/accept_ra
193194

194-
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
195-
echo 1 > /proc/sys/net/ipv6/conf/wlan0/disable_ipv6
195+
echo 1 > ${directory_net}/all/disable_ipv6
196+
echo 1 > ${directory_net}/wlan0/disable_ipv6
196197
else
197-
echo 0 > /proc/sys/net/ipv6/conf/lo/disable_ipv6
198-
echo 0 > /proc/sys/net/ipv6/conf/default/disable_ipv6
198+
echo 0 > ${directory_net}/lo/disable_ipv6
199+
echo 0 > ${directory_net}/default/disable_ipv6
199200

200-
echo 1 > /proc/sys/net/ipv6/conf/all/accept_ra
201-
echo 1 > /proc/sys/net/ipv6/conf/wlan0/accept_ra
202-
203-
echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6
204-
echo 0 > /proc/sys/net/ipv6/conf/wlan0/disable_ipv6
205-
fi
201+
echo 1 > ${directory_net}/all/accept_ra
202+
echo 1 > ${directory_net}/wlan0/accept_ra
206203

204+
echo 0 > ${directory_net}/all/disable_ipv6
205+
echo 0 > ${directory_net}/wlan0/disable_ipv6
206+
fi
207207
use_clash
208-
209208
echo $date_log"info: config ${Clash_config_file}" >> ${CFM_logs_file}
210209
echo $date_log"info: Status ipv6: ${ipv6}" >> ${CFM_logs_file}
211210

@@ -241,12 +240,18 @@ start_clash() {
241240
echo $date_log"err: Clash kernel ${Clash_bin_path} not found !!!。" >> ${CFM_logs_file}
242241
exit 1
243242
fi
244-
245-
run_mosdns
246-
243+
if [ "${run_mode}" == "1" ]; then
244+
run_mosdns
245+
fi
247246
if [ -f ${temporary_config_file} ] ; then
248247
if (${Clash_bin_path} -v > /dev/null 2>&1) ; then
249248
run_clash
249+
# cgroup_limit
250+
if [ "${Cgroup_memory}" == "true" ] ; then
251+
if ! (${scripts_dir}/clash.tool -l) ; then
252+
echo -n ""
253+
fi
254+
fi
250255
else
251256
echo $date_log"err: kernel CFM error/broken/not supported ">> ${CFM_logs_file}
252257
exit 1
@@ -255,6 +260,7 @@ start_clash() {
255260
echo $date_log"err: ${Clash_config_file} not found。" >> ${CFM_logs_file}
256261
exit 1
257262
fi
263+
# RUN PORT DETEC
258264
sleep 0.5
259265
if [ "${port_detect}" == "true" ]; then
260266
if ! (${scripts_dir}/clash.tool -p) ; then
@@ -314,23 +320,10 @@ stop_clash() {
314320
rm -rf ${Clash_pid_file}
315321
}
316322

317-
cgroup_limit() {
318-
if [ "${Cgroup_memory_limit}" == "" ]; then
319-
return
320-
fi
321-
if [ "${Cgroup_memory_path}" == "" ]; then
322-
Cgroup_memory_path=$(mount | grep cgroup | ${busybox_path} awk '/memory/{print $3}' | head -1)
323-
fi
324-
mkdir -p "${Cgroup_memory_path}/clash"
325-
echo $(cat ${Clash_pid_file}) > "${Cgroup_memory_path}/clash/cgroup.procs"
326-
echo "${Cgroup_memory_limit}" > "${Cgroup_memory_path}/clash/memory.limit_in_bytes"
327-
}
328-
329323
while getopts ":sk" signal ; do
330324
case ${signal} in
331325
s)
332326
stop_clash &> $logs_service && start_clash &>> $logs_service
333-
cgroup_limit &>> $logs_service
334327
;;
335328
k)
336329
stop_clash &>> $logs_service

0 commit comments

Comments
 (0)