From eff943777d13f754cf055285fb3ded9a29d7630b Mon Sep 17 00:00:00 2001 From: Beginner <70857188+Beginner-Go@users.noreply.github.com> Date: Sun, 31 Oct 2021 17:04:10 +0800 Subject: [PATCH] luci-app-go-aliyundrive-webdav: add package (#8112) Signed-off-by: Beginner-Go <70857188+Beginner-Go@users.noreply.github.com> --- package/lean/go-aliyundrive-webdav/Makefile | 81 +++++++++++++++++++ .../files/go-aliyundrive-webdav.config | 23 ++++++ .../files/go-aliyundrive-webdav.init | 50 ++++++++++++ ...x-read-version-from-Version-variable.patch | 30 +++++++ .../luci-app-go-aliyundrive-webdav/Makefile | 15 ++++ .../controller/go-aliyundrive-webdav.lua | 23 ++++++ .../cbi/go-aliyundrive-webdav/client.lua | 49 +++++++++++ .../model/cbi/go-aliyundrive-webdav/log.lua | 4 + .../go-aliyundrive-webdav_status.htm | 30 +++++++ .../po/zh-cn/go-aliyundrive-webdav.po | 58 +++++++++++++ .../luci-app-go-aliyundrive-webdav/po/zh_Hans | 1 + .../uci-defaults/luci-go-aliyundrive-webdav | 11 +++ .../acl.d/luci-app-go-aliyundrive-webdav.json | 11 +++ 13 files changed, 386 insertions(+) create mode 100644 package/lean/go-aliyundrive-webdav/Makefile create mode 100644 package/lean/go-aliyundrive-webdav/files/go-aliyundrive-webdav.config create mode 100755 package/lean/go-aliyundrive-webdav/files/go-aliyundrive-webdav.init create mode 100644 package/lean/go-aliyundrive-webdav/patches/100-fix-read-version-from-Version-variable.patch create mode 100644 package/lean/luci-app-go-aliyundrive-webdav/Makefile create mode 100644 package/lean/luci-app-go-aliyundrive-webdav/luasrc/controller/go-aliyundrive-webdav.lua create mode 100644 package/lean/luci-app-go-aliyundrive-webdav/luasrc/model/cbi/go-aliyundrive-webdav/client.lua create mode 100644 package/lean/luci-app-go-aliyundrive-webdav/luasrc/model/cbi/go-aliyundrive-webdav/log.lua create mode 100644 package/lean/luci-app-go-aliyundrive-webdav/luasrc/view/go-aliyundrive-webdav/go-aliyundrive-webdav_status.htm create mode 100644 package/lean/luci-app-go-aliyundrive-webdav/po/zh-cn/go-aliyundrive-webdav.po create mode 120000 package/lean/luci-app-go-aliyundrive-webdav/po/zh_Hans create mode 100755 package/lean/luci-app-go-aliyundrive-webdav/root/etc/uci-defaults/luci-go-aliyundrive-webdav create mode 100644 package/lean/luci-app-go-aliyundrive-webdav/root/usr/share/rpcd/acl.d/luci-app-go-aliyundrive-webdav.json diff --git a/package/lean/go-aliyundrive-webdav/Makefile b/package/lean/go-aliyundrive-webdav/Makefile new file mode 100644 index 000000000..fe355abf3 --- /dev/null +++ b/package/lean/go-aliyundrive-webdav/Makefile @@ -0,0 +1,81 @@ +# SPDX-Identifier-License: GPL-3.0-only +# +# Copyright (C) 2021 ImmortalWrt.org + +include $(TOPDIR)/rules.mk + +PKG_NAME:=go-aliyundrive-webdav +PKG_VERSION:=1.0.12 +PKG_RELEASE:=$(AUTORELEASE) + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://codeload.github.com/LinkLeong/go-aliyundrive-webdav/tar.gz/v$(PKG_VERSION)? +PKG_HASH:=eb60256131240adaa34e2039114237f8cdd9016233da1a417dace6b10bda4d61 + +PKG_LICENSE:=Apache-2.0 +PKG_LICENSE_FILE:=LICENSE +PKG_MAINTAINER:=Tianling Shen + +PKG_CONFIG_DEPENDS:= \ + CONFIG_GO_ALIYUNDRIVE_WEBDAV_COMPRESS_GOPROXY \ + CONFIG_GO_ALIYUNDRIVE_WEBDAV_COMPRESS_UPX + +PKG_BUILD_DEPENDS:=golang/host +PKG_BUILD_PARALLEL:=1 +PKG_USE_MIPS16:=0 + +GO_PKG:=go-aliyun-webdav +GO_PKG_LDFLAGS:=-s -w +GO_PKG_LDFLAGS_X:=main.Version=v$(PKG_VERSION) + +include $(INCLUDE_DIR)/package.mk +include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk + +define Package/go-aliyundrive-webdav + SECTION:=net + CATEGORY:=Network + SUBMENU:=File Transfer + TITLE:=A WebDav server for AliyunDrive + URL:=https://github.com/LinkLeong/go-aliyundrive-webdav + DEPENDS:=$(GO_ARCH_DEPENDS) +endef + +define Package/go-aliyundrive-webdav/config +config GO_ALIYUNDRIVE_WEBDAV_COMPRESS_GOPROXY + bool "Compiling with GOPROXY proxy" + default n + +config GO_ALIYUNDRIVE_WEBDAV_COMPRESS_UPX + bool "Compress executable files with UPX" + default y +endef + +ifeq ($(CONFIG_GO_ALIYUNDRIVE_WEBDAV_COMPRESS_GOPROXY),y) + export GO111MODULE=on + export GOPROXY=https://goproxy.baidu.com +endif + +define Package/go-aliyundrive-webdav/conffiles +/etc/config/go-aliyundrive-webdav +endef + +define Build/Compile + $(call GoPackage/Build/Compile) +ifeq ($(CONFIG_GO_ALIYUNDRIVE_WEBDAV_COMPRESS_UPX),y) + $(STAGING_DIR_HOST)/bin/upx --lzma --best $(GO_PKG_BUILD_BIN_DIR)/go-aliyun-webdav +endif +endef + +define Package/go-aliyundrive-webdav/install + $(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR)) + $(INSTALL_DIR) $(1)/usr/bin/ + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/go-aliyun-webdav $(1)/usr/bin/go-aliyundrive-webdav + + $(INSTALL_DIR) $(1)/etc/config/ + $(INSTALL_CONF) $(CURDIR)/files/go-aliyundrive-webdav.config $(1)/etc/config/go-aliyundrive-webdav + $(INSTALL_DIR) $(1)/etc/init.d/ + $(INSTALL_BIN) $(CURDIR)/files/go-aliyundrive-webdav.init $(1)/etc/init.d/go-aliyundrive-webdav +endef + +$(eval $(call GoBinPackage,go-aliyundrive-webdav)) +$(eval $(call BuildPackage,go-aliyundrive-webdav)) diff --git a/package/lean/go-aliyundrive-webdav/files/go-aliyundrive-webdav.config b/package/lean/go-aliyundrive-webdav/files/go-aliyundrive-webdav.config new file mode 100644 index 000000000..d6ed4edde --- /dev/null +++ b/package/lean/go-aliyundrive-webdav/files/go-aliyundrive-webdav.config @@ -0,0 +1,23 @@ + + +config go-aliyundrive-webdav 'config' + option enabled '0' + + # Listening port + option port '8085' + + # Refresh token + option rt '' + + # Mounting directory + option path '/' + + # Webdav auth username, default: admin + option user 'admin' + + # Webdav auth password, default: 123456 + option pwd '123456' + + # Enable detailed logging + option verbose '0' + diff --git a/package/lean/go-aliyundrive-webdav/files/go-aliyundrive-webdav.init b/package/lean/go-aliyundrive-webdav/files/go-aliyundrive-webdav.init new file mode 100755 index 000000000..9eff96e2e --- /dev/null +++ b/package/lean/go-aliyundrive-webdav/files/go-aliyundrive-webdav.init @@ -0,0 +1,50 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2021 Tianling Shen + +USE_PROCD=1 +START=99 + +CONF="go-aliyundrive-webdav" +PROG="/usr/bin/go-aliyundrive-webdav" + +start_service() { + config_load "$CONF" + + local enabled + config_get_bool enabled "config" "enabled" + [ "$enabled" -eq "1" ] || return 1 + + local port rt path user pwd verbose + config_get port "config" "port" + config_get rt "config" "rt" + config_get path "config" "path" + config_get user "config" "user" + config_get pwd "config" "pwd" + config_get_bool verbose "config" "verbose" + + procd_open_instance "$CONF" + + procd_set_param command "$PROG" + + procd_append_param command "-rt" "$rt" + procd_append_param command "-port" "$port" + procd_append_param command "-path" "$path" + procd_append_param command "-user" "$user" + procd_append_param command "-pwd" "$pwd" + [ "$verbose" -eq "0" ] || procd_append_param command "-v" + + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_set_param respawn + + procd_close_instance +} + +reload_service() { + stop + start +} + +service_triggers() { + procd_add_reload_trigger "go-aliyundrive-webdav" +} diff --git a/package/lean/go-aliyundrive-webdav/patches/100-fix-read-version-from-Version-variable.patch b/package/lean/go-aliyundrive-webdav/patches/100-fix-read-version-from-Version-variable.patch new file mode 100644 index 000000000..ed1002419 --- /dev/null +++ b/package/lean/go-aliyundrive-webdav/patches/100-fix-read-version-from-Version-variable.patch @@ -0,0 +1,30 @@ +From a427929b0267a85ef6924aa3449077420beb23e0 Mon Sep 17 00:00:00 2001 +From: Tianling Shen +Date: Sun, 24 Oct 2021 17:11:10 +0800 +Subject: [PATCH] fix: read version from `Version` variable + +Signed-off-by: Tianling Shen +--- + main.go | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +--- a/main.go ++++ b/main.go +@@ -22,7 +22,7 @@ func init() { + cache.Init() + } + +-var Version = "v1.0.3" ++var Version = "v1.0.12" + + type Task struct { + Id string `json:"id"` +@@ -49,7 +49,7 @@ func main() { + flag.Parse() + + if *versin { +- fmt.Println("v1.0.9") ++ fmt.Println(Version) + return + } + if len(*refreshToken) == 0 || len(os.Args) < 3 || os.Args[1] != "-rt" { diff --git a/package/lean/luci-app-go-aliyundrive-webdav/Makefile b/package/lean/luci-app-go-aliyundrive-webdav/Makefile new file mode 100644 index 000000000..1f7f09f71 --- /dev/null +++ b/package/lean/luci-app-go-aliyundrive-webdav/Makefile @@ -0,0 +1,15 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-go-aliyundrive-webdav +PKG_VERSION:=1.0.2 +PKG_RELEASE:=20211031 + +PKG_MAINTAINER:=jerrykuku + +LUCI_TITLE:=Luci for go-aliyundrive-webdav +LUCI_PKGARCH:=all +LUCI_DEPENDS:=+lua +libuci-lua +go-aliyundrive-webdav + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/package/lean/luci-app-go-aliyundrive-webdav/luasrc/controller/go-aliyundrive-webdav.lua b/package/lean/luci-app-go-aliyundrive-webdav/luasrc/controller/go-aliyundrive-webdav.lua new file mode 100644 index 000000000..2fd254361 --- /dev/null +++ b/package/lean/luci-app-go-aliyundrive-webdav/luasrc/controller/go-aliyundrive-webdav.lua @@ -0,0 +1,23 @@ +-- Copyright (C) 2021 jerryk +-- This is free software, licensed under the APACHE LICENSE, VERSION 2.0. + +module("luci.controller.go-aliyundrive-webdav", package.seeall) + +function index() + if not nixio.fs.access("/etc/config/go-aliyundrive-webdav") then + return + end + entry({"admin", "services", "go-aliyundrive-webdav"}, alias("admin", "services", "go-aliyundrive-webdav", "client"),_("Go AliyunDrive WebDAV"), 10).dependent = true -- 首页 + entry({"admin", "services", "go-aliyundrive-webdav", "client"}, cbi("go-aliyundrive-webdav/client"),_("Settings"), 1).leaf = true -- 客户端配置 + entry({"admin", "services", "go-aliyundrive-webdav", "log"}, cbi("go-aliyundrive-webdav/log"),_("Log"), 2).leaf = true -- 日志页面 + + entry({"admin", "services", "go-aliyundrive-webdav", "status"}, call("action_status")).leaf = true + +end + +function action_status() + local e = {} + e.running = luci.sys.call("pidof go-aliyundrive-webdav >/dev/null") == 0 + luci.http.prepare_content("application/json") + luci.http.write_json(e) +end diff --git a/package/lean/luci-app-go-aliyundrive-webdav/luasrc/model/cbi/go-aliyundrive-webdav/client.lua b/package/lean/luci-app-go-aliyundrive-webdav/luasrc/model/cbi/go-aliyundrive-webdav/client.lua new file mode 100644 index 000000000..998b1c70d --- /dev/null +++ b/package/lean/luci-app-go-aliyundrive-webdav/luasrc/model/cbi/go-aliyundrive-webdav/client.lua @@ -0,0 +1,49 @@ +-- Copyright (C) 2021 jerryk +-- This is free software, licensed under the APACHE LICENSE, VERSION 2.0. + + +local uci = luci.model.uci.cursor() +local m, e + +m = Map("go-aliyundrive-webdav") +m.title = translate("Go AliyunDrive WebDAV") +m.description = translate("Project GitHub URL") + +m:section(SimpleSection).template = "go-aliyundrive-webdav/go-aliyundrive-webdav_status" + +e = m:section(TypedSection, "go-aliyundrive-webdav") +e.anonymous = true + +enable = e:option(Flag, "enabled", translate("Enabled")) +enable.rmempty = false + +rt_token = e:option(Value, "rt", translate("Refresh Token")) +rt_token.description = translate("How to get refresh token") + +port = e:option(Value, "port", translate("Port")) +port.default = "8085" +port.datatype = "port" + +path = e:option(Value, "path", translate("Mounting directory")) +path.description = translate("Access aliyundrive directory, defaults /.") +path.default = "/" + +user = e:option(Value, "user", translate("Username")) +user.default = "admin" + +pwd = e:option(Value, "pwd", translate("Password")) +pwd.password = true +pwd.default = "123456" + +verbose = e:option(Flag, "verbose", translate("Enable detailed logging")) +verbose.default = "0" +verbose.rmempty = false +verbose.optional = false + + +local e = luci.http.formvalue("cbi.apply") +if e then + io.popen("/etc/init.d/go-aliyundrive-webdav restart") +end + +return m diff --git a/package/lean/luci-app-go-aliyundrive-webdav/luasrc/model/cbi/go-aliyundrive-webdav/log.lua b/package/lean/luci-app-go-aliyundrive-webdav/luasrc/model/cbi/go-aliyundrive-webdav/log.lua new file mode 100644 index 000000000..157a9946c --- /dev/null +++ b/package/lean/luci-app-go-aliyundrive-webdav/luasrc/model/cbi/go-aliyundrive-webdav/log.lua @@ -0,0 +1,4 @@ +m = Map("log") +m.title = translate("Detailed Log (In Development)") + +return m diff --git a/package/lean/luci-app-go-aliyundrive-webdav/luasrc/view/go-aliyundrive-webdav/go-aliyundrive-webdav_status.htm b/package/lean/luci-app-go-aliyundrive-webdav/luasrc/view/go-aliyundrive-webdav/go-aliyundrive-webdav_status.htm new file mode 100644 index 000000000..25eb5e73c --- /dev/null +++ b/package/lean/luci-app-go-aliyundrive-webdav/luasrc/view/go-aliyundrive-webdav/go-aliyundrive-webdav_status.htm @@ -0,0 +1,30 @@ + + + +
+

+ + <%:Collecting data...%> + +

+
diff --git a/package/lean/luci-app-go-aliyundrive-webdav/po/zh-cn/go-aliyundrive-webdav.po b/package/lean/luci-app-go-aliyundrive-webdav/po/zh-cn/go-aliyundrive-webdav.po new file mode 100644 index 000000000..425610c38 --- /dev/null +++ b/package/lean/luci-app-go-aliyundrive-webdav/po/zh-cn/go-aliyundrive-webdav.po @@ -0,0 +1,58 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8\n" + +msgid "Go AliyunDrive" +msgstr "Go 阿里云盘" + +msgid "Go AliyunDrive WebDAV" +msgstr "Go 阿里云盘 WebDAV" + +msgid "Enabled" +msgstr "启用" + +msgid "Refresh Token" +msgstr "Refresh Token" + +msgid "Port" +msgstr "监听端口" + +msgid "Mounting directory" +msgstr "挂载目录" + +msgid "Access aliyundrive directory, defaults /." +msgstr "访问 aliyundrive 目录,默认为 / 。" + +msgid "Username" +msgstr "用户名" + +msgid "Password" +msgstr "密码" + +msgid "Collecting data..." +msgstr "获取数据中..." + +msgid "RUNNING" +msgstr "运行中" + +msgid "NOT RUNNING" +msgstr "未运行" + +msgid "Settings" +msgstr "设置" + +msgid "Log" +msgstr "日志" + +msgid "Detailed Log (In Development)" +msgstr "详细日志(开发中)" + +msgid "Enable detailed logging" +msgstr "启用详细日志记录" + +msgid "Project GitHub URL" +msgstr "GitHub 项目地址" + +msgid "How to get refresh token" +msgstr "查看获取 refresh token 的方法" + + diff --git a/package/lean/luci-app-go-aliyundrive-webdav/po/zh_Hans b/package/lean/luci-app-go-aliyundrive-webdav/po/zh_Hans new file mode 120000 index 000000000..41451e4a1 --- /dev/null +++ b/package/lean/luci-app-go-aliyundrive-webdav/po/zh_Hans @@ -0,0 +1 @@ +zh-cn \ No newline at end of file diff --git a/package/lean/luci-app-go-aliyundrive-webdav/root/etc/uci-defaults/luci-go-aliyundrive-webdav b/package/lean/luci-app-go-aliyundrive-webdav/root/etc/uci-defaults/luci-go-aliyundrive-webdav new file mode 100755 index 000000000..4ea0e82a1 --- /dev/null +++ b/package/lean/luci-app-go-aliyundrive-webdav/root/etc/uci-defaults/luci-go-aliyundrive-webdav @@ -0,0 +1,11 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@go-aliyundrive-webdav[-1] + add ucitrack go-aliyundrive-webdav + set ucitrack.@go-aliyundrive-webdav[-1].init=go-aliyundrive-webdav + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +exit 0 diff --git a/package/lean/luci-app-go-aliyundrive-webdav/root/usr/share/rpcd/acl.d/luci-app-go-aliyundrive-webdav.json b/package/lean/luci-app-go-aliyundrive-webdav/root/usr/share/rpcd/acl.d/luci-app-go-aliyundrive-webdav.json new file mode 100644 index 000000000..e623bd798 --- /dev/null +++ b/package/lean/luci-app-go-aliyundrive-webdav/root/usr/share/rpcd/acl.d/luci-app-go-aliyundrive-webdav.json @@ -0,0 +1,11 @@ +{ + "luci-app-go-aliyundrive-webdav": { + "description": "Grant UCI access for luci-app-go-aliyundrive-webdav", + "read": { + "uci": [ "go-aliyundrive-webdav" ] + }, + "write": { + "uci": [ "go-aliyundrive-webdav" ] + } + } +}