From a8df6f359d37373f17118f0d70845fa8734e8d15 Mon Sep 17 00:00:00 2001 From: sunbk201 Date: Fri, 8 Nov 2024 20:44:24 +0800 Subject: [PATCH] feat: support openwrt make build --- build.sh | 2 +- install.sh | 148 +++++++++++--------- openwrt/Makefile | 59 ++++++++ {luci => openwrt/files/luci}/cbi.lua | 0 {luci => openwrt/files/luci}/controller.lua | 0 ua3f.init => openwrt/files/ua3f.init | 0 ua3f.uci => openwrt/files/ua3f.uci | 0 go.mod => src/go.mod | 0 go.sum => src/go.sum | 0 {http => src/http}/http.go | 0 {log => src/log}/log.go | 0 main.go => src/main.go | 0 12 files changed, 143 insertions(+), 66 deletions(-) create mode 100644 openwrt/Makefile rename {luci => openwrt/files/luci}/cbi.lua (100%) rename {luci => openwrt/files/luci}/controller.lua (100%) rename ua3f.init => openwrt/files/ua3f.init (100%) rename ua3f.uci => openwrt/files/ua3f.uci (100%) rename go.mod => src/go.mod (100%) rename go.sum => src/go.sum (100%) rename {http => src/http}/http.go (100%) rename {log => src/log}/log.go (100%) rename main.go => src/main.go (100%) diff --git a/build.sh b/build.sh index fcaee9e..ba37c78 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ project_name="ua3f" release_version="0.5.1" -target=main.go +target=src/main.go dist=./dist release_dir=./bin diff --git a/install.sh b/install.sh index 3d13ade..281eb44 100755 --- a/install.sh +++ b/install.sh @@ -17,86 +17,104 @@ ckcmd() { command -v sh >/dev/null 2>&1 && command -v $1 >/dev/null 2>&1 || type $1 >/dev/null 2>&1 } +chmod_clash() { + if id -u shellclash >/dev/null 2>&1; then + chmod o+w /etc/clash >/dev/null 2>&1 + fi + if id -u shellcrash >/dev/null 2>&1; then + chmod o+w /etc/clash >/dev/null 2>&1 + fi +} + +ck_ua3f_log() { + chmod ugo+w /var/log + if [ -f "/var/log/ua3f.log" ]; then + rm "/var/log/ua3f.log" + fi + touch /var/log/ua3f.log && chmod 666 /var/log/ua3f.log +} + +dl_ua3f() { + wget https://blog.sunbk201.site/cdn/bin/$ua3f_tar + if [ $? -ne 0 ]; then + echo "Download UA3F Failed, Please Retry." + exit 1 + fi + + wget https://blog.sunbk201.site/cdn/ua3f.init + if [ $? -ne 0 ]; then + echo "Download ua3f.init Failed, Please Retry." + exit 1 + fi + + wget https://blog.sunbk201.site/cdn/ua3f.uci + if [ $? -ne 0 ]; then + echo "Download ua3f.uci Failed, Please Retry." + exit 1 + fi + + wget https://blog.sunbk201.site/cdn/cbi.lua + if [ $? -ne 0 ]; then + echo "Download cbi.lua Failed, Please Retry." + exit 1 + fi + + wget https://blog.sunbk201.site/cdn/controller.lua + if [ $? -ne 0 ]; then + echo "Download controller.lua Failed, Please Retry." + exit 1 + fi +} + +clean_ua3f() { + if [ -f "/etc/init.d/ua3f.init" ]; then + rm "/etc/init.d/ua3f.init" + fi + if [ -f "/etc/init.d/ua3f" ]; then + rm "/etc/init.d/ua3f" + fi + if [ -f "/etc/config/ua3f" ]; then + rm "/etc/config/ua3f" + fi + if [ -f "/usr/lib/lua/luci/model/cbi/ua3f.lua" ]; then + rm "/usr/lib/lua/luci/model/cbi/ua3f.lua" + fi + if [ -f "/usr/lib/lua/luci/controller/ua3f.lua" ]; then + rm "/usr/lib/lua/luci/controller/ua3f.lua" + fi +} + +install_ua3f() { + tar zxf $ua3f_tar && rm -f $ua3f_tar + mv ua3f /usr/bin/ua3f && chmod +x /usr/bin/ua3f + mv ua3f.uci /etc/config/ua3f && chmod +x /etc/config/ua3f + mv ua3f.init /etc/init.d/ua3f && chmod +x /etc/init.d/ua3f + mkdir -p /usr/lib/lua/luci/model/cbi + mkdir -p /usr/lib/lua/luci/controller + mv cbi.lua /usr/lib/lua/luci/model/cbi/ua3f.lua + mv controller.lua /usr/lib/lua/luci/controller/ua3f.lua +} + cd /root getcpucore version=0.5.1 ua3f_tar=ua3f-$version-$cpucore.tar.gz -if id -u shellclash >/dev/null 2>&1; then - chmod o+w /etc/clash >/dev/null 2>&1 -fi -if id -u shellcrash >/dev/null 2>&1; then - chmod o+w /etc/clash >/dev/null 2>&1 -fi - -if [ -f "ua3f" ]; then - rm "ua3f" - killall ua3f >/dev/null 2>&1 -fi +chmod_clash if ! command -v sudo >/dev/null 2>&1; then opkg update >/dev/null 2>&1 && opkg install sudo >/dev/null 2>&1 fi -chmod ugo+w /var/log -if [ -f "/var/log/ua3f.log" ]; then - rm "/var/log/ua3f.log" -fi -touch /var/log/ua3f.log && chmod 666 /var/log/ua3f.log - +ck_ua3f_log if [ -f "$ua3f_tar" ]; then rm "$ua3f_tar" fi - -wget https://blog.sunbk201.site/cdn/bin/$ua3f_tar -if [ $? -ne 0 ]; then - echo "Download UA3F Failed, Please Retry." - exit 1 -fi -tar zxf $ua3f_tar && rm -f $ua3f_tar -mv ua3f /usr/bin/ua3f -chmod +x /usr/bin/ua3f - -if [ -f "/etc/init.d/ua3f.init" ]; then - rm "/etc/init.d/ua3f.init" -fi -if [ -f "/etc/init.d/ua3f" ]; then - rm "/etc/init.d/ua3f" -fi -wget https://blog.sunbk201.site/cdn/ua3f.init -if [ $? -ne 0 ]; then - echo "Download ua3f.init Failed, Please Retry." - exit 1 -fi -mv ua3f.init /etc/init.d/ua3f && chmod +x /etc/init.d/ua3f +dl_ua3f +clean_ua3f +install_ua3f /etc/init.d/ua3f enable - -wget https://blog.sunbk201.site/cdn/ua3f.uci -if [ $? -ne 0 ]; then - echo "Download ua3f.uci Failed, Please Retry." - exit 1 -fi -mv ua3f.uci /etc/config/ua3f - -wget https://blog.sunbk201.site/cdn/cbi.lua -if [ $? -ne 0 ]; then - echo "Download cbi.lua Failed, Please Retry." - exit 1 -fi -mkdir -p /usr/lib/lua/luci/model/cbi -mv cbi.lua /usr/lib/lua/luci/model/cbi/ua3f.lua - -wget https://blog.sunbk201.site/cdn/controller.lua -if [ $? -ne 0 ]; then - echo "Download controller.lua Failed, Please Retry." - exit 1 -fi -mkdir -p /usr/lib/lua/luci/controller -mv controller.lua /usr/lib/lua/luci/controller/ua3f.lua - -chmod +x /etc/config/ua3f >/dev/null 2>&1 - if [ $? -eq 0 ]; then echo "Install UA3F Success." fi diff --git a/openwrt/Makefile b/openwrt/Makefile new file mode 100644 index 0000000..5ee5280 --- /dev/null +++ b/openwrt/Makefile @@ -0,0 +1,59 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=UA3F +PKG_VERSION:=0.5.1 +PKG_RELEASE:=1 + +# PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +# PKG_SOURCE_URL:=https://codeload.github.com/SunBK201/UA3F/tar.gz/v$(PKG_VERSION) +# PKG_HASH:=7d9164e31170e5a54fd83fa31785eaad5fb6ffff36a3336060ae32b7cdda9895 + +PKG_MAINTAINER:=SunBK201 +PKG_LICENSE:=GPL-3.0-only +PKG_LICENSE_FILES:=LICENSE + +PKG_BUILD_DEPENDS:=golang/host +PKG_BUILD_PARALLEL:=1 +PKG_BUILD_FLAGS:=no-mips16 + +GO_PKG:=github.com/sunbk201/ua3f + +include $(INCLUDE_DIR)/package.mk +include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk + +define Package/ua3f + SECTION:=net + CATEGORY:=Network + SUBMENU:=Web Servers/Proxies + TITLE:=A SOCKS5 Server for Change User-Agent + URL:=https://github.com/SunBK201/UA3F + DEPENDS:=$(GO_ARCH_DEPENDS) +luci-compat +endef + +define Package/ua3f/description + Implementation of the next generation of HTTP User-Agent modification methodology. +endef + +define Build/Prepare + $(CP) ../src/* $(PKG_BUILD_DIR) +endef + +define Package/ua3f/install + $(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR)) + + $(INSTALL_DIR) $(1)/usr/bin/ + # $(INSTALL_BIN) $(GO_PKG_BUILD_BIN_DIR)/ua3f $(1)/usr/bin/ + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/ua3f $(1)/usr/bin/ + $(INSTALL_DIR) $(1)/etc/init.d/ + $(INSTALL_BIN) ./files/ua3f.init $(1)/etc/init.d/ua3f + $(INSTALL_DIR) $(1)/etc/config/ + $(INSTALL_CONF) ./files/ua3f.uci $(1)/etc/config/ua3f + $(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/ + $(INSTALL_CONF) ./files/luci/cbi.lua $(1)/usr/lib/lua/luci/model/cbi/ua3f.lua + $(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller/ + $(INSTALL_CONF) ./files/luci/controller.lua $(1)/usr/lib/lua/luci/controller/ua3f.lua + +endef + +$(eval $(call GoBinPackage,ua3f)) +$(eval $(call BuildPackage,ua3f)) diff --git a/luci/cbi.lua b/openwrt/files/luci/cbi.lua similarity index 100% rename from luci/cbi.lua rename to openwrt/files/luci/cbi.lua diff --git a/luci/controller.lua b/openwrt/files/luci/controller.lua similarity index 100% rename from luci/controller.lua rename to openwrt/files/luci/controller.lua diff --git a/ua3f.init b/openwrt/files/ua3f.init similarity index 100% rename from ua3f.init rename to openwrt/files/ua3f.init diff --git a/ua3f.uci b/openwrt/files/ua3f.uci similarity index 100% rename from ua3f.uci rename to openwrt/files/ua3f.uci diff --git a/go.mod b/src/go.mod similarity index 100% rename from go.mod rename to src/go.mod diff --git a/go.sum b/src/go.sum similarity index 100% rename from go.sum rename to src/go.sum diff --git a/http/http.go b/src/http/http.go similarity index 100% rename from http/http.go rename to src/http/http.go diff --git a/log/log.go b/src/log/log.go similarity index 100% rename from log/log.go rename to src/log/log.go diff --git a/main.go b/src/main.go similarity index 100% rename from main.go rename to src/main.go