123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #!/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
|