#!/bin/sh # Copyright (C) 2006,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. # # # Homepage: http://www.kozik.net.pl # # Last change: 06.12.2007 # # fsck loop-file. Loop-file can be encrypted, but currently only AES256 is supported. # If encryption is used script will try to load modules aes-i586 and cryptoloop. # # . /home/kozik/bin/kozik_functions usage () { echo "Usage: $(basename $0) [--cryptoloop-aes|--dm-crypt-aes] file" exit 127 } if [ $# -lt 1 ]; then usage fi # Mangle with arguments: LOSETUP_OPTIONS="" count=1 CRYPTOLOOP_AES=0 DMCRYPT_AES=0 for arg in "$@" do if [ $count -eq $# ]; then FILE=$arg elif [ "$arg" == "--cryptoloop-aes" ]; then CRYPTOLOOP_AES=1 elif [ "$arg" == "--dm-crypt-aes" ]; then DMCRYPT_AES=1 fi let "count+=1" done if [ $CRYPTOLOOP_AES -eq 1 ] && [ $DMCRYPT_AES -eq 1 ]; then usage fi test -f "${FILE}" || die "File to mount not found!" DEVS="/dev/loop" # Maybe you want /dev/cloop? if [ $CRYPTOLOOP_AES -eq 1 ]; then LOSETUP_OPTIONS="-e AES256" # FIXME - allow choosing different AES cipher modprobe aes-i586 modprobe cryptoloop elif [ $DMCRYPT_AES -eq 1 ]; then LOSETUP_OPTIONS="" modprobe aes-i586 modprobe dm-crypt DM_NODE_NAME=`basename "${FILE}"` CRYPT_NODE_NAME="${DM_NODE_NAME}.crypt" cryptsetup status $CRYPT_NODE_NAME | grep "is active" && die "$CRYPT_NODE_NAME is currently used. I will not proceed." fi # Main program LOOP_DEV=`find_free_loop_dev` if [ "$LOOP_DEV" != "" ]; then echo "Using loop device: $LOOP_DEV" if [ $CRYPTOLOOP_AES -eq 1 ]; then losetup $LOSETUP_OPTIONS "$LOOP_DEV" "$FILE" || die "Could not losetup ${LOOP_DEV}" fsck "$LOOP_DEV" elif [ $DMCRYPT_AES -eq 1 ]; then losetup $LOSETUP_OPTIONS "$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" fsck "/dev/mapper/${DM_NODE_NAME}.crypt" sync && sync && sync sleep 1 cryptsetup remove "${CRYPT_NODE_NAME}" fi losetup -d "$LOOP_DEV" exit 0 else echo "Could not find any free loop device!" exit 2 fi