diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a41cd44..b675778 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,11 +57,11 @@ jobs: CXX=aarch64-linux-android$api_version-clang++ cd libnatpmp - make CC=$CC natpmpc-shared + make --silent CC=$CC natpmpc-shared cd .. cd ZeroTierOne - make -j $(nproc) ZT_DEBUG=0 ZT_SSO_SUPPORTED=0 CC=$CC CXX=$CXX LDFLAGS="-L../libnatpmp" DEFS="-I../libnatpmp -D__GLIBC__=0" + make --silent -j $(nproc) ZT_DEBUG=0 ZT_SSO_SUPPORTED=0 CC=$CC CXX=$CXX LDFLAGS="-L../libnatpmp" DEFS="-I../libnatpmp -D__GLIBC__=0" cd .. mkdir -p magisk/zerotier/lib @@ -95,5 +95,10 @@ jobs: # cd magisk # zip -q -r ../zerotier-magisk-arm.zip . - - name: Debugging with tmate - uses: mxschmitt/action-tmate@v3.18 + # - name: Debugging with tmate + # uses: mxschmitt/action-tmate@v3.18 + + - name: Release + uses: softprops/action-gh-release@v2 + with: + files: zerotier-magisk-aarch64.zip diff --git a/magisk/LICENSE b/LICENSE similarity index 100% rename from magisk/LICENSE rename to LICENSE diff --git a/README.md b/README.md index 0f4fc46..9e6090a 100644 --- a/README.md +++ b/README.md @@ -10,32 +10,52 @@ **No conflicts with other android VPN service!** +## Requirements + +Built with Android NDK Toolchain, support api 28 (Android 9.0) and above. + +`make-linux.mk` in ZeroTierOne does not support armv7 (see `-mtune=`), so it only supports aarch64 here + +Unofficial planet is not supported because I don't know hot to compile rust with NDK 😭 + +Maybe we can compile with gcc cross-compiling toolchain statically, without linking system calls, but there could be potential compatibility problems. + ## Installation -If you're using a device with an older kernel where this version does not work, you can move to branch kernel-4.14 and installation steps are the same. -but scripts in this branch may be **OUTDATED**. 1. download release from github. 2. install with magisk. 3. modify the config file at `/sdcard/Android/zerotier/network_id.txt` and put your 16-character network id in it. 4. restart and enjoy. -To restart, you can just restart the whole system, or just execute `/data/adb/zerotier/restart.sh`; An android application to control zerotier (networkid, restart, ...) has been added to the todo list. +To restart, execute (in root) `sh /data/adb/zerotier/zerotier.sh restart`; An android application to control zerotier (networkid, restart, ...) has been added to the todo list. -### Scripts and binaries +### Files -all the scripts and binaries are placed in `/data/adb/zerotier/` , you can use termux to run them if needed. -`add_ip_rule.sh` is used to make the `main` route table, which zerotier writes its routes to, available. +``` +/data/adb/zerotier/ + | - run/ + | | - pid # zerotier-one pid + | | - pipe # pipe to service.sh + | | - daemon.log # service.sh log + | ` - zerotier.log # zerotier-one log + | - home/ # zerotier-one home directory + | ` - ... + | - lib/ + | ` - libc++_shared.so # NDK dynamic library + | - zerotier.sh # tool to communicate with service.sh + | - zerotier-one # zerotier-one executable + | - zerotier-cli -> zerotier-one + ` - zerotier-idtool -> zerotier-one +``` + +all the scripts and binaries are placed in `/data/adb/zerotier/`. + +`zerotier.sh` writes commands to the pipe at `run/pipe` and `service.sh` read from it. + +`Usage: sh zerotier.sh {start|stop|restart|join|leave}` + +log files are placed in `run`, `daemon.log` for `service.sh` and `zerotier.log` for ZeroTierOne. ### Build binaries yourself -The following steps have only been tested in "Termux" with the package manager "apt". - -Note that the zerotier binaries are only built for aarch64, you can build it yourself in "Termux". - -Download source files from [zerotier/ZeroTierOne](https://www.github.com/zerotier/ZeroTierOne). - -Delete `ZT_SSO_SUPPORTED=1` in `make-linux.mk` for "aarch64" (or your architecture). this will prevent building zeroidc with rust; the author encountered some problems building zeroidc - -Install package `natpmpc` using `apt install natpmpc` and update your `libnpth` library using `apt install libnpth`. - -At last run `make` or multithreaded `make -j8`. +The binaries are built with Android NDK toolchains on Github Action, see `.github/workflow/build.yml` for detailed information. diff --git a/README_ZH.md b/README_ZH.md index 45e2b21..5dc4a38 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -8,29 +8,53 @@ 将 ZeroTier 保持后台运行,不与其他 Android VPN 应用程序冲突 +## 运行要求 + +使用 NDK 编译,支持 api 28 (Android 9.0) 及以上的设备 + +由于 ZeroTierOne 的 make-linux.mk 尚不支持 armv7 的设备(看似支持,但是 `-mtune=` 说明了一切),所以此处也不支持 + +暂时不支持 SSO 即自建 planet,因为 NDK 编译 rust 还没玩明白 😭 + +有其他项目使用 gcc 交叉编译工具链静态编译,支持了自建 planet,本仓库应该会出相应版本,可能存在较大兼容性问题 +(如经过测试,必须在 root 下运行,否则 Bad System Call,可能是 `/system/lib, /vendor/lib` 没有权限访问造成的,理论上还是能够完全支持,只是怕 Android 阉割内核) + ## 安装 -部分较老内核版本可能不受支持,可以移步 kernel-4.14 分支进行尝试,但是该分支不保证更新 1. 从 Release 下载压缩包 2. 导入 magisk 进行安装 3. 将你的 16 位 ZeroTier network id 写入 `/sdcard/Android/zerotier/network_id.txt` 4. 重启 -你可以用 `su` 执行 `/data/adb/zerotier/restart.sh` 来重启,或者干脆重启手机,计划写一个 app 来完成 +你可以用 `su` 执行 `sh /data/adb/zerotier/zerotier.sh restart` 来重启,或者干脆重启手机,计划写一个 app 来完成 -### 路径 +### 文件 + +``` +/data/adb/zerotier/ + | - run/ + | | - pid # zerotier-one pid + | | - pipe # pipe to service.sh + | | - daemon.log # service.sh log + | ` - zerotier.log # zerotier-one log + | - home/ # zerotier-one home directory + | ` - ... + | - lib/ + | ` - libc++_shared.so # NDK dynamic library + | - zerotier.sh # tool to communicate with service.sh + | - zerotier-one # zerotier-one executable + | - zerotier-cli -> zerotier-one + ` - zerotier-idtool -> zerotier-one +``` ZeroTier 可执行文件和操作的 Shell 脚本放在 `/data/adb/zerotier/` -`add_ip_rule.sh` is used to make the `main` route table, which zerotier writes its routes to, available. + +`zerotier.sh` 向管道 `run/pipe` 写入, `service.sh` 读取管道,然后进行操作 + +`Usage: sh zerotier.sh {start|stop|restart|join|leave}` + +log files are placed in `run`, `daemon.log` for `service.sh` and `zerotier.log` for ZeroTierOne. ### 自行编译 -仅使用 termux (aarch64) 进行过测试 - -从 [zerotier/ZeroTierOne](https://www.github.com/zerotier/ZeroTierOne) 下载代码 - -在 `make-linux.mk` 中对 "aarch64" 或你的架构删除 `ZT_SSO_SUPPORTED=1` 即删除 zeroidc 支持,无需安装 rust 进行编译(目前未找到方法编译 zeroidc ) - -`apt-get -y install natpmpc libnpth` 安装依赖库 - -最后 `make` 编译(多线程使用 `make -j8`) +使用 NDK,参考 `.github/workflow/build.yml` diff --git a/magisk/customize.sh b/magisk/customize.sh index e7dd9a1..cf04d05 100644 --- a/magisk/customize.sh +++ b/magisk/customize.sh @@ -14,6 +14,7 @@ ui_print "- set file permission" set_perm_recursive ${MODPATH}/zerotier 0 0 0755 0755 ui_print "- create work dir" +rm -rf ${ZT_PATH} mkdir -p ${ZT_PATH} mkdir ${ZT_PATH}/run ${ZT_PATH}/home mv ${MODPATH}/zerotier/* ${ZT_PATH} @@ -25,7 +26,7 @@ ui_print "- create config dir" mkdir -p ${CONF_PATH} if [[ ! -e ${CONF_PATH}/${CONF_NAME} ]]; then touch ${CONF_PATH}/${CONF_NAME} - echo "1111111111111111" > ${CONF_PATH}/${CONF_NAME} + echo "0000000000000000" > ${CONF_PATH}/${CONF_NAME} fi ui_print "- clean up" diff --git a/magisk/service.sh b/magisk/service.sh index 7376de3..598dda5 100644 --- a/magisk/service.sh +++ b/magisk/service.sh @@ -21,7 +21,7 @@ _stop() { kill -9 $pid ret=$? - + rm -rf ./run/pid if [ $ret -eq 0 ]; then @@ -74,7 +74,7 @@ __start() { } _start() { if pid=$(pidof zerotier-one); then - log "zerotier-one already running" + log "zerotier-one already running pid $pid" else __start log "started zerotier-one pid $pid" @@ -90,8 +90,6 @@ export LD_LIBRARY_PATH=/data/adb/zerotier/lib __start -trap "rm -f $pipe" EXIT - rm -f $pipe mkfifo $pipe @@ -99,23 +97,20 @@ while true do if read line < $pipe; then log "received commad $line" - if [[ "$line" == 'quit' ]]; then - log "stopped" - break - elif [[ "$line" == 'start' ]]; then - _start - elif [[ "$line" == 'stop' ]]; then - _stop - elif [[ "$line" == 'restart' ]]; then - _stop - sleep 1 - _start - elif [[ "$line" == 'join' ]]; then - _join - elif [[ "$line" == 'leave' ]]; then - _leave - else - log "unknown command $line" - fi + case line in + "quit") + log "stopped" + break;; + "start") _start;; + "stop") _stop;; + "restart") + _stop + sleep 1 + _start;; + "join") _join;; + "leave") _leave;; + *) + log "unknown command $line";; + esac fi done diff --git a/magisk/zerotier/zerotier.sh b/magisk/zerotier/zerotier.sh index 3b2aab6..d375773 100644 --- a/magisk/zerotier/zerotier.sh +++ b/magisk/zerotier/zerotier.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/system/bin/sh pipe=/data/adb/zerotier/run/pipe if [[ ! -p $pipe ]]; then echo "daemon not running"