1
1
#! /bin/sh
2
- #
3
- # D-Team Technology Co.,Ltd. ShenZhen
4
- # 作者:Vic
5
- #
2
+
3
+ #
4
+ # D-Team Technology Co.,Ltd. ShenZhen
5
+ # 作者:Vic
6
6
#
7
7
# 警告:对着屏幕的哥们,我们允许你使用此脚本,但不允许你抹去作者的信息,请保留这段话。
8
8
#
9
+
9
10
. /lib/functions.sh
10
11
. /lib/functions/service.sh
11
12
12
13
global=0
13
14
config_file=" /etc/config/samba"
14
15
15
16
wait_for_init () {
16
- for i in ` seq 30`
17
- do
18
- [ -e /tmp/procd.done ] || {
19
- sleep 1; continue ;
20
- }
21
- return
22
- done
17
+ for i in ` seq 30`
18
+ do
19
+ [ -e /tmp/procd.done ] || {
20
+ sleep 1; continue ;
21
+ }
22
+ return
23
+ done
23
24
}
24
25
25
26
smb_handle () {
26
- config_get path $1 path
27
- if [ " $path " = " $2 " ] ; then
28
- global=1
29
- fi
27
+ config_get path $1 path
28
+ if [ " $path " = " $2 " ] ; then
29
+ global=1
30
+ fi
30
31
}
31
32
32
33
chk_en () {
33
- config_get_bool autoshare $1 autoshare 0
34
+ config_get_bool autoshare $1 autoshare 1
34
35
[ $autoshare -eq 0 ] && exit
35
36
}
36
37
@@ -41,56 +42,57 @@ device=`basename $DEVPATH`
41
42
42
43
case " $ACTION " in
43
44
add)
44
-
45
- case " $device " in
46
- sd* ) ;;
47
- md* ) ;;
48
- hd* );;
49
- mmcblk* );;
50
- * ) return ;;
51
- esac
52
-
53
- path=" /dev/$device "
54
-
55
- wait_for_init
56
-
57
- cat /proc/mounts | while read j
58
- do
59
- str=${j%% * }
60
- if [ " $str " == $path ]; then
61
- strr=${j#* }
62
- target=${strr%% * }
63
- global=0
64
- config_foreach smb_handle sambashare $target
65
- name=${target#*/ mnt/ }
66
-
67
- if [ $global -eq 0 ] ; then
68
- echo -e " \n\nconfig sambashare" >> $config_file
69
- echo -e " \toption auto '1'" >> $config_file
70
- echo -e " \toption name '$name '" >> $config_file
71
- echo -e " \toption path '$target '" >> $config_file
72
- echo -e " \toption read_only 'no'" >> $config_file
73
- echo -e " \toption guest_ok 'yes'" >> $config_file
74
- echo -e " \toption device '$device '" >> $config_file
45
+
46
+ case " $device " in
47
+ sd* );;
48
+ md* );;
49
+ hd* );;
50
+ mmcblk* );;
51
+ * ) return ;;
52
+ esac
53
+
54
+ path=" /dev/$device "
55
+
56
+ wait_for_init
57
+
58
+ cat /proc/mounts | grep -v ' /boot\|/opt|p1' | while read j
59
+ do
60
+ str=${j%% * }
61
+ if [ " $str " == $path ]; then
62
+ strr=${j#* }
63
+ target=${strr%% * }
64
+ global=0
65
+ config_foreach smb_handle sambashare $target
66
+ name=${target#*/ mnt/ }
67
+
68
+ if [ $global -eq 0 ] ; then
69
+ echo -e " \n\nconfig sambashare" >> $config_file
70
+ echo -e " \toption auto '1'" >> $config_file
71
+ echo -e " \toption name '$name '" >> $config_file
72
+ echo -e " \toption path '$target '" >> $config_file
73
+ echo -e " \toption read_only 'no'" >> $config_file
74
+ echo -e " \toption guest_ok 'yes'" >> $config_file
75
+ echo -e " \toption create_mask '0666'" >> $config_file
76
+ echo -e " \toption dir_mask '0777'" >> $config_file
77
+ echo -e " \toption device '$device '" >> $config_file
75
78
/etc/init.d/samba reload
76
79
return
77
- fi
78
- fi
79
- done
80
+ fi
81
+ fi
82
+ done
80
83
;;
84
+
81
85
remove)
82
86
i=0
83
87
while true
84
88
do
85
-
86
89
dev=` uci get samba.@sambashare[$i ].device`
87
90
[ $? -ne 0 ] && break
88
-
91
+
89
92
[ " $dev " = " $device " ] && {
90
93
auto=` uci get samba.@sambashare[$i ].auto`
91
94
[ $auto = " 1" ] && {
92
95
mount_dir=` uci get samba.@sambashare[$i ].name`
93
- rm -rf /mnt/$device /mnt/$mount_dir
94
96
uci delete samba.@sambashare[$i ]
95
97
uci commit
96
98
/etc/init.d/samba reload
0 commit comments