You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
1.5 KiB

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