#!/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: 11.02.2007 # # Mount cryptsetup-loop file # # . /home/kozik/bin/kozik_functions usage () { echo "Usage: $(basename $0) file mount_point" exit 127 } if [ $# -ne 2 ]; then usage fi FILE=$1 MOUNT_POINT=$2 DM_NODE_NAME=`basename "${FILE}"` CRYPT_NODE_NAME="${DM_NODE_NAME}.crypt" test -d "${MOUNT_POINT}" || die "Mount point not found!" test -f "${FILE}" || die "File to mount not found!" mount -v | grep "${MOUNT_POINT}" && die "${MOUNT_POINT} seems to be already mounted." LOOP_DEV=`find_free_loop_dev` if [ "$LOOP_DEV" != "" ]; then echo "Using loop device: ${LOOP_DEV}" modprobe aes-i586 modprobe dm-crypt losetup "${LOOP_DEV}" "${FILE}" || die "Could not losetup ${LOOP_DEV}" cryptsetup -c aes create "${CRYPT_NODE_NAME}" "${LOOP_DEV}" || die "Could not cryptsetup ${DM_NODE_NAME}.crypt" mount "/dev/mapper/${CRYPT_NODE_NAME}" "${MOUNT_POINT}" STATUS=$? if [ $STATUS -ne 0 ]; then cryptsetup remove "${CRYPT_NODE_NAME}" losetup -d "${LOOP_DEV}" fi exit $STATUS else echo "Could not find suitable loop device!" fi