From: Tianling Shen Date: Wed, 28 May 2025 09:20:08 +0000 (+0800) Subject: dufs: add new package X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=2c8a641e0a396dd992bfda6f02234a2bdb5a6e5e;p=feed%2Fpackages.git dufs: add new package Dufs is a distinctive utility file server that supports static serving, uploading, searching, accessing control, webdav... Signed-off-by: Tianling Shen --- diff --git a/net/dufs/Makefile b/net/dufs/Makefile new file mode 100644 index 0000000000..5d3e3a5543 --- /dev/null +++ b/net/dufs/Makefile @@ -0,0 +1,54 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2024-2025 ImmortalWrt.org + +include $(TOPDIR)/rules.mk + +PKG_NAME:=dufs +PKG_VERSION:=0.43.0 +PKG_RELEASE:=1 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://codeload.github.com/sigoden/dufs/tar.gz/v$(PKG_VERSION)? +PKG_HASH:=4ba3b90486336efc4e592bcf15f14d4e3b6ac7b3b1bf8770815b8c43975d8b01 + +PKG_MAINTAINER:=Tianling Shen +PKG_LICENSE:=Apache-2.0 MIT +PKG_LICENSE_FILES:=LICENSE-APACHE LICENSE-MIT + +PKG_BUILD_DEPENDS:=rust/host +PKG_BUILD_PARALLEL:=1 + +include $(INCLUDE_DIR)/package.mk +include ../../lang/rust/rust-package.mk + +define Package/dufs + SECTION:=net + CATEGORY:=Network + SUBMENU:=Web Servers/Proxies + TITLE:=A distinctive utility file server + URL:=https://github.com/sigoden/dufs + DEPENDS:=$(RUST_ARCH_DEPENDS) @!(i386||mips64) +liblzma +endef + +define Package/dufs/description + Dufs is a distinctive utility file server that supports static + serving, uploading, searching, accessing control, webdav... +endef + +define Package/dufs/conffiles +/etc/config/dufs +endef + +define Package/dufs/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/bin/dufs $(1)/usr/bin/ + + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_CONF) $(CURDIR)/files/dufs.config $(1)/etc/config/dufs + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) $(CURDIR)/files/dufs.init $(1)/etc/init.d/dufs +endef + +$(eval $(call RustBinPackage,dufs)) +$(eval $(call BuildPackage,dufs)) diff --git a/net/dufs/files/dufs.config b/net/dufs/files/dufs.config new file mode 100644 index 0000000000..f7c9164859 --- /dev/null +++ b/net/dufs/files/dufs.config @@ -0,0 +1,46 @@ + +config dufs 'config' + option enabled '0' + + # Specify bind address or unix socket + option bind '' + # Specify port to listen on + option port '5000' + # Specify a (URL) path prefix + option path_prefix '' + # Path to an SSL/TLS certificate to serve with HTTPS + option tls_cert '' + # Path to the SSL/TLS certificate's private key + option tls_key '' + # Enable CORS, sets `Access-Control-Allow-Origin: *` + option enable_cors '0' + # Allow access from Internet + option internet '0' + + # Specific path to serve + option serve_path '/mnt' + # Add auth roles, e.g. user:pass@/dir1:rw,/dir2 + list auth '' + # Hide paths from directory listings, e.g. tmp,*.log,*.lock + list hidden '' + + # Serve index.html when requesting a directory, returns 404 if not found index.html + option render_index '0' + # Serve index.html when requesting a directory, returns directory listing if not found index.html (enabled by default) + option render_try_index '1' + + # Allow all operations + option allow_all '0' + # Allow upload files/folders + option allow_upload '0' + # Allow delete files/folders + option allow_delete '0' + # Allow search files/folders + option allow_search '0' + # Allow symlink to files/folders outside root directory + option allow_symlink '0' + # Allow zip archive generation + option allow_archive '0' + # Set zip compress level [possible values: none, low, medium, high] + option compress '' + diff --git a/net/dufs/files/dufs.init b/net/dufs/files/dufs.init new file mode 100644 index 0000000000..0ca1b2b4e7 --- /dev/null +++ b/net/dufs/files/dufs.init @@ -0,0 +1,105 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2024-2025 Tianling Shen + +START=99 +USE_PROCD=1 + +CONF="dufs" +PROG="/usr/bin/dufs" + +is_enabled() { + local enabled + config_get_bool enabled "$1" "$2" "${3:-0}" + if [ "$enabled" -eq "1" ]; then + return 0 + else + return 1 + fi +} + +append_param() { + procd_append_param command "$1" $2 +} + +append_param_arg() { + local value + config_get value "$1" "$2" $3 + [ -n "$value" ] && append_param "--${2//_/-}" "$value" +} + +append_param_bool() { + is_enabled "$1" "$2" && append_param "--${2//_/-}" +} + +start_service() { + config_load "$CONF" + + is_enabled "config" "enabled" || return 1 + + procd_open_instance "$CONF" + procd_set_param command "$PROG" + + append_param_arg "config" "bind" + append_param_arg "config" "port" "5000" + append_param_arg "config" "path_prefix" + append_param_arg "config" "tls_cert" + append_param_arg "config" "tls_key" + append_param_bool "config" "enable_cors" + + local auth_roles hidden + config_get auth_roles "config" "auth" + config_get hidden "config" "hidden" + [ -z "$auth_roles" ] || config_list_foreach "config" "auth" "append_param '--auth'" + [ -z "$hidden" ] || config_list_foreach "config" "hidden" "append_param '--hidden'" + + append_param_bool "config" "render_index" + append_param_bool "config" "render_try_index" "1" + + append_param_bool "config" "allow_all" + append_param_bool "config" "allow_upload" + append_param_bool "config" "allow_delete" + append_param_bool "config" "allow_search" + append_param_bool "config" "allow_symlink" + append_param_bool "config" "allow_archive" + append_param_arg "config" "compress" + + local serve_path + config_get serve_path "config" "serve_path" "/mnt" + append_param "$serve_path" + + procd_set_param limits core="unlimited" + procd_set_param limits nofile="1000000 1000000" + procd_set_param respawn + procd_set_param stderr 1 + + if is_enabled "config" "internet"; then + local listen_port + config_get listen_port "config" "port" "5000" + procd_open_data + json_add_array firewall + json_add_object "" + json_add_string type rule + json_add_string name "Allow-access-dufs-at-$listen_port" + json_add_string src "*" + json_add_string dest_port "$listen_port" + json_add_string proto tcp + json_add_string target ACCEPT + json_close_object + json_close_array + procd_close_data + fi + + procd_close_instance +} + +service_started() { + procd_set_config_changed firewall +} + +service_stopped() { + procd_set_config_changed firewall +} + +service_triggers() { + procd_add_reload_trigger "$CONF" +}