OpenWrt packages
Sign in or create your account | Project List | Help
OpenWrt packages Git Source Tree
Root/
| 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 | # try to mount the container |
| 33 | /bin/mount -o loop $CONTAINER $CPATH |
| 34 | |
| 35 | return $? |
| 36 | } |
| 37 | |
| 38 | container_reinitialize() { |
| 39 | SIZE=`/sbin/uci get -q ibrdtn.storage.container_size` |
| 40 | CONTAINER=`/sbin/uci -q get ibrdtn.storage.container` |
| 41 | |
| 42 | # try to rebuild the container |
| 43 | if [ -n "$SIZE" ]; then |
| 44 | /bin/rm -f $CONTAINER |
| 45 | /usr/share/ibrdtn/mkcontainer.sh $CONTAINER $SIZE |
| 46 | |
| 47 | if [ $? -eq 0 ]; then |
| 48 | container_mount |
| 49 | return $? |
| 50 | fi |
| 51 | |
| 52 | return 1 |
| 53 | fi |
| 54 | |
| 55 | return 1 |
| 56 | } |
| 57 | |
| 58 | check_var $CONTAINER "Storage container not set in uci.\nuse: uci set ibrdtn.storage.container=<container-file>" |
| 59 | check_var $CPATH "Storage container mount path not set in uci.\nuse: uci set ibrdtn.storage.path=<mount-path>" |
| 60 | |
| 61 | check_path $CPATH "Storage container mount path does not exist." |
| 62 | if [ $? -gt 0 ]; then |
| 63 | /bin/mkdir -p $CPATH |
| 64 | |
| 65 | if [ $? -gt 0 ]; then |
| 66 | echo "can not create container mount path." |
| 67 | exit 1 |
| 68 | fi |
| 69 | fi |
| 70 | |
| 71 | if [ "$1" == "-u" ]; then |
| 72 | /bin/umount $CPATH |
| 73 | exit 0 |
| 74 | fi |
| 75 | |
| 76 | if [ -n "`/bin/mount | grep $CPATH`" ]; then |
| 77 | echo "Container already mounted" |
| 78 | exit 0 |
| 79 | fi |
| 80 | |
| 81 | if [ ! -f "$CONTAINER" ]; then |
| 82 | echo "Storage container file $CONTAINER does not exist." |
| 83 | container_reinitialize |
| 84 | exit $? |
| 85 | fi |
| 86 | |
| 87 | # try to mount the container |
| 88 | container_mount |
| 89 | |
| 90 | if [ $? -gt 0 ]; then |
| 91 | echo -n "can not mount container file. checking... " |
| 92 | /usr/sbin/e2fsck -p $CONTAINER |
| 93 | |
| 94 | if [ $? -gt 0 ]; then |
| 95 | echo " error" |
| 96 | echo "Container file $CONTAINER broken. Try to reinitialize the container." |
| 97 | container_reinitialize |
| 98 | |
| 99 | if [ $? -eq 0 ]; then |
| 100 | echo "container ready!" |
| 101 | exit 0 |
| 102 | else |
| 103 | exit 1 |
| 104 | fi |
| 105 | fi |
| 106 | echo "done" |
| 107 | |
| 108 | container_mount |
| 109 | |
| 110 | if [ $? -gt 0 ]; then |
| 111 | echo "mount failed!" |
| 112 | exit 1 |
| 113 | fi |
| 114 | fi |
| 115 | |
| 116 | echo "container ready!" |
| 117 | exit 0 |
| 118 | |
| 119 |
