mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-02 13:53:56 +08:00
🎁 Sync 2026-07-07 20:50:55
This commit is contained in:
1 parent
add8ea0d42
commit
66678c8afc
100 files changed
+5162
-17005
No files matched your search
+15
-7
@@ -7,18 +7,20 @@
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_ARCH_baidudrive:=$(ARCH)
|
||||
PKG_ARCH_BAIDUDRIVE:=$(ARCH)
|
||||
|
||||
PKG_NAME:=baidudrive
|
||||
PKG_VERSION:=0.4.0
|
||||
PKG_RELEASE:=2
|
||||
PKG_VERSION:=1.0.1
|
||||
PKG_RELEASE:=3
|
||||
PKG_SOURCE:=$(PKG_NAME)-binary-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://github.com/Carseason/openwrt-packages/releases/download/prebuilt/
|
||||
PKG_SOURCE_URL:=https://github.com/linkease/istore-packages/releases/download/prebuilt/
|
||||
PKG_HASH:=skip
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-binary-$(PKG_VERSION)
|
||||
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_USE_MIPS16:=0
|
||||
STRIP:=true
|
||||
RSTRIP:=:
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
@@ -27,7 +29,7 @@ define Package/$(PKG_NAME)
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=Web Servers/Proxies
|
||||
TITLE:=BaiduDrive
|
||||
DEPENDS:=@(x86_64||aarch64)
|
||||
DEPENDS:=@(x86_64||aarch64) +curl
|
||||
URL:=https://github.com/linkease/istore-packages
|
||||
endef
|
||||
|
||||
@@ -46,8 +48,14 @@ define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/init.d $(1)/etc/uci-defaults $(1)/etc/config
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/baidudrive.$(PKG_ARCH_baidudrive) $(1)/usr/sbin/baidudrive
|
||||
$(INSTALL_DIR) $(1)/usr/sbin $(1)/usr/libexec/baidudrive $(1)/opt/baidunas-sdk $(1)/opt/baidunas-glibc $(1)/etc/init.d $(1)/etc/uci-defaults $(1)/etc/config
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/baidudrive.$(PKG_ARCH_BAIDUDRIVE) $(1)/usr/sbin/baidudrive
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/nas_sdk/$(PKG_ARCH_BAIDUDRIVE)/baiduNas $(1)/opt/baidunas-sdk/baiduNas
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/nas_sdk/$(PKG_ARCH_BAIDUDRIVE)/P2PClient.bin $(1)/opt/baidunas-sdk/P2PClient.bin
|
||||
$(INSTALL_DATA) $(PKG_BUILD_DIR)/nas_sdk/$(PKG_ARCH_BAIDUDRIVE)/libkernel.so $(1)/opt/baidunas-sdk/libkernel.so
|
||||
$(CP) $(PKG_BUILD_DIR)/glibc/$(PKG_ARCH_BAIDUDRIVE)/. $(1)/opt/baidunas-glibc/
|
||||
$(LN) /usr/sbin/baidudrive $(1)/opt/baidunas-sdk/P2PClient
|
||||
$(INSTALL_BIN) ./files/sdk-init.sh $(1)/usr/libexec/baidudrive/sdk-init.sh
|
||||
$(INSTALL_BIN) ./files/baidudrive.init $(1)/etc/init.d/baidudrive
|
||||
$(INSTALL_BIN) ./files/baidudrive.uci-default $(1)/etc/uci-defaults/09-baidudrive
|
||||
$(INSTALL_CONF) ./files/baidudrive.config $(1)/etc/config/baidudrive
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
config baidudrive
|
||||
option 'enabled' '0'
|
||||
option 'data_dir' ''
|
||||
option 'port' '8080'
|
||||
option 'host' '0.0.0.0'
|
||||
option 'port' '10780'
|
||||
option 'sdk_dir' '/opt/baidunas-sdk'
|
||||
option 'sdk_host' '127.0.0.1'
|
||||
option 'sdk_port' '8001'
|
||||
option 'macid' ''
|
||||
option 'device_type' ''
|
||||
option 'usb_path' ''
|
||||
option 'download_path' '/'
|
||||
option 'quota_path' ''
|
||||
option 'tmp_path' ''
|
||||
option 'log_level' '7'
|
||||
@@ -6,7 +6,51 @@ USE_PROCD=1
|
||||
get_config() {
|
||||
config_get_bool enabled "$1" enabled 1
|
||||
config_get data_dir "$1" data_dir ""
|
||||
config_get port "$1" port "8080"
|
||||
config_get host "$1" host "0.0.0.0"
|
||||
config_get port "$1" port "10780"
|
||||
config_get sdk_dir "$1" sdk_dir "/opt/baidunas-sdk"
|
||||
config_get sdk_host "$1" sdk_host "127.0.0.1"
|
||||
config_get sdk_port "$1" sdk_port "8001"
|
||||
config_get macid "$1" macid ""
|
||||
config_get device_type "$1" device_type ""
|
||||
config_get usb_path "$1" usb_path ""
|
||||
config_get download_path "$1" download_path "/"
|
||||
config_get quota_path "$1" quota_path ""
|
||||
config_get tmp_path "$1" tmp_path ""
|
||||
config_get log_level "$1" log_level "7"
|
||||
}
|
||||
|
||||
require_start_value() {
|
||||
local name="$1"
|
||||
local value="$2"
|
||||
if [ -z "$value" ]; then
|
||||
logger -t baidudrive "$name is empty; please set option $name in /etc/config/baidudrive"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
require_executable() {
|
||||
local path="$1"
|
||||
if [ ! -x "$path" ]; then
|
||||
logger -t baidudrive "missing executable: $path"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
require_file() {
|
||||
local path="$1"
|
||||
if [ ! -e "$path" ]; then
|
||||
logger -t baidudrive "missing runtime file: $path"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
storage_root_from_data_dir() {
|
||||
local path="$1"
|
||||
df -P "$path" 2>/dev/null | awk 'NR == 2 { print $6 }'
|
||||
}
|
||||
|
||||
start_service() {
|
||||
@@ -15,16 +59,74 @@ start_service() {
|
||||
if [ "$enabled" != 1 ]; then
|
||||
return 1
|
||||
fi
|
||||
if [ -z "$data_dir" ]; then
|
||||
logger -t baidudrive "data_dir is empty; please set option data_dir in /etc/config/baidudrive"
|
||||
return 1
|
||||
fi
|
||||
|
||||
require_start_value data_dir "$data_dir" || return 1
|
||||
require_start_value macid "$macid" || return 1
|
||||
require_start_value device_type "$device_type" || return 1
|
||||
require_executable /usr/sbin/baidudrive || return 1
|
||||
require_executable "$sdk_dir/baiduNas" || return 1
|
||||
require_executable "$sdk_dir/P2PClient" || return 1
|
||||
require_executable "$sdk_dir/P2PClient.bin" || return 1
|
||||
require_file "$sdk_dir/libkernel.so" || return 1
|
||||
require_file /opt/baidunas-glibc || return 1
|
||||
|
||||
mkdir -p "$data_dir" || return 1
|
||||
|
||||
local storage_root
|
||||
storage_root="$(storage_root_from_data_dir "$data_dir")"
|
||||
if [ -n "$storage_root" ]; then
|
||||
[ -n "$usb_path" ] && [ "$usb_path" != "/mnt" ] || usb_path="$storage_root"
|
||||
[ -n "$quota_path" ] && [ "$quota_path" != "/mnt" ] || quota_path="$storage_root"
|
||||
fi
|
||||
[ -n "$usb_path" ] || usb_path="$data_dir"
|
||||
[ -n "$quota_path" ] || quota_path="$usb_path"
|
||||
[ -n "$tmp_path" ] || tmp_path="$data_dir/sdk-tmp"
|
||||
|
||||
mkdir -p "$tmp_path" || return 1
|
||||
rm -rf /mnt/mnt /mnt/.baidudrive-write-test-* 2>/dev/null || true
|
||||
|
||||
logger -t baidudrive "Starting Baidu NAS SDK"
|
||||
procd_open_instance baiduNas
|
||||
procd_set_param command "$sdk_dir/baiduNas" \
|
||||
-ip "$sdk_host" \
|
||||
-port "$sdk_port" \
|
||||
-macid "$macid" \
|
||||
-type "$device_type" \
|
||||
-tmppath "$tmp_path" \
|
||||
-usbpath "$usb_path" \
|
||||
-downloadpath "$download_path" \
|
||||
-order lifo \
|
||||
-forceipv4 \
|
||||
-loglevel "$log_level"
|
||||
procd_set_param dir "$sdk_dir"
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
|
||||
logger -t baidudrive "Starting Baidu NAS SDK init loop"
|
||||
procd_open_instance sdk-init
|
||||
procd_set_param command /usr/libexec/baidudrive/sdk-init.sh
|
||||
procd_set_param env \
|
||||
DATA_DIR="$data_dir" \
|
||||
BAIDU_NAS_HOST="$sdk_host" \
|
||||
BAIDU_NAS_PORT="$sdk_port" \
|
||||
BAIDU_NAS_USB_PATH="$usb_path" \
|
||||
BAIDU_NAS_QUOTA_PATH="$quota_path"
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
|
||||
logger -t baidudrive "Starting BaiduDrive Service"
|
||||
procd_open_instance baidudrive
|
||||
procd_set_param command /usr/sbin/baidudrive --port "$port" --data "$data_dir"
|
||||
procd_set_param env \
|
||||
BAIDU_NAS_MACID="$macid" \
|
||||
BAIDU_NAS_DEVICE_TYPE="$device_type" \
|
||||
BAIDU_NAS_USB_PATH="$usb_path" \
|
||||
BAIDU_NAS_QUOTA_PATH="$quota_path"
|
||||
procd_set_param command /usr/sbin/baidudrive --host "$host" --port "$port" --data "$data_dir"
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
#!/bin/sh
|
||||
[ ! -f "/usr/share/ucitrack/luci-app-baidudrive.json" ] && {
|
||||
cat > /usr/share/ucitrack/luci-app-baidudrive.json << EEOF
|
||||
{
|
||||
"config": "baidudrive",
|
||||
"init": "baidudrive"
|
||||
}
|
||||
EEOF
|
||||
}
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@baidudrive[-1]
|
||||
add ucitrack baidudrive
|
||||
set ucitrack.@baidudrive[-1].init=baidudrive
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
/etc/init.d/baidudrive enable
|
||||
/etc/init.d/baidudrive start
|
||||
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
DATA_DIR=${DATA_DIR:-/mnt/baidudrive/data}
|
||||
BAIDU_NAS_HOST=${BAIDU_NAS_HOST:-127.0.0.1}
|
||||
BAIDU_NAS_PORT=${BAIDU_NAS_PORT:-8001}
|
||||
BAIDU_NAS_USB_PATH=${BAIDU_NAS_USB_PATH:-/mnt}
|
||||
BAIDU_NAS_QUOTA_PATH=${BAIDU_NAS_QUOTA_PATH:-$BAIDU_NAS_USB_PATH}
|
||||
LOG_FILE="$DATA_DIR/sdk-init.log"
|
||||
|
||||
mkdir -p "$DATA_DIR"
|
||||
|
||||
log() {
|
||||
printf '%s %s\n' "$(date -Iseconds 2>/dev/null || date)" "$*" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
while true; do
|
||||
token=$(sed -n 's/.*"access_token"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$DATA_DIR/session.json" 2>/dev/null | head -n 1)
|
||||
if [ -z "$token" ]; then
|
||||
log "session token not ready"
|
||||
sleep 2
|
||||
continue
|
||||
fi
|
||||
|
||||
set -- $(df -m "$BAIDU_NAS_QUOTA_PATH" | awk 'NR==2 {print $2, $4}')
|
||||
total=${1:-0}
|
||||
free=${2:-0}
|
||||
sdk_ready=1
|
||||
|
||||
register_response=$(curl -fsS --max-time 10 -G \
|
||||
--data-urlencode "access_token=$token" \
|
||||
"http://$BAIDU_NAS_HOST:$BAIDU_NAS_PORT/register" 2>/dev/null || true)
|
||||
if printf '%s' "$register_response" | grep -F '"errno":0' >/dev/null; then
|
||||
device_id=$(printf '%s' "$register_response" | sed -n 's/.*"device_id"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1)
|
||||
log "register ok device_id=${device_id:-unknown}"
|
||||
else
|
||||
log "register failed"
|
||||
sdk_ready=0
|
||||
fi
|
||||
|
||||
if curl -fsS --max-time 10 -G \
|
||||
--data-urlencode "type=quota" \
|
||||
--data-urlencode "path=$BAIDU_NAS_USB_PATH" \
|
||||
--data-urlencode "free=$free" \
|
||||
--data-urlencode "total=$total" \
|
||||
"http://$BAIDU_NAS_HOST:$BAIDU_NAS_PORT/event" >/dev/null 2>&1; then
|
||||
log "quota ok path=$BAIDU_NAS_USB_PATH total=${total} free=${free}"
|
||||
else
|
||||
log "quota failed"
|
||||
sdk_ready=0
|
||||
fi
|
||||
|
||||
if curl -fsS --max-time 10 -G \
|
||||
--data-urlencode "type=usbIn" \
|
||||
--data-urlencode "path=$BAIDU_NAS_USB_PATH" \
|
||||
"http://$BAIDU_NAS_HOST:$BAIDU_NAS_PORT/event" >/dev/null 2>&1; then
|
||||
log "usbIn ok path=$BAIDU_NAS_USB_PATH"
|
||||
else
|
||||
log "usbIn failed"
|
||||
sdk_ready=0
|
||||
fi
|
||||
|
||||
if [ "$sdk_ready" = "1" ]; then
|
||||
log "sdk init ready"
|
||||
sleep 60
|
||||
else
|
||||
sleep 2
|
||||
fi
|
||||
done
|
||||
Reference in new issue
Block a user