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.

66 lines
1.4 KiB

  1. #!/bin/sh
  2. UCI_SPOOLDIR="/var/spool/uvol"
  3. _uvol_init_spooldir() {
  4. [ ! -d "$(dirname "$UCI_SPOOLDIR")" ] && mkdir -p "$(dirname "$UCI_SPOOLDIR")"
  5. mkdir -m 0700 -p "$UCI_SPOOLDIR"
  6. }
  7. uvol_uci_add() {
  8. local volname="$1"
  9. local devname="$2"
  10. local mode="$3"
  11. local autofs uuid uciname
  12. uciname=${volname//-/_}
  13. uuid="$(/sbin/block info | grep "^$2" | xargs -n 1 echo | grep "^UUID=.*")"
  14. [ "$uuid" ] || return 22
  15. _uvol_init_spooldir
  16. uuid="${uuid:5}"
  17. autofs=0
  18. [ "$mode" = "ro" ] && autofs=1
  19. if [ -e "${UCI_SPOOLDIR}/remove-$1" ]; then
  20. rm "${UCI_SPOOLDIR}/remove-$1"
  21. fi
  22. cat >"${UCI_SPOOLDIR}/add-$1" <<EOF
  23. set fstab.$uciname=mount
  24. set fstab.$uciname.uuid=$uuid
  25. set fstab.$uciname.target=/var/run/uvol/$volname
  26. set fstab.$uciname.options=$mode
  27. set fstab.$uciname.autofs=$autofs
  28. set fstab.$uciname.enabled=1
  29. commit fstab
  30. EOF
  31. }
  32. uvol_uci_remove() {
  33. local volname="$1"
  34. local uciname
  35. uciname=${volname//-/_}
  36. if [ -e "${UCI_SPOOLDIR}/add-$1" ]; then
  37. rm "${UCI_SPOOLDIR}/add-$1"
  38. return
  39. fi
  40. _uvol_init_spooldir
  41. cat >"${UCI_SPOOLDIR}/remove-$1" <<EOF
  42. delete fstab.$uciname
  43. commit fstab
  44. EOF
  45. }
  46. uvol_uci_commit() {
  47. local volname="$1"
  48. if [ -e "${UCI_SPOOLDIR}/add-$1" ]; then
  49. uci batch < "${UCI_SPOOLDIR}/add-$1"
  50. rm "${UCI_SPOOLDIR}/add-$1"
  51. elif [ -e "${UCI_SPOOLDIR}/remove-$1" ]; then
  52. uci batch < "${UCI_SPOOLDIR}/remove-$1"
  53. rm "${UCI_SPOOLDIR}/remove-$1"
  54. fi
  55. return $?
  56. }