diff --git a/.github/workflows/build-gcc.yml b/.github/workflows/build-gcc.yml index 08ad1f7..64f8149 100644 --- a/.github/workflows/build-gcc.yml +++ b/.github/workflows/build-gcc.yml @@ -1,28 +1,12 @@ -# This is a basic workflow to help you get started with Actions - name: build with GCC toolchains -# Controls when the workflow will run on: - # Triggers the workflow on push or pull request events but only for the "master" branch - # push: - # branches: [ "master" ] - # pull_request: - # branches: [ "master" ] - - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" build: - # The type of runner that the job will run on runs-on: ubuntu-22.04 - - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: Checkout zerotier-magisk uses: actions/checkout@v4 @@ -32,7 +16,6 @@ jobs: repository: zerotier/ZeroTierOne path: ZeroTierOne - # Runs a single command using the runners shell - name: Prepare GCC Toolchain run: | sudo apt-get install -qqy gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf g++-aarch64-linux-gnu g++-arm-linux-gnueabihf diff --git a/.github/workflows/build-ndk.yml b/.github/workflows/build-ndk.yml index f8bd419..5ded3e6 100644 --- a/.github/workflows/build-ndk.yml +++ b/.github/workflows/build-ndk.yml @@ -1,32 +1,16 @@ -# This is a basic workflow to help you get started with Actions - name: build with NDK toolchains -# Controls when the workflow will run on: - # Triggers the workflow on push or pull request events but only for the "master" branch - # push: - # branches: [ "master" ] - # pull_request: - # branches: [ "master" ] - - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: env: api_version: 28 # min. 21 ndk: r26d # android-ndk-$ndk-linux.zip -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job + runs-on: ubuntu-22.04 steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: Checkout zerotier-magisk uses: actions/checkout@v4 @@ -42,7 +26,6 @@ jobs: repository: miniupnp/libnatpmp path: libnatpmp - # Runs a single command using the runners shell - name: Prepare NDK Toolchain run: | wget -qO ndk.zip https://dl.google.com/android/repository/android-ndk-$ndk-linux.zip diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 14ff33f..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -zerotier-magisk.zip diff --git a/magisk/customize.sh b/magisk/customize.sh index fa428ad..6205e32 100644 --- a/magisk/customize.sh +++ b/magisk/customize.sh @@ -3,43 +3,31 @@ SKIPUNZIP=1 ASH_STANDALONE=0 -ZT_PATH=/data/adb/zerotier -CONF_PATH=/sdcard/Android/zerotier -CONF_NAME=network_id.txt +ZTPATH=/data/adb/zerotier +SYSBIN=/system/bin ui_print "- unzip" -unzip -o "${ZIPFILE}" -x 'META-INF/*' -d "${MODPATH}" >&2 - -ui_print "- set file permission" -set_perm_recursive ${MODPATH}/zerotier 0 0 0755 0755 +unzip -o $ZIPFILE -x 'META-INF/*' -d $MODPATH >&2 ui_print "- create work dir" -mkdir -p ${ZT_PATH} -mkdir ${ZT_PATH}/run ${ZT_PATH}/home -mv ${MODPATH}/zerotier/* ${ZT_PATH} +mkdir -p $ZTPATH/run $ZTPATH/home +mv $MODPATH/zerotier/* $ZTPATH +ln -sf $ZTPATH/zerotier-one $ZTPATH/zerotier-cli +ln -sf $ZTPATH/zerotier-one $ZTPATH/zerotier-idtool -ln -s ${ZT_PATH}/zerotier-one ${ZT_PATH}/zerotier-cli -ln -s ${ZT_PATH}/zerotier-one ${ZT_PATH}/zerotier-idtool +ui_print "- link to system" +mkdir -p $MODPATH$SYSBIN +ln -sf $ZTPATH/zerotier.sh $MODPATH$SYSBIN/zerotier.sh +ln -sf $ZTPATH/zerotier-cli $MODPATH$SYSBIN/zerotier-cli -ui_print "- create config dir" -mkdir -p ${CONF_PATH} -if [[ ! -e ${CONF_PATH}/${CONF_NAME} ]]; then - touch ${CONF_PATH}/${CONF_NAME} - echo "0000000000000000" > ${CONF_PATH}/${CONF_NAME} -fi - -ui_print "- clean up" -rm -rf ${MODPATH}/customize.sh 2>/dev/null -rm -rf ${MODPATH}/bin 2>/dev/null -sleep 1 +ui_print "- set file permission" +set_perm_recursive $MODPATH 0 0 0755 0644 +set_perm_recursive $ZTPATH 0 0 0755 0644 ui_print "- installed" -set_perm_recursive ${MODPATH} 0 0 0755 0644 - ui_print "---------- information -----------" -ui_print "- zerotier root: ${ZT_PATH}" -ui_print "- zerotier version: $(grep_prop version ${TMPDIR}/module.prop)" -ui_print "- config file path: ${CONF_PATH}/${CONF_NAME}" +ui_print "- zerotier root: $ZTPATH" +ui_print "- zerotier version: $(grep_prop version $TMPDIR/module.prop)" diff --git a/magisk/module.prop b/magisk/module.prop index 4820963..9c4b963 100644 --- a/magisk/module.prop +++ b/magisk/module.prop @@ -1,6 +1,6 @@ id=zerotier -name=Zerotier For Magisk +name=ZeroTier for Magisk version=v1.14.0 -versionCode=100 +versionCode=114 author=eventlOwOp description=zerotier for magisk diff --git a/magisk/service.sh b/magisk/service.sh index 30b6aac..026bf3f 100644 --- a/magisk/service.sh +++ b/magisk/service.sh @@ -2,16 +2,15 @@ MODDIR=${0%/*} -zerotier_root=/data/adb/zerotier +ZTROOT=/data/adb/zerotier +ZTRUNTIME=$ZTROOT/run -pipe=/data/adb/zerotier/run/pipe -zerotier_log=/data/adb/zerotier/run/zerotier.log -daemon_log=/data/adb/zerotier/run/daemon.log -network_id_path=/sdcard/Android/zerotier/network_id.txt -pid=-1 +pipe=$ZTRUNTIME/pipe +ZTLOG=$ZTRUNTIME/zerotier.log +daemon_log=$ZTRUNTIME/daemon.log -cli_output=/data/adb/zerotier/run/cli.out -cli_pid=/data/adb/zerotier/run/cli.pid +cli_output=$ZTRUNTIME/cli.out +cli_pid=$ZTRUNTIME/cli.pid log() { t=`date +"%m-%d %H:%M:%S.%3N"` @@ -23,40 +22,31 @@ log_cli() { } _stop() { pid=`pidof zerotier-one` - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then log "zerotier-one not running" - return 1 + return fi kill -9 $pid - ret=$? - - if [ $ret -eq 0 ]; then - log "stopped zerotier-one" - return 0 - else + if [[ $? -ne 0 ]]; then log "kill zerotier-one failed" + return fi - - return 1 + + wait + log "stopped zerotier-one" } - __start() { - nohup ./zerotier-one -d >> $zerotier_log 2>&1 & - - sleep 1 - - pid=`pidof zerotier-one` + $ZTROOT/zerotier-one -d >> $ZTLOG 2>&1 & } _start() { if pid=`pidof zerotier-one`; then log "zerotier-one already running pid $pid" else __start + pid=`pidof zerotier-one` log "started zerotier-one pid $pid" fi - - return 0 } _status() { # fake systemd lol @@ -72,45 +62,14 @@ _status() { fi } -# _join() { -# nid=$(cat $network_id_path) - -# ./zerotier-cli join $nid >> $zerotier_log 2>&1 - -# if [ $? -ne 0 ]; then -# log "join network failed" -# return 1 -# else -# log "joined $nid" -# fi - -# return 0 -# } - -# _leave() { -# nid=$(cat $network_id_path) - -# ./zerotier-cli leave $nid >> $zerotier_log 2>&1 - -# if [ $? -ne 0 ]; then -# log "leave network failed" -# return 1 -# else -# log "left $nid" -# fi - -# return 0 -# } - -cd /data/adb/zerotier -rm -f ./run/* +cd $ZTROOT +rm -f $ZTRUNTIME mkfifo $pipe ip rule add from all lookup main pref 1 export LD_LIBRARY_PATH=/data/adb/zerotier/lib __start -(sleep 20 && _join) & while true do @@ -118,13 +77,9 @@ do case "$cmd" in "start") _start;; "stop") _stop;; - "restart") - _stop - sleep 1 - _start;; + "restart") _stop; _start;; "status") _status;; - *) - log "unknown command $cmd";; + *) log "unknown command $cmd";; esac cpid=`cat $cli_pid` diff --git a/magisk/uninstall.sh b/magisk/uninstall.sh index e151521..f7913ce 100644 --- a/magisk/uninstall.sh +++ b/magisk/uninstall.sh @@ -1,2 +1 @@ -rm -rf /data/adb/zerotier -rm -rf /sdcard/Android/zerotier +rm -rf /data/adb/zerotier \ No newline at end of file diff --git a/magisk/zerotier/zerotier.sh b/magisk/zerotier/zerotier.sh index f017bca..0f8f33e 100644 --- a/magisk/zerotier/zerotier.sh +++ b/magisk/zerotier/zerotier.sh @@ -15,28 +15,24 @@ rm -f $cli_output echo $$ > $cli_pid on_receive() { + kill -9 %% cat $cli_output exit 0 } run() { - echo $1 > $pipe + echo $cmd > $pipe } trap 'on_receive' SIGUSR1 +cmd=$1 -if [[ "$1" ]]; then - if [[ "$2" ]]; then - echo $help_text - exit 1 - fi - - case "$1" in - "start") run $1;; - "stop") run $1;; - "restart") run $1;; - "status") run $1;; - *) - echo "unknown command $1";; +if [[ $# -eq 1 ]]; then + case "$cmd" in + "start") run;; + "stop") run;; + "restart") run;; + "status") run;; + *) echo "unknown command $cmd";; esac else echo $help_text @@ -44,6 +40,7 @@ else fi sleep 20 & -wait $! -echo "time out" +wait + +echo "20 seconds time out" exit 1 \ No newline at end of file