sg-data-mount.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/ash
  2. ## handling of Btrfs partition
  3. ##
  4. ## parse blkid output
  5. ## find Btrfs partition with 'sg-data' label
  6. ## mount it to /www
  7. _TARGET_LABEL='sg-data'
  8. _TARGET_MOUNT='/www'
  9. _MOUNT_PARAMS='rw,noatime,nodiratime,sync'
  10. detectBtrfs() {
  11. IFS=$'\n'
  12. local _P _L
  13. for _L in $(blkid); do
  14. IFS=' '
  15. for _P in $_L; do
  16. if [ "${_P//dev/}" != "${_P}" ]; then
  17. _DEV="${_P/:}"
  18. else
  19. eval "_${_P/=*}=\"${_P/*=/}\""
  20. fi
  21. if [ "$_TYPE" != "" ] && [ -z "${_TYPE/btrfs}" ] && [ -z "${_LABEL/$1}" ]; then
  22. #echo "$_DEV $_UUID"
  23. return 0
  24. fi
  25. done
  26. done
  27. IFS=$OFS
  28. return 1
  29. }
  30. if mountpoint -q $_TARGET_MOUNT; then
  31. echo "/www is already a mountpoint"
  32. exit 1
  33. fi
  34. if ! detectBtrfs $_TARGET_LABEL; then
  35. echo "no Btrfs partition with label $_TARGET_LABEL was found"
  36. exit 1
  37. fi
  38. if ! mount -o $_MOUNT_PARAMS $_DEV $_TARGET_MOUNT; then
  39. echo "error mounting $_DEV partition"
  40. exit 1
  41. fi
  42. if ! mountpoint -q $_TARGET_MOUNT; then
  43. echo "$_TARGET_MOUNT is not a mountpoint.."
  44. exit 1
  45. fi
  46. ## reload Lighttpd since it might have had open files in /www
  47. killall -HUP lighttpd
  48. exit 0