Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/sbin/openrc-run
- # Decrypt and mount /home
- DEV=/dev/sda6
- DEV_NAME=home
- DEV_MAPPED=/dev/mapper/$DEV_NAME
- MOUNTPOINT=/home
- depend() {
- need localmount
- #need device_mapper
- need dmcrypt
- }
- start () {
- ebegin "Opening encrypted $DEV"
- if [ ! -e $DEV_MAPPED ]; then
- cat /etc/luks | cryptsetup luksOpen $DEV $DEV_NAME || \
- eerror $? "Error opening device $DEV"
- else
- eerror "Error: device $DEV_MAPPED already mapped"
- return 1
- fi
- if ! grep -qw $DEV_MAPPED /proc/mounts && \
- ! grep -qw $MOUNTPOINT /proc/mounts; then
- mount $DEV_MAPPED $MOUNTPOINT || \
- eerror $? "Error mounting mapped device $DEV_MAPPED"
- else
- eerror "Error: mapped device $DEV_MAPPED already mounted or mountpoint $MOUNTPOINT busy"
- return 2
- fi
- eend ${?}
- }
- stop() {
- ebegin "Closing encrypted $DEV"
- if egrep -qw "$DEV_MAPPED * $MOUNTPOINT" /proc/mounts; then
- #sync $MOUNTPOINT || \
- # eerror $? "Error syncing mountpoint $MOUNTPOINT"
- umount $MOUNTPOINT || \
- eerror $? "Warning: unmounting $DEV_MAPPED from $MOUNTPOINT"
- else
- echo "Warning: device $DEV_MAPPED not mounted at $MOUNTPOINT"
- echo "Continue stopping? Yes/No"
- read CONTINUE;
- if [[ x$CONTINUE != xYes ]]; then
- eerror "Exiting"
- return 5
- fi
- fi
- if [ -e $DEV_MAPPED ]; then
- cryptsetup luksClose $DEV_NAME || \
- echo $? "Error closing mapped device $DEV_MAPPED ($DEV_NAME)"
- else
- eerror "Error: mapped device $DEV doesn\'t exist"
- return 4
- fi
- eend ${?}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement