#!/bin/sh # Copyright (C) 2007 Krzysztof Kozlowski # License: GNU General Public License version 2 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # version 2 as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # Ostatnia zmiana: 06.12.2007 # # Umount cryptsetup-loop file # # . /home/kozik/bin/kozik_functions usage () { echo "Usage: $(basename $0) [mount_point|crypt_node_name]" exit 127 } if [ $# -ne 1 ]; then usage fi MOUNT_POINT=${1%/} ABSOLUTE_PATHNAME=`absolute_pathname "${MOUNT_POINT}"` if [ "$ABSOLUTE_PATHNAME" == "" ]; then # It is crypt_node_name? CRYPT_NODE_NAME=${MOUNT_POINT} CRYPT_NODE_FILEPATH="/dev/mapper/${CRYPT_NODE_NAME}" if [ -b "${CRYPT_NODE_FILEPATH}" ] || [ -c "${CRYPT_NODE_FILEPATH}" ]; then MOUNT_POINT="" else die "Could not find mount point or crypt node name $1" fi else CRYPT_NODE_FILEPATH=`mount | grep "${MOUNT_POINT}" | cut -f 1 -d ' '` CRYPT_NODE_FILEPATH=`trim_string "${CRYPT_NODE_FILEPATH}"` CRYPT_NODE_NAME=`basename "${CRYPT_NODE_FILEPATH}"` fi LOOP_DEV=`cryptsetup status "${CRYPT_NODE_NAME}" | grep device | sed -e 's/device://'` LOOP_DEV=`trim_string "${LOOP_DEV}"` if [ "${CRYPT_NODE_NAME}" == "" ]; then die "Could not find dm-crypt node name!" fi if [ "${LOOP_DEV}" == "" ]; then die "Could not find loop device name!" fi if [ "${MOUNT_POINT}" != "" ]; then echo "Umounting ${MOUNT_POINT}..." umount "${MOUNT_POINT}" || die "Could not umount ${MOUNT_POINT} on ${CRYPT_NODE_NAME} - ${LOOP_DEV}" fi echo "Removing dm-crypt node ${CRYPT_NODE_NAME}..." cryptsetup remove "${CRYPT_NODE_NAME}" echo "Removing loop device ${LOOP_DEV}..." losetup -d "${LOOP_DEV}" exit $?