Advertisement
Guest User

OpenRC LUKS Automount

a guest
Feb 19th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #!/sbin/openrc-run
  2. # Decrypt and mount /home
  3.  
  4. DEV=/dev/sda6
  5. DEV_NAME=home
  6. DEV_MAPPED=/dev/mapper/$DEV_NAME
  7. MOUNTPOINT=/home
  8.  
  9. depend() {
  10. need localmount
  11. #need device_mapper
  12. need dmcrypt
  13. }
  14.  
  15. start () {
  16. ebegin "Opening encrypted $DEV"
  17. if [ ! -e $DEV_MAPPED ]; then
  18. cat /etc/luks | cryptsetup luksOpen $DEV $DEV_NAME || \
  19. eerror $? "Error opening device $DEV"
  20. else
  21. eerror "Error: device $DEV_MAPPED already mapped"
  22. return 1
  23. fi
  24. if ! grep -qw $DEV_MAPPED /proc/mounts && \
  25. ! grep -qw $MOUNTPOINT /proc/mounts; then
  26. mount $DEV_MAPPED $MOUNTPOINT || \
  27. eerror $? "Error mounting mapped device $DEV_MAPPED"
  28. else
  29. eerror "Error: mapped device $DEV_MAPPED already mounted or mountpoint $MOUNTPOINT busy"
  30. return 2
  31. fi
  32. eend ${?}
  33. }
  34.  
  35. stop() {
  36. ebegin "Closing encrypted $DEV"
  37. if egrep -qw "$DEV_MAPPED * $MOUNTPOINT" /proc/mounts; then
  38. #sync $MOUNTPOINT || \
  39. # eerror $? "Error syncing mountpoint $MOUNTPOINT"
  40. umount $MOUNTPOINT || \
  41. eerror $? "Warning: unmounting $DEV_MAPPED from $MOUNTPOINT"
  42. else
  43. echo "Warning: device $DEV_MAPPED not mounted at $MOUNTPOINT"
  44. echo "Continue stopping? Yes/No"
  45. read CONTINUE;
  46. if [[ x$CONTINUE != xYes ]]; then
  47. eerror "Exiting"
  48. return 5
  49. fi
  50. fi
  51. if [ -e $DEV_MAPPED ]; then
  52. cryptsetup luksClose $DEV_NAME || \
  53. echo $? "Error closing mapped device $DEV_MAPPED ($DEV_NAME)"
  54. else
  55. eerror "Error: mapped device $DEV doesn\'t exist"
  56. return 4
  57. fi
  58. eend ${?}
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement