blob: 0eee6d432f4e5a630c115ccf255289d759e4025d (
plain)
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
|
#!/bin/sh
UCI_SPOOLDIR="/var/spool/uvol"
_uvol_init_spooldir() {
[ ! -d "$(dirname "$UCI_SPOOLDIR")" ] && mkdir -p "$(dirname "$UCI_SPOOLDIR")"
mkdir -m 0700 -p "$UCI_SPOOLDIR"
}
uvol_uci_add() {
local volname="$1"
local devname="$2"
local mode="$3"
local autofs uuid uciname
uciname=${volname//-/_}
uuid="$(/sbin/block info | grep "^$2" | xargs -n 1 echo | grep "^UUID=.*")"
[ "$uuid" ] || return 22
_uvol_init_spooldir
uuid="${uuid:5}"
autofs=0
[ "$mode" = "ro" ] && autofs=1
if [ -e "${UCI_SPOOLDIR}/remove-$1" ]; then
rm "${UCI_SPOOLDIR}/remove-$1"
fi
cat >"${UCI_SPOOLDIR}/add-$1" <<EOF
set fstab.$uciname=mount
set fstab.$uciname.uuid=$uuid
set fstab.$uciname.target=/var/run/uvol/$volname
set fstab.$uciname.options=$mode
set fstab.$uciname.autofs=$autofs
set fstab.$uciname.enabled=1
commit fstab
EOF
}
uvol_uci_remove() {
local volname="$1"
local uciname
uciname=${volname//-/_}
if [ -e "${UCI_SPOOLDIR}/add-$1" ]; then
rm "${UCI_SPOOLDIR}/add-$1"
return
fi
_uvol_init_spooldir
cat >"${UCI_SPOOLDIR}/remove-$1" <<EOF
delete fstab.$uciname
commit fstab
EOF
}
uvol_uci_commit() {
local volname="$1"
if [ -e "${UCI_SPOOLDIR}/add-$1" ]; then
uci batch < "${UCI_SPOOLDIR}/add-$1"
rm "${UCI_SPOOLDIR}/add-$1"
elif [ -e "${UCI_SPOOLDIR}/remove-$1" ]; then
uci batch < "${UCI_SPOOLDIR}/remove-$1"
rm "${UCI_SPOOLDIR}/remove-$1"
fi
return $?
}
|