lede-packages-rs

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

mountcontainer.sh (2155B)


      1 #!/bin/sh
      2 #
      3 
      4 CONTAINER=`/sbin/uci -q get ibrdtn.storage.container`
      5 CPATH=`/sbin/uci -q get ibrdtn.storage.path`
      6 
      7 check_var() {
      8 	if [ -z "$1" ]; then
      9 		echo "$2"
     10 		exit 1
     11 	fi
     12 }
     13 
     14 check_path() {
     15 	if [ ! -d "$1" ]; then
     16 		echo "$2"
     17 		return 1
     18 	fi
     19 }
     20 
     21 check_file() {
     22 	if [ ! -f "$1" ]; then
     23 		echo "$2"
     24 		exit 1
     25 	fi
     26 }
     27 
     28 container_mount() {
     29 	CONTAINER=`/sbin/uci -q get ibrdtn.storage.container`
     30 	CPATH=`/sbin/uci -q get ibrdtn.storage.path`
     31 
     32 	if [ -z "`mount | grep ' on $CPATH '`" ]; then
     33 		# try to mount the container
     34 		/bin/mount -o loop $CONTAINER $CPATH
     35 
     36 		return $?
     37 	fi
     38 
     39 	return 0
     40 }
     41 
     42 container_reinitialize() {
     43 	SIZE=`/sbin/uci get -q ibrdtn.storage.container_size`
     44 	CONTAINER=`/sbin/uci -q get ibrdtn.storage.container`
     45 
     46 	# try to rebuild the container
     47 	if [ -n "$SIZE" ]; then
     48 		/bin/rm -f $CONTAINER
     49 		/usr/share/ibrdtn/mkcontainer.sh $CONTAINER $SIZE
     50 
     51 		if [ $? -eq 0 ]; then
     52 			container_mount
     53 			return $?
     54 		fi
     55 
     56 		return 1
     57 	fi
     58 
     59 	return 1
     60 }
     61 
     62 check_var $CONTAINER "Storage container not set in uci.\nuse: uci set ibrdtn.storage.container=<container-file>"
     63 check_var $CPATH "Storage container mount path not set in uci.\nuse: uci set ibrdtn.storage.path=<mount-path>"
     64 
     65 check_path $CPATH "Storage container mount path does not exist."
     66 if [ $? -gt 0 ]; then
     67 	/bin/mkdir -p $CPATH
     68 
     69 	if [ $? -gt 0 ]; then
     70 		echo "can not create container mount path."
     71 		exit 1
     72 	fi
     73 fi
     74 
     75 if [ "$1" == "-u" ]; then
     76 	/bin/umount $CPATH
     77 	exit 0
     78 fi
     79 
     80 if [ -n "`/bin/mount | grep $CPATH`" ]; then
     81 	echo "Container already mounted"
     82 	exit 0
     83 fi
     84 
     85 if [ ! -f "$CONTAINER" ]; then
     86 	echo "Storage container file $CONTAINER does not exist."
     87 	container_reinitialize
     88 	exit $?
     89 fi
     90 
     91 # try to mount the container
     92 container_mount
     93 
     94 if [ $? -gt 0 ]; then
     95 	echo -n "can not mount container file. checking... "
     96 	/usr/sbin/e2fsck -p $CONTAINER
     97 
     98 	if [ $? -gt 0 ]; then
     99 		echo " error"
    100 		echo "Container file $CONTAINER broken. Try to reinitialize the container."
    101 		container_reinitialize
    102 
    103 		if [ $? -eq 0 ]; then
    104 			echo "container ready!"
    105 			exit 0
    106 		else
    107 			exit 1
    108 		fi
    109 	fi
    110 	echo "done"
    111 
    112 	container_mount
    113 
    114 	if [ $? -gt 0 ]; then
    115 		echo "mount failed!"
    116 		exit 1
    117 	fi
    118 fi
    119 
    120 echo "container ready!"
    121 exit 0
    122