Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. # mounter.sh
  4. # author: postables
  5. # script to handle various disk management tasks:
  6. # * mount/unmount luks encrypted drives
  7. # * mount/unmount sshfs directories
  8. # wrapper script to handle open+mount, and closing of luks encrypted drives
  9.  
  10. function sshfs_exists {
  11. if [[ $(which sshfs) == "" ]]; then
  12. echo "sshfs not installed"
  13. exit 1
  14. fi
  15. }
  16.  
  17. function help {
  18. printf "
  19. help menu
  20. \n
  21. \tmount-sshfs)
  22. \t
  23. \t * mount a remote directory via sshfs
  24. \t * requires sshfs be installed
  25. \n
  26. \tunmount-sshfs)
  27. \t
  28. \t * unmount FUSE filesystems
  29. \t * requires sshfs be installed
  30. \n
  31. \tmount-luks)
  32. \t * decrypt, and mount a luks encrypted drive
  33. \n
  34. \tunmount-luks)
  35. \t * unmount a luks encrypted rive (this decrypts it)
  36. \n
  37. " | less
  38. }
  39.  
  40. case "$1" in
  41.  
  42. mount-sshfs)
  43. sshfs_exists
  44. echo "enter remote username"
  45. read -r USER
  46. echo "enter remote host identifier (ip, dns, etc...)"
  47. read -r HOST
  48. echo "enter remote directory to mount from"
  49. read -r REMOTE_DIR
  50. echo "enter local path to mount to"
  51. read -r LOCAL_DIR
  52. echo "$USER@$HOST:$REMOTE_DIR $LOCAL_DIR"
  53. sshfs $USER\@$HOST\:$REMOTE_DIR $LOCAL_DIR
  54. ;;
  55. unmount-sshfs)
  56. sshfs_exists
  57. echo "enter sshfs mount point"
  58. read -r MOUNT_POINT
  59. fusermount -u "$MOUNT_POINT"
  60. ;;
  61. mount-luks)
  62. echo "enter encrypt partition, ie /dev/sdc1"
  63. read -r PARTITION
  64. echo "enter name for partition"
  65. read -r NAME
  66. echo "[INFO] opening drive"
  67. sudo cryptsetup luksOpen "$PARTITION" "$NAME"
  68. if [[ "$?" -ne 0 ]]; then
  69. echo "[ERROR] failed to open luks encrypted drive"
  70. exit 1
  71. fi
  72. echo "enter path to mount drive to"
  73. read -r MOUNT_POINT
  74. echo "[INFO] mounting drive"
  75. sudo mount "/dev/mapper/$NAME" "$MOUNT_POINT"
  76. if [[ "$?" -ne 0 ]]; then
  77. echo "[ERROR] failed to mount drive"
  78. exit 1
  79. fi
  80. echo "[INFO] successfully mounted drive"
  81. ;;
  82. unmount-luks)
  83. echo "enter encrpted drive to unmount, ie /dev/mapper/ipfs-data"
  84. read -r MOUNT_POINT
  85. echo "[INFO] unmounting drive"
  86. sudo umount "$MOUNT_POINT"
  87. if [[ "$?" -ne 0 ]]; then
  88. echo "[ERROR] failed to unmount drive"
  89. exit 1
  90. fi
  91. echo "[INFO] closing luks drive"
  92. sudo cryptsetup luksClose "$MOUNT_POINT"
  93. if [[ "$?" -ne 0 ]]; then
  94. echo "[ERROR] failed to close luks drive"
  95. exit 1
  96. fi
  97. echo "[INFO] successfully unmounted and closed luks drive"
  98. ;;
  99. *)
  100. help
  101. ;;
  102.  
  103. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement