From d91b4c9e043adfd4b7d97090a3b038d1bb1103c4 Mon Sep 17 00:00:00 2001 From: SunBK201 Date: Fri, 15 Nov 2024 01:41:05 +0800 Subject: [PATCH] feat: migrate from opkg to ipkg and restructure package files for ua3f service --- build.sh | 11 +++- {opkg => ipkg}/CONTROL/control | 4 +- {opkg => ipkg}/CONTROL/control-e | 4 +- {opkg => ipkg}/CONTROL/postinst | 0 {opkg => ipkg}/CONTROL/prerm | 0 opkg/etc/config/ua3f | 10 ---- opkg/etc/init.d/ua3f | 66 --------------------- opkg/usr/lib/lua/luci/controller/ua3f.lua | 5 -- opkg/usr/lib/lua/luci/model/cbi/ua3f.lua | 70 ----------------------- 9 files changed, 14 insertions(+), 156 deletions(-) rename {opkg => ipkg}/CONTROL/control (82%) rename {opkg => ipkg}/CONTROL/control-e (82%) rename {opkg => ipkg}/CONTROL/postinst (100%) rename {opkg => ipkg}/CONTROL/prerm (100%) delete mode 100644 opkg/etc/config/ua3f delete mode 100755 opkg/etc/init.d/ua3f delete mode 100755 opkg/usr/lib/lua/luci/controller/ua3f.lua delete mode 100755 opkg/usr/lib/lua/luci/model/cbi/ua3f.lua diff --git a/build.sh b/build.sh index a7e79fa..9e4e088 100755 --- a/build.sh +++ b/build.sh @@ -59,8 +59,17 @@ for file in ./*; do done cd .. -opkg_template=./opkg +opkg_template=./ipkg ipkg_build=ipkg-build.sh +mkdir -p $opkg_template/usr/bin +mkdir -p $opkg_template/usr/lib/lua/luci/controller +mkdir -p $opkg_template/usr/lib/lua/luci/model/cbi +mkdir -p $opkg_template/etc/init.d +mkdir -p $opkg_template/etc/config +cp openwrt/files/luci/controller.lua $opkg_template/usr/lib/lua/luci/controller/ +cp openwrt/files/luci/cbi.lua $opkg_template/usr/lib/lua/luci/model/cbi/ +cp openwrt/files/ua3f.init $opkg_template/etc/init.d/ua3f +cp openwrt/files/ua3f.uci $opkg_template/etc/config/ua3f for goarch in "amd64" "arm" "arm64" "mipsle" "mips64" "riscv64" "386" "mipsle-softfloat" "mipsle-hardfloat" "armv7" "armv8"; do obj_name=$project_name-$release_version-$goarch mv $dist/bin/$obj_name $opkg_template/usr/bin/ua3f diff --git a/opkg/CONTROL/control b/ipkg/CONTROL/control similarity index 82% rename from opkg/CONTROL/control rename to ipkg/CONTROL/control index dc3322f..5efbab6 100644 --- a/opkg/CONTROL/control +++ b/ipkg/CONTROL/control @@ -1,11 +1,11 @@ Package: ua3f Version: 0.6.0-1 -Depends: libc, luci-compat +Depends: luci-compat Source: /feed/openwrt SourceName: UA3F License: GPL-3.0-only Section: net SourceDateEpoch: 1711267200 Architecture: all -Installed-Size: 2775040 +Installed-Size: 3563520 Description: Implementation of the next generation of HTTP User-Agent modification methodology. diff --git a/opkg/CONTROL/control-e b/ipkg/CONTROL/control-e similarity index 82% rename from opkg/CONTROL/control-e rename to ipkg/CONTROL/control-e index dc3322f..6d0cd3f 100644 --- a/opkg/CONTROL/control-e +++ b/ipkg/CONTROL/control-e @@ -1,11 +1,11 @@ Package: ua3f Version: 0.6.0-1 -Depends: libc, luci-compat +Depends: luci-compat Source: /feed/openwrt SourceName: UA3F License: GPL-3.0-only Section: net SourceDateEpoch: 1711267200 Architecture: all -Installed-Size: 2775040 +Installed-Size: 3686400 Description: Implementation of the next generation of HTTP User-Agent modification methodology. diff --git a/opkg/CONTROL/postinst b/ipkg/CONTROL/postinst similarity index 100% rename from opkg/CONTROL/postinst rename to ipkg/CONTROL/postinst diff --git a/opkg/CONTROL/prerm b/ipkg/CONTROL/prerm similarity index 100% rename from opkg/CONTROL/prerm rename to ipkg/CONTROL/prerm diff --git a/opkg/etc/config/ua3f b/opkg/etc/config/ua3f deleted file mode 100644 index 93b4153..0000000 --- a/opkg/etc/config/ua3f +++ /dev/null @@ -1,10 +0,0 @@ -config 'ua3f' 'enabled' - option enabled '0' - -config 'ua3f' 'main' - option port '1080' - option bind '127.0.0.1' - option ua 'FFF' - option ua_regex '(iPhone|iPad|Android|Macintosh|Windows|Linux|Apple|Mac OS X)' - option partial_replace false - option log_level 'info' \ No newline at end of file diff --git a/opkg/etc/init.d/ua3f b/opkg/etc/init.d/ua3f deleted file mode 100755 index 29cf225..0000000 --- a/opkg/etc/init.d/ua3f +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/sh /etc/rc.common - -USE_PROCD=1 - -START=99 - -NAME="ua3f" -PROG="/usr/bin/$NAME" - -start_service() { - config_load "$NAME" - - local enabled - config_get_bool enabled "enabled" "enabled" "0" - if [ "$enabled" -ne "1" ]; then - return 1 - fi - - local port - local bind - local ua - local log_level - local ua_regex - local partial_replace - config_get port "main" "port" "1080" - config_get bind "main" "bind" "127.0.0.1" - config_get ua "main" "ua" "FFF" - config_get ua_regex "main" "ua_regex" "(iPhone|iPad|Android|Macintosh|Windows|Linux)" - config_get_bool partial_replace "main" "partial_replace" 0 - config_get log_level "main" "log_level" "info" - - mkdir -p /var/log/ua3f - chmod o+w /var/log/ua3f - - procd_open_instance "$NAME" - procd_set_param command "$PROG" - procd_append_param command -b "$bind" - procd_append_param command -p $port - procd_append_param command -f "$ua" - procd_append_param command -r "$ua_regex" - procd_append_param command -l $log_level - [ "$partial_replace" = "1" ] && procd_append_param command -s - - procd_set_param respawn - procd_set_param stdout 1 - procd_set_param stderr 1 - - if id -u shellclash >/dev/null 2>&1; then - procd_set_param user shellclash - elif id -u shellcrash >/dev/null 2>&1; then - procd_set_param user shellcrash - elif id -u nobody >/dev/null 2>&1; then - procd_set_param user nobody - fi - - procd_close_instance -} - -reload_service() { - stop - start -} - -service_triggers() { - procd_add_reload_trigger "$NAME" -} diff --git a/opkg/usr/lib/lua/luci/controller/ua3f.lua b/opkg/usr/lib/lua/luci/controller/ua3f.lua deleted file mode 100755 index 6145e37..0000000 --- a/opkg/usr/lib/lua/luci/controller/ua3f.lua +++ /dev/null @@ -1,5 +0,0 @@ -module("luci.controller.ua3f", package.seeall) - -function index() - entry({ "admin", "services", "ua3f" }, cbi("ua3f"), "UA3F", 1) -end diff --git a/opkg/usr/lib/lua/luci/model/cbi/ua3f.lua b/opkg/usr/lib/lua/luci/model/cbi/ua3f.lua deleted file mode 100755 index 0686201..0000000 --- a/opkg/usr/lib/lua/luci/model/cbi/ua3f.lua +++ /dev/null @@ -1,70 +0,0 @@ -local uci = require("luci.model.uci").cursor() - -ua3f = Map("ua3f", - "UA3F", - [[ - Version: 0.6.0 -
- Across the Campus we can reach every corner in the world. - ]] -) - -enable = ua3f:section(NamedSection, "enabled", "ua3f", "Status") -main = ua3f:section(NamedSection, "main", "ua3f", "Settings") - -enable:option(Flag, "enabled", "Enabled") -status = enable:option(DummyValue, "status", "Status") -status.rawhtml = true -status.cfgvalue = function(self, section) - local pid = luci.sys.exec("pidof ua3f") - if pid == "" then - return "" .. "Stopped" .. "" - else - return "" .. "Running" .. "" - end -end - -main:tab("general", "General Settings") -main:tab("log", "Log") - -port = main:taboption("general", Value, "port", "Port") -port.placeholder = "1080" - -bind = main:taboption("general", Value, "bind", "Bind Address") -bind:value("127.0.0.1") -bind:value("0.0.0.0") - -log_level = main:taboption("general", ListValue, "log_level", "Log Level") -log_level:value("debug") -log_level:value("info") -log_level:value("warn") -log_level:value("error") -log_level:value("fatal") -log_level:value("panic") -log = main:taboption("log", TextValue, "") -log.readonly = true -log.cfgvalue = function(self, section) - return luci.sys.exec("cat /var/log/ua3f/ua3f.log") -end -log.rows = 30 - -ua = main:taboption("general", Value, "ua", "User-Agent") -ua.placeholder = "FFF" - -uaRegexPattern = main:taboption("general", Value, "ua_regex", "User-Agent Regex Pattern") -uaRegexPattern.placeholder = "(iPhone|iPad|Android|Macintosh|Windows|Linux|Apple|Mac OS X)" -uaRegexPattern.description = "Regular expression pattern for matching User-Agent" - -partialRepalce = main:taboption("general", Flag, "partial_replace", "Partial Replace") -partialRepalce.description = -"Replace only the matched part of the User-Agent, only works when User-Agent Regex Pattern is not empty" -partialRepalce.default = "0" - ---[[ -local apply = luci.http.formvalue("cbi.apply") -if apply then - io.popen("/etc/init.d/ua3f restart") -end ---]] - -return ua3f