autosamba: compatible with samba4

- samba4 config file path: /etc/config/samba4
- samba4 config name: samba4
- samba4 init path: /etc/init.d/samba4
This commit is contained in:
zonyitoo 2022-10-25 12:23:52 +08:00 committed by Tianling Shen
parent 74852bfd02
commit 9ab9dbfb85
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
2 changed files with 62 additions and 61 deletions

View File

@ -25,12 +25,11 @@ define Package/autosamba/description
endef endef
define Build/Compile define Build/Compile
true
endef endef
define Package/autosamba/install define Package/autosamba/install
$(INSTALL_DIR) $(1)/etc/hotplug.d/block $(INSTALL_DIR) $(1)/etc/hotplug.d/block
$(INSTALL_BIN) ./files/20-smb $(1)/etc/hotplug.d/block/20-smb $(INSTALL_BIN) ./files/20-smb $(1)/etc/hotplug.d/block/
endef endef
$(eval $(call BuildPackage,autosamba)) $(eval $(call BuildPackage,autosamba))

30
package/emortal/autosamba/files/20-smb Executable file → Normal file
View File

@ -1,16 +1,17 @@
#!/bin/sh #!/bin/sh
# #
# D-Team Technology Co.,Ltd. ShenZhen # D-Team Technology Co.,Ltd. ShenZhen
# 作者:Vic # 作者:Vic
# #
#
# 警告:对着屏幕的哥们,我们允许你使用此脚本,但不允许你抹去作者的信息,请保留这段话。 # 警告:对着屏幕的哥们,我们允许你使用此脚本,但不允许你抹去作者的信息,请保留这段话。
# #
. /lib/functions.sh . /lib/functions.sh
. /lib/functions/service.sh . /lib/functions/service.sh
global=0 global=0
config_file="/etc/config/samba" config_file="/etc/config/samba4"
wait_for_init() { wait_for_init() {
for i in `seq 30` for i in `seq 30`
@ -34,8 +35,8 @@ chk_en() {
[ $autoshare -eq 0 ] && exit [ $autoshare -eq 0 ] && exit
} }
config_load samba config_load samba4
config_foreach chk_en samba config_foreach chk_en samba4
device=`basename $DEVPATH` device=`basename $DEVPATH`
@ -43,8 +44,8 @@ case "$ACTION" in
add) add)
case "$device" in case "$device" in
sd*) ;; sd*);;
md*) ;; md*);;
hd*);; hd*);;
mmcblk*);; mmcblk*);;
*) return;; *) return;;
@ -54,7 +55,7 @@ case "$ACTION" in
wait_for_init wait_for_init
cat /proc/mounts | while read j cat /proc/mounts | grep -v '/boot\|/opt' | while read j
do do
str=${j%% *} str=${j%% *}
if [ "$str" == $path ];then if [ "$str" == $path ];then
@ -74,27 +75,28 @@ case "$ACTION" in
echo -e "\toption create_mask '0666'" >> $config_file echo -e "\toption create_mask '0666'" >> $config_file
echo -e "\toption dir_mask '0777'" >> $config_file echo -e "\toption dir_mask '0777'" >> $config_file
echo -e "\toption device '$device'" >> $config_file echo -e "\toption device '$device'" >> $config_file
/etc/init.d/samba reload echo -e "\toption inherit_owner 'yes'" >> $config_file
/etc/init.d/samba4 reload
return return
fi fi
fi fi
done done
;; ;;
remove) remove)
i=0 i=0
while true while true
do do
dev=`uci get samba4.@sambashare[$i].device`
dev=`uci get samba.@sambashare[$i].device`
[ $? -ne 0 ] && break [ $? -ne 0 ] && break
[ "$dev" = "$device" ] && { [ "$dev" = "$device" ] && {
auto=`uci get samba.@sambashare[$i].auto` auto=`uci get samba4.@sambashare[$i].auto`
[ $auto = "1" ] && { [ $auto = "1" ] && {
mount_dir=`uci get samba.@sambashare[$i].name` mount_dir=`uci get samba4.@sambashare[$i].name`
uci delete samba.@sambashare[$i] uci delete samba4.@sambashare[$i]
uci commit uci commit
/etc/init.d/samba reload /etc/init.d/samba4 reload
return return
} }
} }