-
Notifications
You must be signed in to change notification settings - Fork 0
/
10-mount
159 lines (131 loc) · 3.29 KB
/
10-mount
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/sh
set_fstab(){
my_fstype="`block info | grep "/dev/$device" | awk -F 'TYPE="' '{print $2}' | sed 's/\"//'`"
[ -n "$my_fstype" ] && {
logger -t Auto-Mount "New block.File system:${my_fstype}"
if [ "$my_fstype" = 'swap' ]; then
n=$(uci show fstab | grep "fstab.@swap" | grep -c "=swap")
[ $n -gt 0 ] && {
for i in $(seq 0 $n)
do
old_swap="$(uci get fstab.@swap[$i].device)"
[ "$old_swap" == "/dev/$device" ] && {
FLAG="SKIP"
break
}
done
}
[ "$FLAG" != "SKIP" ] && {
uci add fstab swap
uci set fstab.@swap[$n]="swap"
uci set fstab.@swap[$n].enabled='1'
uci set fstab.@swap[$n].device="/dev/$device"
}
else
n=$(uci show fstab | grep "fstab.@mount" | grep -c "=mount")
[ $n -gt 0 ] && {
for i in $(seq 0 $n)
do
old_mount="$(uci get fstab.@mount[$i].uuid)"
[ "$old_mount" == "${get_uuid}" ] && {
FLAG="SKIP"
break
}
done
}
[ "$FLAG" != "SKIP" ] && {
uci add fstab mount
uci set fstab.@mount[$n]="mount"
uci set fstab.@mount[$n].enabled='1'
uci set fstab.@mount[$n].uuid="${get_uuid}"
uci set fstab.@mount[$n].target="/mnt/$device"
uci set fstab.@mount[$n].fstype="$my_fstype"
case "$my_fstype" in
ext*)
uci set fstab.@mount[$n].options="noatime"
;;
'ntfs')
if [ $(lsmod | grep -c ufsd) -ge 1 ]
then
uci set fstab.@mount[$n].fstype="ufsd"
uci set fstab.@mount[$n].options="noatime,nls=utf8,force"
else
uci set fstab.@mount[$n].fstype="ntfs-3g"
uci set fstab.@mount[$n].options="noatime,iocharset=utf8,big_writes"
fi
;;
'exfat')
uci set fstab.@mount[$n].options="noatime"
;;
'vfat')
uci set fstab.@mount[$n].options="iocharset=utf8,umask=0000,dmask=0000,fmask=0000"
;;
*)
uci revert fstab
;;
esac
}
fi
uci commit fstab
}
}
del_fstab(){
del_disk=$(uci show fstab | grep "/mnt/$device" | awk -F '[' '{print $2}' | awk -F ']' '{print $1}' | sort -r )
[ -n "$del_disk" ] && {
for i in $del_disk
do
uci delete fstab.@mount[$i]
done
uci commit fstab
}
}
[ -e /etc/config/fstab ] || {
block detect > /etc/config/fstab
}
[ -e /etc/config/fstab ] && {
del_num=$(uci show fstab | grep ".enabled='0'" | awk -F '[' '{print $2}' | awk -F ']' '{print $1}' | sort -r )
[ -n "$del_num" ] && {
for i in $del_num
do
uci delete fstab.@mount[$i]
done
uci commit fstab
}
}
blkdev=`dirname $DEVPATH`
if [ `basename $blkdev` != "block" ]; then
device=`basename $DEVPATH`
mountpoint=`sed -ne "s|^[^ ]*/$device ||; T; s/ .*//p" /proc/self/mounts`
case "$ACTION" in
add)
get_uuid=`block info | grep "/dev/${device}" | awk -F "UUID=" '{print $2}'| awk -F "\"" '{print $2}'`
[ -n "$get_uuid" ] && {
mounted=`mount -l | awk '{print $1}'`
flag=0
for dev_mounted in $mounted ; do
if [ "/dev/${device}" == $dev_mounted ]; then
flag=1
fi
done
[ $flag != 1 ] && {
logger -t Auto-Mount "Block /dev/${device} added."
logger -t Auto-Mount "UUID=$get_uuid"
have_uuid=$(uci show fstab | grep -c "$get_uuid")
[ "$have_uuid" = "0" ] && {
mkdir -p /mnt/$device
chmod 777 /mnt/$device
set_fstab
block mount >> /dev/null 2>&1
}
}
}
;;
remove)
del_fstab
umount /mnt/$device
if [ $? -eq 0 ]
then
rmdir /mnt/$device
fi
esac
fi