mediatek usb:add auto ksmbd

This commit is contained in:
padavanonly
2025-04-09 21:31:55 +08:00
parent ecfb1d4d3b
commit 627c38d3cd
4 changed files with 158 additions and 3 deletions

View File

@@ -0,0 +1,35 @@
#
# Copyright (C) 2010-2011 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=autoksmbd
PKG_VERSION:=1
PKG_RELEASE:=12
include $(INCLUDE_DIR)/package.mk
define Package/autoksmbd
TITLE:=ksmbd autoconfig hotplug script.
MAINTAINER:=Lean
DEPENDS:=+luci-app-ksmbd +wsdd2
PKGARCH:=all
endef
define Package/autoksmbd/description
A hotplug script to config Ksmbd share automatically.
endef
define Build/Compile
endef
define Package/autoksmbd/install
$(INSTALL_DIR) $(1)/etc/hotplug.d/block
$(INSTALL_BIN) ./files/20-ksmbd $(1)/etc/hotplug.d/block/
endef
$(eval $(call BuildPackage,autoksmbd))

View File

@@ -0,0 +1,120 @@
#!/bin/sh
#
# D-Team Technology Co.,Ltd. ShenZhen
# 作者:Vic
#
# 警告:对着屏幕的哥们,我们允许你使用此脚本,但不允许你抹去作者的信息,请保留这段话。
#
. /lib/functions.sh
. /lib/functions/service.sh
global=0
config_file="/etc/config/ksmbd"
[ ! -f /etc/config/ksmbd ] && {
echo "
config globals
option 'workgroup' 'WORKGROUP'
option 'description' 'Ksmbd on OpenWrt'
" > $config_file
}
wait_for_init() {
for i in `seq 30`
do
[ -e /tmp/procd.done ] || {
sleep 1; continue;
}
return
done
}
smb_handle() {
config_get path $1 path
if [ "$path" = "$2" ] ;then
global=1
fi
}
chk_en() {
config_get_bool autoshare $1 autoshare 1
[ $autoshare -eq 0 ] && exit
}
config_load ksmbd
config_foreach chk_en ksmbd
device=`basename $DEVPATH`
case "$ACTION" in
add)
case "$device" in
sd*);;
md*);;
hd*);;
*) return;;
esac
path="/dev/$device"
wait_for_init
[ "$(uci -q get ksmbd.@globals[0].autoshare)" == "1" ] && {
/etc/init.d/ksmbd restart
exit 0;
}
cat /proc/mounts | grep -v '/boot\|/opt' | while read j
do
str=${j%% *}
if [ "$str" == $path ];then
strr=${j#* }
target=${strr%% *}
global=0
config_foreach smb_handle share $target
name=${target#*/mnt/}
name=$(echo $name | sed -e "s/^\///")
if [ $global -eq 0 ] ;then
echo -e "\n\nconfig share" >> $config_file
echo -e "\toption auto '1'" >> $config_file
echo -e "\toption name '$name'" >> $config_file
echo -e "\toption path '$target'" >> $config_file
echo -e "\toption read_only 'no'" >> $config_file
echo -e "\toption guest_ok 'yes'" >> $config_file
echo -e "\toption create_mask '0666'" >> $config_file
echo -e "\toption dir_mask '0777'" >> $config_file
echo -e "\toption device '$device'" >> $config_file
echo -e "\toption force_root '1'" >> $config_file
/etc/init.d/ksmbd reload
return
fi
fi
done
uci -q set ksmbd.@globals[0].autoshare='1'
uci commit ksmbd
;;
remove)
i=0
while true
do
dev=`uci get ksmbd.@share[$i].device`
[ $? -ne 0 ] && break
[ "$dev" = "$device" ] && {
auto=`uci get ksmbd.@share[$i].auto`
[ $auto = "1" ] && {
mount_dir=`uci get ksmbd.@share[$i].name`
uci delete ksmbd.@share[$i]
uci commit
/etc/init.d/ksmbd reload
return
}
}
let i+=1
done
;;
esac

View File

@@ -3,8 +3,8 @@ KERNEL_LOADADDR := 0x48080000
MT7981_USB_PKGS := automount blkid blockdev fdisk \
kmod-nls-cp437 kmod-nls-iso8859-1 kmod-usb2 kmod-usb3 \
luci-app-usb-printer luci-i18n-usb-printer-zh-cn \
kmod-usb-net-rndis usbutils kmod-usb-net-qmi-wwan-quectel-bpi \
kmod-usb-net-qmi-wwan
kmod-usb-net-rndis usbutils \
kmod-usb-net-qmi-wwan autoksmbd
define Device/mt7981-spim-nor-rfb
DEVICE_VENDOR := MediaTek

View File

@@ -9,7 +9,7 @@ MT7986_WWAN_PKGS := wwan uqmi modemmanager \
luci-proto-modemmanager luci-proto-qmi \
kmod-usb-net-cdc-ether kmod-usb-net-cdc-mbim kmod-usb-net-cdc-ncm \
kmod-usb-serial-option kmod-usb-serial-qualcomm \
kmod-usb-net-qmi-wwan-quectel-bpi kmod-usb-net-qmi-wwan
autoksmbd kmod-usb-net-qmi-wwan
define Device/mt7986a-ax6000-spim-nor-rfb
DEVICE_VENDOR := MediaTek