diff --git a/package/lean/aliyundrive-webdav/Makefile b/package/lean/aliyundrive-webdav/Makefile new file mode 100644 index 000000000..6bce290e8 --- /dev/null +++ b/package/lean/aliyundrive-webdav/Makefile @@ -0,0 +1,76 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=aliyundrive-webdav +PKG_VERSION:=0.4.0 +PKG_RELEASE:=1 + +PKG_LICENSE:=MIT +PKG_MAINTAINER:=messense + +PKG_LIBC:=musl +ifeq ($(ARCH),arm) + PKG_LIBC:=musleabi + + ARM_CPU_FEATURES:=$(word 2,$(subst +,$(space),$(call qstrip,$(CONFIG_CPU_TYPE)))) + ifneq ($(filter $(ARM_CPU_FEATURES),vfp vfpv2),) + PKG_LIBC:=musleabihf + endif +endif + +PKG_ARCH=$(ARCH) +ifeq ($(ARCH),i386) + PKG_ARCH:=i686 +endif + +PKG_SOURCE:=aliyundrive-webdav-$(PKG_ARCH)-unknown-linux-$(PKG_LIBC).tar.gz +PKG_SOURCE_URL:=https://github.com/messense/aliyundrive-webdav/releases/download/v$(PKG_VERSION)/ +PKG_HASH:=skip + +include $(INCLUDE_DIR)/package.mk + +define Package/aliyundrive-webdav + SECTION:=multimedia + CATEGORY:=Multimedia + TITLE:=WebDAV server for AliyunDrive + URL:=https://github.com/messense/aliyundrive-webdav +endef + +define Package/aliyundrive-webdav/description +WebDAV server for AliyunDrive. +endef + +define Package/aliyundrive-webdav/conffiles +/etc/config/aliyundrive-webdav +endef + +define Download/sha256sum + FILE:=$(PKG_SOURCE).sha256 + URL_FILE:=$(FILE) + URL:=$(PKG_SOURCE_URL) + HASH:=skip +endef +$(eval $(call Download,sha256sum)) + +define Build/Prepare + mv $(DL_DIR)/$(PKG_SOURCE).sha256 . + cp $(DL_DIR)/$(PKG_SOURCE) . + shasum -a 256 -c $(PKG_SOURCE).sha256 + rm $(PKG_SOURCE).sha256 $(PKG_SOURCE) + + tar -C $(PKG_BUILD_DIR)/ -zxf $(DL_DIR)/$(PKG_SOURCE) +endef + +define Build/Compile + echo "aliyundrive-webdav using precompiled binary." +endef + +define Package/aliyundrive-webdav/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/aliyundrive-webdav $(1)/usr/bin/aliyundrive-webdav + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/aliyundrive-webdav.init $(1)/etc/init.d/aliyundrive-webdav + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_CONF) ./files/aliyundrive-webdav.config $(1)/etc/config/aliyundrive-webdav +endef + +$(eval $(call BuildPackage,aliyundrive-webdav)) diff --git a/package/lean/aliyundrive-webdav/files/aliyundrive-webdav.config b/package/lean/aliyundrive-webdav/files/aliyundrive-webdav.config new file mode 100644 index 000000000..74248f63e --- /dev/null +++ b/package/lean/aliyundrive-webdav/files/aliyundrive-webdav.config @@ -0,0 +1,11 @@ +config server + option enable '0' + option debug '0' + option refresh_token '' + option host '0.0.0.0' + option port '8080' + option auth_user '' + option auth_password '' + option read_buffer_size '10485760' + option cache_size '1000' + option root '/' diff --git a/package/lean/aliyundrive-webdav/files/aliyundrive-webdav.init b/package/lean/aliyundrive-webdav/files/aliyundrive-webdav.init new file mode 100755 index 000000000..6a5212653 --- /dev/null +++ b/package/lean/aliyundrive-webdav/files/aliyundrive-webdav.init @@ -0,0 +1,47 @@ +#!/bin/sh /etc/rc.common + +USE_PROCD=1 + +START=99 +STOP=15 + +NAME=aliyundrive-webdav + +uci_get_by_type() { + local ret=$(uci get $NAME.@$1[0].$2 2>/dev/null) + echo ${ret:=$3} +} + +start_service() { + local enable=$(uci_get_by_type server enable) + case "$enable" in + 1|on|true|yes|enabled) + local refresh_token=$(uci_get_by_type server refresh_token) + local auth_user=$(uci_get_by_type server auth_user) + local auth_password=$(uci_get_by_type server auth_password) + local read_buf_size=$(uci_get_by_type server read_buffer_size 10485760) + local cache_size=$(uci_get_by_type server cache_size 1000) + local host=$(uci_get_by_type server host 127.0.0.1) + local port=$(uci_get_by_type server port 8080) + local root=$(uci_get_by_type server root /) + + procd_open_instance + procd_set_param command /bin/sh -c "/usr/bin/$NAME -I --host $host --port $port --root $root -S $read_buf_size --cache-size $cache_size --workdir /var/run/$NAME >>/var/log/$NAME.log 2>&1" + procd_set_param pidfile /var/run/$NAME.pid + procd_set_param env REFRESH_TOKEN="$refresh_token" + [[ ! -z "$auth_user" ]] && procd_append_param env WEBDAV_AUTH_USER="$auth_user" + [[ ! -z "$auth_password" ]] && procd_append_param env WEBDAV_AUTH_PASSWORD="$auth_password" + case $(uci_get_by_type server debug) in + 1|on|true|yes|enabled) + procd_append_param env RUST_LOG="aliyundrive_webdav=debug" ;; + *) ;; + esac + procd_close_instance ;; + *) + stop_service ;; + esac +} + +service_triggers() { + procd_add_reload_trigger "/etc/config/$NAME" +} diff --git a/package/lean/luci-app-aliyundrive-webdav/Makefile b/package/lean/luci-app-aliyundrive-webdav/Makefile new file mode 100644 index 000000000..a36cb36a5 --- /dev/null +++ b/package/lean/luci-app-aliyundrive-webdav/Makefile @@ -0,0 +1,16 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-aliyundrive-webdav +PKG_VERSION:=0.4.0 +PKG_RELEASE:=1 + +PKG_LICENSE:=MIT +PKG_MAINTAINER:=messense + +LUCI_TITLE:=LuCI Support for aliyundrive-webdav +LUCI_PKGARCH:=all +LUCI_DEPENDS:=+aliyundrive-webdav +lua +libuci-lua + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/package/lean/luci-app-aliyundrive-webdav/luasrc/controller/aliyundrive-webdav.lua b/package/lean/luci-app-aliyundrive-webdav/luasrc/controller/aliyundrive-webdav.lua new file mode 100644 index 000000000..0829ad2a3 --- /dev/null +++ b/package/lean/luci-app-aliyundrive-webdav/luasrc/controller/aliyundrive-webdav.lua @@ -0,0 +1,35 @@ +module("luci.controller.aliyundrive-webdav", package.seeall) + +function index() + if not nixio.fs.access("/etc/config/aliyundrive-webdav") then + return + end + entry({"admin", "services", "aliyundrive-webdav"}, alias("admin", "services", "aliyundrive-webdav", "client"),_("AliyunDrive WebDAV"), 10).dependent = true -- 首页 + entry({"admin", "services", "aliyundrive-webdav", "client"}, cbi("aliyundrive-webdav/client"),_("Settings"), 10).leaf = true -- 客户端配置 + entry({"admin", "services", "aliyundrive-webdav", "log"}, form("aliyundrive-webdav/log"),_("Log"), 30).leaf = true -- 日志页面 + + entry({"admin", "services", "aliyundrive-webdav", "status"}, call("action_status")).leaf = true + entry({"admin", "services", "aliyundrive-webdav", "logtail"}, call("action_logtail")).leaf = true +end + +function action_status() + local e = {} + e.running = luci.sys.call("pidof aliyundrive-webdav >/dev/null") == 0 + e.application = luci.sys.exec("aliyundrive-webdav --version") + luci.http.prepare_content("application/json") + luci.http.write_json(e) +end + +function action_logtail() + local fs = require "nixio.fs" + local log_path = "/var/log/aliyundrive-webdav.log" + local e = {} + e.running = luci.sys.call("pidof aliyundrive-webdav >/dev/null") == 0 + if fs.access(log_path) then + e.log = luci.sys.exec("tail -n 100 %s | sed 's/\\x1b\\[[0-9;]*m//g'" % log_path) + else + e.log = "" + end + luci.http.prepare_content("application/json") + luci.http.write_json(e) +end diff --git a/package/lean/luci-app-aliyundrive-webdav/luasrc/model/cbi/aliyundrive-webdav/client.lua b/package/lean/luci-app-aliyundrive-webdav/luasrc/model/cbi/aliyundrive-webdav/client.lua new file mode 100644 index 000000000..98c319db5 --- /dev/null +++ b/package/lean/luci-app-aliyundrive-webdav/luasrc/model/cbi/aliyundrive-webdav/client.lua @@ -0,0 +1,48 @@ +local uci = luci.model.uci.cursor() +local m, e + +m = Map("aliyundrive-webdav", translate("AliyunDrive WebDAV"), + translate("Project GitHub URL")) + +m:section(SimpleSection).template = "aliyundrive-webdav/aliyundrive-webdav_status" + +e = m:section(TypedSection, "server") +e.anonymous = true + +enable = e:option(Flag, "enable", translate("Enable")) +enable.rmempty = false + +refresh_token = e:option(Value, "refresh_token", translate("Refresh Token"), + translate("How to get refresh token")) + +root = e:option(Value, "root", translate("Root Directory")) +root.default = "/" + +host = e:option(Value, "host", translate("Host")) +host.default = "0.0.0.0" +host.datatype = "ipaddr" + +port = e:option(Value, "port", translate("Port")) +port.default = "8080" +port.datatype = "port" + +auth_user = e:option(Value, "auth_user", translate("Username")) +auth_password = e:option(Value, "auth_password", translate("Password")) +auth_password.password = true + +read_buffer_size = e:option(Value, "read_buffer_size", translate("Read Buffer Size")) +read_buffer_size.default = "10485760" +read_buffer_size.datatype = "uinteger" + +cache_size = e:option(Value, "cache_size", translate("Cache Size")) +cache_size.default = "1000" +cache_size.datatype = "uinteger" + +debug = e:option(Flag, "debug", translate("Debug Mode")) +debug.rmempty = false + +local e = luci.http.formvalue("cbi.apply") +if e then + io.popen("/etc/init.d/aliyundrive-webdav restart") +end +return m diff --git a/package/lean/luci-app-aliyundrive-webdav/luasrc/model/cbi/aliyundrive-webdav/log.lua b/package/lean/luci-app-aliyundrive-webdav/luasrc/model/cbi/aliyundrive-webdav/log.lua new file mode 100644 index 000000000..200cb1928 --- /dev/null +++ b/package/lean/luci-app-aliyundrive-webdav/luasrc/model/cbi/aliyundrive-webdav/log.lua @@ -0,0 +1,9 @@ +log = SimpleForm("logview") +log.submit = false +log.reset = false + +t = log:field(DummyValue, '', '') +t.rawhtml = true +t.template = 'aliyundrive-webdav/aliyundrive-webdav_log' + +return log diff --git a/package/lean/luci-app-aliyundrive-webdav/luasrc/view/aliyundrive-webdav/aliyundrive-webdav_log.htm b/package/lean/luci-app-aliyundrive-webdav/luasrc/view/aliyundrive-webdav/aliyundrive-webdav_log.htm new file mode 100644 index 000000000..fd125856f --- /dev/null +++ b/package/lean/luci-app-aliyundrive-webdav/luasrc/view/aliyundrive-webdav/aliyundrive-webdav_log.htm @@ -0,0 +1,15 @@ +<%+cbi/valueheader%> + + + +<%+cbi/valuefooter%> diff --git a/package/lean/luci-app-aliyundrive-webdav/luasrc/view/aliyundrive-webdav/aliyundrive-webdav_status.htm b/package/lean/luci-app-aliyundrive-webdav/luasrc/view/aliyundrive-webdav/aliyundrive-webdav_status.htm new file mode 100644 index 000000000..39bd7d421 --- /dev/null +++ b/package/lean/luci-app-aliyundrive-webdav/luasrc/view/aliyundrive-webdav/aliyundrive-webdav_status.htm @@ -0,0 +1,21 @@ + + +
+

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

+
diff --git a/package/lean/luci-app-aliyundrive-webdav/po/zh-cn/aliyundrive-webdav.po b/package/lean/luci-app-aliyundrive-webdav/po/zh-cn/aliyundrive-webdav.po new file mode 100644 index 000000000..95347df5c --- /dev/null +++ b/package/lean/luci-app-aliyundrive-webdav/po/zh-cn/aliyundrive-webdav.po @@ -0,0 +1,59 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8\n" + +msgid "AliyunDrive" +msgstr "阿里云盘" + +msgid "AliyunDrive WebDAV" +msgstr "阿里云盘 WebDAV" + +msgid "Enable" +msgstr "启用" + +msgid "Refresh Token" +msgstr "Refresh Token" + +msgid "Root Directory" +msgstr "根目录" + +msgid "Host" +msgstr "监听主机" + +msgid "Port" +msgstr "监听端口" + +msgid "Username" +msgstr "用户名" + +msgid "Password" +msgstr "密码" + +msgid "Read Buffer Size" +msgstr "下载缓冲大小(bytes)" + +msgid "Cache Size" +msgstr "目录缓存大小" + +msgid "Collecting data..." +msgstr "获取数据中..." + +msgid "RUNNING" +msgstr "运行中" + +msgid "NOT RUNNING" +msgstr "未运行" + +msgid "Settings" +msgstr "设置" + +msgid "Log" +msgstr "日志" + +msgid "Debug Mode" +msgstr "调试模式" + +msgid "Project GitHub URL" +msgstr "GitHub 项目地址" + +msgid "How to get refresh token" +msgstr "查看获取 refresh token 的方法" diff --git a/package/lean/luci-app-aliyundrive-webdav/root/etc/uci-defaults/luci-aliyundrive-webdav b/package/lean/luci-app-aliyundrive-webdav/root/etc/uci-defaults/luci-aliyundrive-webdav new file mode 100755 index 000000000..69c5433ca --- /dev/null +++ b/package/lean/luci-app-aliyundrive-webdav/root/etc/uci-defaults/luci-aliyundrive-webdav @@ -0,0 +1,11 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@aliyundrive-webdav[-1] + add ucitrack aliyundrive-webdav + set ucitrack.@aliyundrive-webdav[-1].init=aliyundrive-webdav + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +exit 0