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.

83 lines
1.6 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=0
  12. local target="/var/run/uvol/$volname"
  13. local uuid uciname
  14. [ "$mode" = "ro" ] && autofs=1
  15. uciname="${volname//[-.]/_}"
  16. uciname="${uciname//[!([:alnum:]_)]}"
  17. uuid="$(/sbin/block info | grep "^$2" | xargs -n 1 echo | grep "^UUID=.*")"
  18. [ "$uuid" ] || return 22
  19. uuid="${uuid:5}"
  20. case "$uciname" in
  21. "_meta")
  22. target="/var/run/uvol/.meta"
  23. ;;
  24. "_"*)
  25. return 1
  26. ;;
  27. esac
  28. _uvol_init_spooldir
  29. if [ -e "${UCI_SPOOLDIR}/remove-$1" ]; then
  30. rm "${UCI_SPOOLDIR}/remove-$1"
  31. fi
  32. cat >"${UCI_SPOOLDIR}/add-$1" <<EOF
  33. set fstab.$uciname=mount
  34. set fstab.$uciname.uuid=$uuid
  35. set fstab.$uciname.target=$target
  36. set fstab.$uciname.options=$mode
  37. set fstab.$uciname.autofs=$autofs
  38. set fstab.$uciname.enabled=1
  39. EOF
  40. }
  41. uvol_uci_remove() {
  42. local volname="$1"
  43. local uciname
  44. uciname="${volname//[-.]/_}"
  45. uciname="${uciname//[!([:alnum:]_)]}"
  46. if [ -e "${UCI_SPOOLDIR}/add-$1" ]; then
  47. rm "${UCI_SPOOLDIR}/add-$1"
  48. return
  49. fi
  50. _uvol_init_spooldir
  51. cat >"${UCI_SPOOLDIR}/remove-$1" <<EOF
  52. delete fstab.$uciname
  53. EOF
  54. }
  55. uvol_uci_commit() {
  56. local volname="$1"
  57. local ucibatch
  58. for ucibatch in "${UCI_SPOOLDIR}/"*"-$volname"${volname+*} ; do
  59. [ -e "$ucibatch" ] || break
  60. uci batch < "$ucibatch"
  61. [ $? -eq 0 ] && rm "$ucibatch"
  62. done
  63. uci commit fstab
  64. return $?
  65. }
  66. uvol_uci_init() {
  67. uci -q get fstab.@uvol[0] && return
  68. uci add fstab uvol
  69. uci set fstab.@uvol[-1].initialized=1
  70. }