lede-packages-rs

git clone git://archive.git.mtrnord.blog/MTRNord/lede-packages-rs.git
Log | Files | Refs | README | LICENSE

systemcheck.sh (1529B)


      1 #!/bin/sh
      2 #
      3 #
      4 
      5 check_mounted() {
      6 	DIR=$1
      7 	while [ "$DIR" != "/" ]; do
      8 		if [ -n "`mount | grep "$DIR"`" ]; then
      9 			return 0
     10 		fi
     11 
     12 		DIR=`dirname $DIR`
     13 	done
     14 	return 1
     15 }
     16 
     17 check_writable() {
     18 	CHECKFILE="$1/.container-lock"
     19 	/bin/touch $CHECKFILE
     20 
     21 	if [ $? -gt 0 ]; then
     22 		return 1;
     23 	fi
     24 
     25 	/bin/echo "0123456789" >> $CHECKFILE
     26 
     27 	if [ $? -gt 0 ]; then
     28 		return 2;
     29 	fi
     30 
     31 	/bin/rm $CHECKFILE
     32 
     33 	if [ $? -gt 0 ]; then
     34 		return 3;
     35 	fi
     36 }
     37 
     38 check_mountdev() {
     39 	# get wait_mount option
     40 	WAIT_MOUNT_DEV=`uci -q get ibrdtn.safemode.wait_mount`
     41 	
     42 	if [ $? -ne 0 ]; then
     43 		return 0
     44 	fi
     45 	
     46 	DATA=`mount | grep ${WAIT_MOUNT_DEV}`
     47 
     48 	if [ -n "${DATA}" ]; then
     49 		return 0
     50 	fi
     51 	
     52 	return 1
     53 }
     54 
     55 # check the storage device
     56 check_mountdev
     57 RET=$?
     58 
     59 if [ ${RET} -ne 0 ]; then
     60 	WAIT_SECONDS=60
     61 	/usr/bin/logger -t "systemcheck.sh" -p 2 "disk storage not ready, wait max. ${WAIT_SECONDS} seconds until it is mounted"
     62 	while [ ${RET} -ne 0 ] && [ ${WAIT_SECONDS} -ne 0 ]; do
     63 		sleep 1
     64 		let WAIT_SECONDS=WAIT_SECONDS-1
     65 		check_mountdev
     66 		RET=$?
     67 	done
     68 fi
     69 
     70 if [ ${RET} -ne 0 ]; then
     71 	# failed, storage not mounted
     72 	exit 1
     73 fi
     74 
     75 # get the path for the container
     76 CONTAINER=`uci -q get ibrdtn.storage.container`
     77 
     78 if [ -z "$CONTAINER" ]; then
     79 	exit 0
     80 fi
     81 
     82 CONTAINER_PATH=`dirname $CONTAINER`
     83 
     84 if [ -n "$CONTAINER_PATH" ]; then
     85 	# check if the container is on a mounted device
     86 	check_mounted $CONTAINER_PATH
     87 
     88 	if [ $? -gt 0 ]; then
     89 		# failed
     90 		exit 1
     91 	fi
     92 
     93 	# check if the device is writable
     94 	check_writable $CONTAINER_PATH
     95 
     96 	if [ $? -gt 0 ]; then
     97 		# failed
     98 		exit 1
     99 	fi
    100 fi
    101