rc.fuse 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #! /bin/sh -
  2. #
  3. # Load the fuse module (if exists) and mount the fuse control file system
  4. #
  5. # Copyright (c) 2019-2020 Matias Fonzo, <selk@dragora.org>.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. PROGRAM="${0##*/}"
  19. # Sanity check
  20. if ! command -v fusermount > /dev/null
  21. then
  22. echo "${0}: Error: fusermount(1) is not available." 1>&2
  23. exit 127;
  24. fi
  25. # Main functions
  26. fuse_start()
  27. {
  28. if modinfo fuse > /dev/null 2>&1
  29. then
  30. echo "${PROGRAM}: Loading fuse (kernel) module ..."
  31. modprobe fuse
  32. fi
  33. if ! mountpoint -q /sys/fs/fuse/connections
  34. then
  35. echo "${PROGRAM}: Mounting fusectl filesystem ..."
  36. mount -v -t fusectl fusectl /sys/fs/fuse/connections
  37. else
  38. echo "${PROGRAM}: FUSE filesystem already mounted at /sys/fs/fuse/connections" 1>&2
  39. fi
  40. }
  41. fuse_stop()
  42. {
  43. if mountpoint -q /sys/fs/fuse/connections
  44. then
  45. echo "${PROGRAM}: Unmounting FUSE filesystem ..."
  46. umount -v /sys/fs/fuse/connections
  47. else
  48. echo "${PROGRAM}: FUSE filesystem not mounted." 1>&2
  49. fi
  50. if grep -q -w ^fuse /proc/modules
  51. then
  52. echo "${PROGRAM}: Unloading fuse (kernel) module ..."
  53. rmmod fuse
  54. fi
  55. }
  56. # Command line arguments
  57. case $1 in
  58. start)
  59. fuse_start
  60. ;;
  61. stop)
  62. fuse_stop
  63. ;;
  64. restart)
  65. fuse_stop
  66. fuse_start
  67. ;;
  68. *)
  69. echo "Usage: $0 (start|stop|restart)" 1>&2
  70. exit 1
  71. ;;
  72. esac