blob: 3110bcf0682024de057280c0966916188b06ade5 (
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
|
#!/bin/sh
#
#
check_mounted() {
DIR=$1
while [ "$DIR" != "/" ]; do
if [ -n "`mount | grep "$DIR"`" ]; then
return 0
fi
DIR=`dirname $DIR`
done
return 1
}
check_writable() {
CHECKFILE="$1/.container-lock"
/bin/touch $CHECKFILE
if [ $? -gt 0 ]; then
return 1;
fi
/bin/echo "0123456789" >> $CHECKFILE
if [ $? -gt 0 ]; then
return 2;
fi
/bin/rm $CHECKFILE
if [ $? -gt 0 ]; then
return 3;
fi
}
check_mountdev() {
# get wait_mount option
WAIT_MOUNT_DEV=`uci -q get ibrdtn.safemode.wait_mount`
if [ $? -ne 0 ]; then
return 0
fi
DATA=`mount | grep ${WAIT_MOUNT_DEV}`
if [ -n "${DATA}" ]; then
return 0
fi
return 1
}
# check the storage device
check_mountdev
RET=$?
if [ ${RET} -ne 0 ]; then
WAIT_SECONDS=60
/usr/bin/logger -t "systemcheck.sh" -p 2 "disk storage not ready, wait max. ${WAIT_SECONDS} seconds until it is mounted"
while [ ${RET} -ne 0 ] && [ ${WAIT_SECONDS} -ne 0 ]; do
sleep 1
let WAIT_SECONDS=WAIT_SECONDS-1
check_mountdev
RET=$?
done
fi
if [ ${RET} -ne 0 ]; then
# failed, storage not mounted
exit 1
fi
# get the path for the container
CONTAINER=`uci -q get ibrdtn.storage.container`
if [ -z "$CONTAINER" ]; then
exit 0
fi
CONTAINER_PATH=`dirname $CONTAINER`
if [ -n "$CONTAINER_PATH" ]; then
# check if the container is on a mounted device
check_mounted $CONTAINER_PATH
if [ $? -gt 0 ]; then
# failed
exit 1
fi
# check if the device is writable
check_writable $CONTAINER_PATH
if [ $? -gt 0 ]; then
# failed
exit 1
fi
fi
|