blob: 2eaed2f9b9c528aed0b931cd8e31e1633a6df752 (
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
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
|
#!/bin/sh
#
CONTAINER=`/sbin/uci -q get ibrdtn.storage.container`
CPATH=`/sbin/uci -q get ibrdtn.storage.path`
check_var() {
if [ -z "$1" ]; then
echo "$2"
exit 1
fi
}
check_path() {
if [ ! -d "$1" ]; then
echo "$2"
return 1
fi
}
check_file() {
if [ ! -f "$1" ]; then
echo "$2"
exit 1
fi
}
container_mount() {
CONTAINER=`/sbin/uci -q get ibrdtn.storage.container`
CPATH=`/sbin/uci -q get ibrdtn.storage.path`
if [ -z "`mount | grep ' on $CPATH '`" ]; then
# try to mount the container
/bin/mount -o loop $CONTAINER $CPATH
return $?
fi
return 0
}
container_reinitialize() {
SIZE=`/sbin/uci get -q ibrdtn.storage.container_size`
CONTAINER=`/sbin/uci -q get ibrdtn.storage.container`
# try to rebuild the container
if [ -n "$SIZE" ]; then
/bin/rm -f $CONTAINER
/usr/share/ibrdtn/mkcontainer.sh $CONTAINER $SIZE
if [ $? -eq 0 ]; then
container_mount
return $?
fi
return 1
fi
return 1
}
check_var $CONTAINER "Storage container not set in uci.\nuse: uci set ibrdtn.storage.container=<container-file>"
check_var $CPATH "Storage container mount path not set in uci.\nuse: uci set ibrdtn.storage.path=<mount-path>"
check_path $CPATH "Storage container mount path does not exist."
if [ $? -gt 0 ]; then
/bin/mkdir -p $CPATH
if [ $? -gt 0 ]; then
echo "can not create container mount path."
exit 1
fi
fi
if [ "$1" == "-u" ]; then
/bin/umount $CPATH
exit 0
fi
if [ -n "`/bin/mount | grep $CPATH`" ]; then
echo "Container already mounted"
exit 0
fi
if [ ! -f "$CONTAINER" ]; then
echo "Storage container file $CONTAINER does not exist."
container_reinitialize
exit $?
fi
# try to mount the container
container_mount
if [ $? -gt 0 ]; then
echo -n "can not mount container file. checking... "
/usr/sbin/e2fsck -p $CONTAINER
if [ $? -gt 0 ]; then
echo " error"
echo "Container file $CONTAINER broken. Try to reinitialize the container."
container_reinitialize
if [ $? -eq 0 ]; then
echo "container ready!"
exit 0
else
exit 1
fi
fi
echo "done"
container_mount
if [ $? -gt 0 ]; then
echo "mount failed!"
exit 1
fi
fi
echo "container ready!"
exit 0
|