From 9468965e0f68842090fb8f273a799d5cadab7c70 Mon Sep 17 00:00:00 2001 From: Jayson Reis Date: Mon, 5 Apr 2021 02:11:53 +0200 Subject: [PATCH] Add zerotier without entware depdenency --- .gitignore | 2 ++ wdpk/zerotier/Dockerfile | 5 ++++ wdpk/zerotier/Makefile | 8 ++++++ wdpk/zerotier/apkg.rc | 2 +- wdpk/zerotier/build.sh | 5 ++-- wdpk/zerotier/cgi-bin/zerotier.py | 40 +++++++++++++++++------------- wdpk/zerotier/compile-in-docker.sh | 15 +++++++++++ wdpk/zerotier/install.sh | 2 -- wdpk/zerotier/remove.sh | 2 -- wdpk/zerotier/start.sh | 9 ++++--- 10 files changed, 62 insertions(+), 28 deletions(-) create mode 100644 wdpk/zerotier/Dockerfile create mode 100644 wdpk/zerotier/Makefile create mode 100755 wdpk/zerotier/compile-in-docker.sh diff --git a/.gitignore b/.gitignore index 5fe9a3a..c16ea04 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ wdpk/*/work* wdpk/*/*.sign wdpk/*/*.xml +wdpk/zerotier/bin/ + .env toolchains/*/work* diff --git a/wdpk/zerotier/Dockerfile b/wdpk/zerotier/Dockerfile new file mode 100644 index 0000000..14393d5 --- /dev/null +++ b/wdpk/zerotier/Dockerfile @@ -0,0 +1,5 @@ +FROM rustembedded/cross:arm-unknown-linux-gnueabihf +RUN cd /usr/src && curl -sLO https://github.com/zerotier/ZeroTierOne/archive/refs/tags/1.6.4.tar.gz && tar zxvf 1.6.4.tar.gz && rm 1.6.4.tar.gz +ENV CC=arm-linux-gnueabihf-gcc +ENV CXX=arm-linux-gnueabihf-g++ +ENV STRIP=arm-linux-gnueabihf-strip diff --git a/wdpk/zerotier/Makefile b/wdpk/zerotier/Makefile new file mode 100644 index 0000000..21aa57a --- /dev/null +++ b/wdpk/zerotier/Makefile @@ -0,0 +1,8 @@ +SRC := compile-in-docker.sh Dockerfile +all: bin/zerotier-one + +.PHONY: all + +bin/zerotier-one: $(SRC) + ./compile-in-docker.sh + diff --git a/wdpk/zerotier/apkg.rc b/wdpk/zerotier/apkg.rc index 4a6d130..11a6a55 100644 --- a/wdpk/zerotier/apkg.rc +++ b/wdpk/zerotier/apkg.rc @@ -1,5 +1,5 @@ Package: zerotier -Version: 1.6.3 +Version: 1.6.4 Packager: TFL Email: Homepage: http://www.zerotier.com diff --git a/wdpk/zerotier/build.sh b/wdpk/zerotier/build.sh index dd1d567..28d5d09 100755 --- a/wdpk/zerotier/build.sh +++ b/wdpk/zerotier/build.sh @@ -1,8 +1,6 @@ #!/bin/sh - +set -e APP_NAME="$(basename $(pwd))" -DATE="$(date +"%m%d%Y")" -CWD="$(pwd)" VERSION="$(awk '/Version/{print $NF}' apkg.rc)" echo "Building ${APP_NAME} version ${VERSION}" @@ -10,6 +8,7 @@ echo "Building ${APP_NAME} version ${VERSION}" MODELS="MyCloudEX2Ultra" for model in $MODELS; do + make ../../mksapkg-OS5 -E -s -m $model > /dev/null done diff --git a/wdpk/zerotier/cgi-bin/zerotier.py b/wdpk/zerotier/cgi-bin/zerotier.py index b0f9379..4e9a9e3 100755 --- a/wdpk/zerotier/cgi-bin/zerotier.py +++ b/wdpk/zerotier/cgi-bin/zerotier.py @@ -1,37 +1,43 @@ #!/usr/bin/env python3 import cgitb -import re + cgitb.enable() + import cgi import os +import re import subprocess -print('Content-type: text/plain') -print('') +os.environ["PATH"] += os.path.pathsep + "/mnt/HD/HD_a2/Nas_Prog/zerotier/bin/" +os.environ["ZEROTIER_HOME"] = "/mnt/HD/HD_a2/.systemfile/zerotier" +print("Content-type: text/plain") +print("") + def list_networks(): - print('
')
-    print('command output')
-    output = subprocess.check_output(["/opt/bin/zerotier-cli", "listnetworks"])
-    print(output.decode('utf-8'))
-    print('
') + print("
")
+    print("command output")
+    output = subprocess.check_output(["zerotier-cli", "listnetworks"])
+    print(output.decode("utf-8"))
+    print("
") def join_network(): - print('
')
+    print("
")
     form = cgi.FieldStorage()
-    network_name = form['network_name'].value.strip()
-    match = re.match('^[0-9a-f]+$', network_name)
+    network_name = form["network_name"].value.strip()
+    match = re.match("^[0-9a-f]+$", network_name)
     if not match:
-        print(f'Not a valid network name {network_name!r}')
+        print(f"Not a valid network name {network_name!r}")
         exit(0)
 
-    print(f'trying to join {network_name!r}')
-    output = subprocess.check_output(["/opt/bin/zerotier-cli", "join", network_name])
-    print(output.decode('utf-8'))
-    print('
') + print(f"trying to join {network_name!r}") + output = subprocess.check_output(["zerotier-cli", "join", network_name]) + print(output.decode("utf-8")) + print("
") + -if os.environ['REQUEST_METHOD'] != 'GET': +if os.environ["REQUEST_METHOD"] != "GET": join_network() exit(0) diff --git a/wdpk/zerotier/compile-in-docker.sh b/wdpk/zerotier/compile-in-docker.sh new file mode 100755 index 0000000..b6551e7 --- /dev/null +++ b/wdpk/zerotier/compile-in-docker.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e +docker build -t zerotier . +docker run \ + -v $PWD/bin:/usr/src/bin --rm -it \ + -e ME="$(id -u):$(id -g)" \ + zerotier \ + bash -exc 'cd /usr/src/ZeroTier* && make -j8 ZT_DISABLE_COMPRESSION=1 && cp zerotier-one /usr/src/bin/ && chown -R $ME /usr/src/bin/' + +cd bin +for link in zerotier-cli zerotier-idtool; +do + ln -sf zerotier-one $link +done +cd .. diff --git a/wdpk/zerotier/install.sh b/wdpk/zerotier/install.sh index c42f6af..df8847a 100755 --- a/wdpk/zerotier/install.sh +++ b/wdpk/zerotier/install.sh @@ -7,5 +7,3 @@ NAS_PROG=$(readlink -f $2) # install all package scripts to the proper location cp -rfv ${INSTALL_DIR} ${NAS_PROG} &2>&1 >> $DEBUG_FILE - -/opt/bin/opkg install zerotier &2>&1 >> $DEBUG_FILE diff --git a/wdpk/zerotier/remove.sh b/wdpk/zerotier/remove.sh index d092073..53ce371 100755 --- a/wdpk/zerotier/remove.sh +++ b/wdpk/zerotier/remove.sh @@ -3,7 +3,5 @@ path=$1 -/opt/bin/opkg remove zerotier - rm -rf $path rm -rf "/var/www/apps/zerotier/" diff --git a/wdpk/zerotier/start.sh b/wdpk/zerotier/start.sh index 56560b5..10c2d4f 100755 --- a/wdpk/zerotier/start.sh +++ b/wdpk/zerotier/start.sh @@ -1,4 +1,7 @@ -#! /bin/sh -[ -f /tmp/debug_apkg ] && echo "APKG_DEBUG: $0 $@" >> /tmp/debug_apkg +#!/bin/bash +[ -f /tmp/debug_apkg ] && echo "APKG_DEBUG: $0 $@ $PWD" >> /tmp/debug_apkg -/opt/bin/zerotier-one -d \ No newline at end of file +export ZEROTIER_HOME=/mnt/HD/HD_a2/.systemfile/zerotier +mkdir -p "$ZEROTIER_HOME" + +$1/bin/zerotier-one -d