Skip to content

Commit

Permalink
change:
Browse files Browse the repository at this point in the history
- replace curl, with /data/adb/magisk/busybox wget
- fix tool download core
- remove mosdns
- optimize cfm service scripts
- update kernel
  • Loading branch information
twnesss committed Jan 13, 2023
1 parent 6e75808 commit 023e9d9
Show file tree
Hide file tree
Showing 18 changed files with 337 additions and 478 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ You can download the release [installer zip](https://github.com/taamarin/Clashfo
##### Change proxy mode
- Clash uses `TPROXY` transparent proxy `TCP + UDP` by default, if it detects that the device does not support `TPROXY`, it will automatically use `REDIRECT` to proxy only `TCP`

- Open `${MODDIR}/scripts/clash.config` file line [17-18](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L17-#L18), modify the value of `network_mode` to `TCP` or `MIXED `to use `REDIRECT` to proxy `TCP`, and `UDP` will not be proxied when `TUN` is not enabled in the Clash kernel
- Open `${MODDIR}/scripts/clash.config` file line [14-15](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L14-#L15), modify the value of `network_mode` to `TCP` or `MIXED `to use `REDIRECT` to proxy `TCP`, and `UDP` will not be proxied when `TUN` is not enabled in the Clash kernel

##### Bypass transparent proxy when connected to Wi-Fi or open a hotspot
Clash default transparent proxy local and hotspot, line [20-23](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L20-#L23)
Clash default transparent proxy local and hotspot, line [17-21](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L17-#L21)

- Open the `${MODDIR}/scripts/clash.config` file, modify the `ignore_out_list` array and add the `wlan+` element, the transparent proxy will `bypass` the `WLAN`, and the hotspot will not be affected

- Open the `${MODDIR}/scripts/clash.config` file, modify the ap_list array and delete the `wlan+` element to opaque proxy `WLAN` and hotspot (the `MediaTek` model may be `ap+` instead of `wlan+`)

##### Select which packages to proxy
- If you expect all Apps proxy by Clash with transparent proxy EXCEPT specific Apps, write down bypass at the first line then these Apps' packages separated as above in file `/data/clash/packages.list`
- clash.config line [14-15](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L14-#L15)
- clash.config line [11-12](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L11-#L12)
- `blacklist` & `whitelits`, not working on `fake-ip`

- dns:
Expand All @@ -87,7 +87,7 @@ Clash default transparent proxy local and hotspot, line [20-23](https://github.c
##### subscription
you can use SubScription
- open `/data/clash/clash.config` line [30-35](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L30-#L35)
- open `/data/clash/clash.config` line [29-34](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L29-#L34)
- update_interval="interval contab"
- Subcript_url="your_link"
- auto_updateSubcript="true"
Expand All @@ -98,7 +98,7 @@ ${MODDIR}/scripts/clash.tool -s
```

##### Config Online
- **clash.config** line [37-38](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L37-#L38), If true,
- **clash.config** line [36-37](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L36-#L37), If true,
- use it to download the subscription configuration, when starting Clash , So no need to type `${MODDIR}/scripts/clash.tool -s` anymore

##### Change Clash kernel
Expand All @@ -108,13 +108,13 @@ You can use Clash.Premium and Clash.Meta
- Clash Premium
- `/data/clash/kernel/lib/Clash.Premium`

you can download the Kernel automatically, for the settings in the **clash.config** line [85-109](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L85-#L109)
you can download the Kernel automatically, for the settings in the **clash.config** line [79-103](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L79-#L103)
```shell
${MODDIR}/scripts/clash.tool -k
```

##### GeoSite, GeoIP, and Mmdb
- settings are in clash.config line [111-135](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L111-#L135)
- settings are in clash.config line [105-116](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L105-#L116)
- if true, will be updated every day at 00.00
- you can change the URL

Expand Down
Binary file modified binary/arm.tar.bz2
Binary file not shown.
Binary file modified binary/arm64.tar.bz2
Binary file not shown.
38 changes: 29 additions & 9 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,32 @@ mod_config="${clash_data_sc}/clash.config"
yacd_dir="${clash_data_dir}/dashboard"
latest=$(date +%Y%m%d%H%M)

if [ $BOOTMODE ! = true ] ; then
ui_print "- Installing through TWRP Not supported"
ui_print "- Intsall this module via Magisk Manager"
abort "- ! Aborting installation !"
if $BOOTMODE; then
ui_print "- Installing from Magisk app"
else
ui_print "*********************************************************"
ui_print "! Install from recovery is NOT supported"
ui_print "! Some recovery has broken implementations, install with such recovery will finally cause CFM modules not working"
ui_print "! Please install from Magisk app"
abort "*********************************************************"
fi

# check Magisk
ui_print "- Magisk version: $MAGISK_VER ($MAGISK_VER_CODE)"

# check android
if [ "$API" -lt 19 ]; then
ui_print "! Unsupported sdk: $API"
abort "! Minimal supported sdk is 19 (Android 4.4)"
else
ui_print "- Device sdk: $API"
fi

# check architecture
if [ "$ARCH" != "arm" ] && [ "$ARCH" != "arm64" ] && [ "$ARCH" != "x86" ] && [ "$ARCH" != "x64" ]; then
abort "! Unsupported platform: $ARCH"
else
ui_print "- Device platform: $ARCH"
fi

ui_print "- Installing Clash for Magisk"
Expand All @@ -46,7 +68,6 @@ mkdir -p ${clash_data_dir}/dashboard
mkdir -p ${MODPATH}/system/bin
mkdir -p ${clash_data_dir}/run
mkdir -p ${clash_data_dir}/scripts
mkdir -p ${clash_data_dir}/mosdns
mkdir -p ${clash_data_dir}/assets

case "${ARCH}" in
Expand All @@ -71,6 +92,7 @@ unzip -o ${MODPATH}/dashboard.zip -d ${clash_data_dir}/dashboard/ >&2

ui_print "- Move Scripts Clash"
mv ${MODPATH}/scripts/* ${clash_data_dir}/scripts/
mv ${clash_data_dir}/scripts/config.yaml ${clash_data_dir}/
mv ${clash_data_dir}/scripts/template ${clash_data_dir}/

ui_print "- Move Cert&Geo"
Expand Down Expand Up @@ -106,9 +128,7 @@ mv ${clash_data_dir_kernel}/setcap ${MODPATH}${bin_path}/
mv ${clash_data_dir_kernel}/getpcaps ${MODPATH}${bin_path}/
mv ${clash_data_dir_kernel}/getcap ${MODPATH}${bin_path}/
mv ${clash_data_dir}/scripts/clash.config ${clash_data_dir}/
mv ${clash_data_dir}/scripts/mosdns ${clash_data_dir}/
mv ${clash_data_dir}/mosdns/mosdns ${clash_data_dir_kernel}/
mv ${clash_data_dir}/mosdns/dnstt-client ${clash_data_dir_kernel}/
mv ${clash_data_dir}/scripts/dnstt/dnstt-client ${clash_data_dir_kernel}/

if [ ! -f "${bin_path}/ss" ] ; then
mv ${clash_data_dir_kernel}/ss ${MODPATH}${bin_path}/
Expand All @@ -122,6 +142,7 @@ rm -rf ${MODPATH}/geo
rm -rf ${MODPATH}/binary
rm -rf ${MODPATH}/clash_service.sh
rm -rf ${clash_data_dir}/scripts/config.yaml
rm -rf ${clash_data_dir}/scripts/dnstt
rm -rf ${clash_data_dir_kernel}/curl

sleep 1
Expand Down Expand Up @@ -150,7 +171,6 @@ set_perm ${clash_data_dir}/scripts/clash.cron 0 0 0755
set_perm ${clash_data_dir}/scripts/start.sh 0 0 0755
set_perm ${clash_data_dir}/scripts/usage.sh 0 0 0755
set_perm ${clash_data_dir}/clash.config ${uid} ${gid} 0755
set_perm ${clash_data_dir}/kernel/mosdns 0 0 0755
set_perm ${clash_data_dir}/kernel/dnstt-client 0 0 0755
set_perm ${clash_service_dir}/clash_service.sh 0 0 0755
sleep 1
Expand Down
22 changes: 0 additions & 22 deletions geo/config.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions module.prop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id=ClashForMagisk
name=Clash for Magisk
version=v2.5.1
versionCode=20221201
version=v2.5.4
versionCode=20221227
author=t🌸amarin
description= Use iptables to support Clash's transparent proxy. Hey, damn half-crippled Android!!!
updateJson=https://github.com/taamarin/ClashforMagisk/raw/master/update.json
87 changes: 37 additions & 50 deletions scripts/clash.config
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
#!/system/bin/sh

# busybox path
now=$(date +"%I.%M %p")
busybox_path="/data/adb/magisk/busybox"
ipv6=$(grep "ipv6" /data/clash/template | ${busybox_path} awk -F ': ' '{print $2}' | head -1)

run_usage="false"
# display usage res cpu in loh

mark_id="2022"
run_mosdns="0"
# 0 is to start only clash, 1 is clash+mosdns

# blacklist ,whitelist, or core
# blacklist / whitelist, or / core [only tun]
mode="blacklist"

network_mode="UDP"
# TCP: REDIRECT / UDP: TPROXY / MIXED: TCP + TUN

ap_list=("wlan+" "ap+" "rndis+")
# ap_list=("softap+" "wlan+" "swlan+" "ap+" "rndis+")
# untuk info AP type ifconfig di terminal
ap_list=("softap+" "wlan+" "swlan+" "ap+" "rndis+")
ignore_out_list=()
# ap list

port_detect="false"
port_detect="true"
# detected port

use_premium="false"
Expand All @@ -31,7 +30,7 @@ update_interval="0 00 * * *"
# set interval update, info: https://crontab.guru/
auto_updateSubcript="false"
# setting auto update subcript
Subcript_url="https://is.gd/subscmfa"
Subcript_url="link url"
# url langganan config

config_online="false"
Expand All @@ -52,42 +51,37 @@ Cgroup_memory_limit="50M"
Clash_bin_name="clash"
Clash_data_dir="/data/clash"
# directory clash & file
Clash_template="$Clash_data_dir/template"
Clash_template="${Clash_data_dir}/template"
# directory template
Clash_run_path="$Clash_data_dir/run"
CFM_logs_file="$Clash_run_path/run.logs"
Clash_pid_file="$Clash_run_path/clash.pid"
Clash_bin="$Clash_data_dir/kernel"
Clash_lib="$Clash_bin/lib"
Clash_bin_path="$Clash_bin/${Clash_bin_name}"
Clash_Premium="$Clash_lib/Clash.Premium"
Clash_Meta="$Clash_lib/Clash.Meta"
Clash_scripts_dir="$Clash_data_dir/scripts"
appuid_file="$Clash_run_path/appuid.list"
filter_packages_file="$Clash_data_dir/packages.list"
Clash_run_path="${Clash_data_dir}/run"
CFM_logs_file="${Clash_run_path}/run.logs"
Clash_pid_file="${Clash_run_path}/clash.pid"
Clash_bin="${Clash_data_dir}/kernel"
Clash_lib="${Clash_bin}/lib"
Clash_bin_path="${Clash_bin}/${Clash_bin_name}"
Clash_Premium="${Clash_lib}/clash.premium"
Clash_Meta="${Clash_lib}/clash.meta"
Clash_scripts_dir="${Clash_data_dir}/scripts"
appuid_file="${Clash_run_path}/appuid.list"
filter_packages_file="${Clash_data_dir}/packages.list"
system_packages_file="/data/system/packages.list"
# directory lservice

use_config="false"
if [ "${use_config}" == "false" ] ; then
Clash_config_file="$Clash_data_dir/config.yaml"
Clash_config_file="${Clash_data_dir}/config.yaml"
else
Clash_config_file="$Clash_data_dir/assets/${use_config}"
Clash_config_file="${Clash_data_dir}/assets/${use_config}"
fi
temporary_config_file="$Clash_run_path/config.yaml"
temporary_config_file="${Clash_run_path}/config.yaml"
# custom config.yaml

mosdns_data_dir="$Clash_data_dir/mosdns"
mosdns_bin_path="$Clash_bin/mosdns"
mosdns_config_file="$mosdns_data_dir/config.yaml"
# moddns is a plug-in DNS forwarder. Users can splicing plug-ins as needed to customize their own DNS processing logic.

schedule_update_core="false"
url_meta="https://github.com/MetaCubeX/Clash.Meta/releases"
url_premium="https://github.com/Dreamacro/clash/releases"
arm=$(uname -m)
if [ "${use_premium}" == "false" ] ; then
file_kernel="Clash.Meta"
file_kernel="clash.meta"
meta_alpha="true"
tag="Prerelease-Alpha"
tag_name="alpha-[0-9,a-z]+"
Expand All @@ -99,50 +93,43 @@ if [ "${use_premium}" == "false" ] ; then
arch="armv7"
fi
else
file_kernel="Clash.Premium"
file_kernel="clash.premium"
platform="linux"
if [ ${arm} == "aarch64" ] ; then
arch="armv8"
arch="arm64"
else
arch="armv7"
fi
fi

auto_updateGeoX="true"
auto_updateGeoX="false"
Clash_geodata_mode=$(grep "geodata-mode" ${Clash_template} | ${busybox_path} awk -F ': ' '{print $2}')
if [ "${use_premium}" == "true" ] ; then
Clash_GeoIP_file="$Clash_data_dir/Country.mmdb"
Clash_GeoIP_file="${Clash_data_dir}/Country.mmdb"
GeoIP_dat_url="https://github.com/Loyalsoldier/geoip/raw/release/Country.mmdb"
else
Clash_GeoIP_file="$Clash_data_dir/GeoIP.dat"
Clash_GeoIP_file="${Clash_data_dir}/GeoIP.dat"
GeoIP_dat_url="https://github.com/v2fly/geoip/raw/release/geoip-only-cn-private.dat"
fi
Clash_GeoSite_file="$Clash_data_dir/GeoSite.dat"
Clash_GeoSite_file="${Clash_data_dir}/GeoSite.dat"
GeoSite_url="https://github.com/CHIZI-0618/v2ray-rules-dat/raw/release/geosite.dat"

iptables_version=$(iptables -V | grep -o "v1\.[0-9]")
if [ "${iptables_version}" = "v1.4" ] ; then
export ANDROID_DATA=/data
export ANDROID_ROOT=/system
iptables_wait="iptables"
ip6tables_wait="ip6tables"
elif [ "${iptables_version}" = "v1.6" ] || [ "${iptables_version}" = "v1.8" ] ; then
if [ "${iptables_version}" = "v1.6" ] || [ "${iptables_version}" = "v1.8" ] ; then
iptables_wait="iptables -w 100"
ip6tables_wait="ip6tables -w 100"
else
export ANDROID_DATA=/data
export ANDROID_ROOT=/system
iptables_wait="iptables"
ip6tables_wait="ip6tables"
ip6tables_wait="ip6tables"
fi

# tproxy-port
Clash_tproxy_port=$(grep "tproxy-port" ${Clash_template} | ${busybox_path} awk -F ': ' '{print $2}')
Clash_redir_port=$(grep "redir-port" ${Clash_template} | ${busybox_path} awk -F ': ' '{print $2}')
# dns
if [ "${run_mosdns}" == "1" ] ; then
Clash_dns_port="2053"
else
Clash_dns_port=$(grep "listen" ${Clash_template} | ${busybox_path} awk -F ':' '{print $3}')
fi
Clash_dns_port=$(grep "listen" ${Clash_template} | ${busybox_path} awk -F ':' '{print $3}')
# tun status
Clash_tun_status=$(${busybox_path} awk -F ': ' '/^tun: *$/{getline; print $2}' ${Clash_template})
Clash_stack_mode=$(grep "stack" ${Clash_template} | ${busybox_path} awk -F ': ' '{print $2}')
Expand All @@ -153,7 +140,7 @@ Clash_fake_ip_range=$(grep "fake-ip-range" ${Clash_template} | ${busybox_path} a
# v2dns, 0 is v2dns off, 1 is v2dns on
# create akun v2dns di whyvpn ,
dnstt_bin_name="dnstt-client"
dnstt_client_bin="$Clash_bin/$dnstt_bin_name"
dnstt_client_bin="${Clash_bin}/${dnstt_bin_name}"
run_dnstt="0"
dns_for_dnstt="1.1.1.1"
pubkey=""
Expand All @@ -164,9 +151,9 @@ reserved_ip6=(::/128 ::1/128 ::ffff:0:0/96 100::/64 64:ff9b::/96 2001::/32 2001:

log() {
export TZ=Asia/Jakarta
echo "$(date '+%H:%M %z') $*" | tee -a ${CFM_logs_file} >> /dev/null 2>&1
echo "${now} $*" | tee -a ${CFM_logs_file} >> /dev/null 2>&1
}
logs() {
export TZ=Asia/Jakarta
echo -n "$(date '+%H:%M %z') $*" | tee -a ${CFM_logs_file} >> /dev/null 2>&1
echo -n "${now} $*" | tee -a ${CFM_logs_file} >> /dev/null 2>&1
}
2 changes: 1 addition & 1 deletion scripts/clash.inotify
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ service_control() {
if [ "${events}" = "d" ]; then
${service_path} -s &> ${log} && ${iptables_path} -s &>> ${log} &
elif [ "${events}" = "n" ]; then
${service_path} -k &>> ${log} && ${iptables_path} -k &>> ${log} &
${iptables_path} -k &>> ${log} && ${service_path} -k &>> ${log} &
fi
fi
}
Expand Down
Loading

0 comments on commit 023e9d9

Please sign in to comment.