truecrypt_scripts/truecrypt_init.sh
author ft
Tue, 10 Jun 2014 09:22:20 +0200
changeset 14 4762c3abc17a
parent 13 af44ef281875
child 15 f6fc3ab7f0c9
permissions -rwxr-xr-x
fixed umount issue
ft@1
     1
#!/bin/sh
ft@1
     2
ft@1
     3
BASEDIR="$(dirname $0)"
ft@1
     4
DEVICE="$1"
ft@1
     5
MOUNTPOINT="$2"
ft@1
     6
PASSWORD="$3"
ft@1
     7
KEYFILE="$4"
ft@1
     8
ft@1
     9
if [ -r "$BASEDIR/truecrypt_config.cfg" ]
ft@1
    10
then
ft@1
    11
	. "$BASEDIR/truecrypt_config.cfg"
ft@1
    12
else
ft@1
    13
	echo "truecrypt_config.cfg not found" >&2
ft@1
    14
	exit 1
ft@1
    15
fi
ft@1
    16
ft@8
    17
# make sure to have "/dev/sdb" (not "/dev/sdb1")
ft@13
    18
#DEVICE="${DEVICE:0:8}" the bash way does not word in dash -.-
ft@13
    19
DEVICE="$(echo "$DEVICE" | awk '{print substr($1,0,9)}')"
ft@8
    20
ft@8
    21
# make sure the device is not mounted
ft@14
    22
umount /var/run/usbmount/*
ft@14
    23
sleep 1
ft@8
    24
umount ${DEVICE}*
ft@8
    25
ft@14
    26
ft@7
    27
if [ -z "$KEYFILE" ]
ft@7
    28
then
ft@7
    29
	message="$($tc_cmd -c --non-interactive --quick --filesystem=none --encryption=AES --hash=RIPEMD-160 -p "$PASSWORD" "$DEVICE")"
ft@7
    30
	result="$?"
ft@7
    31
else
ft@7
    32
	message="$($tc_cmd -c --non-interactive --quick --filesystem=none --encryption=AES --hash=RIPEMD-160 -p "$PASSWORD" -k "$KEYFILE" "$DEVICE")"
ft@7
    33
	result="$?"
ft@7
    34
fi
ft@7
    35
	
ft@7
    36
if [ "$result" != "0" ]
ft@7
    37
then
ft@7
    38
	exit 1
ft@7
    39
fi
ft@1
    40
ft@1
    41
ft@1
    42
ft@1
    43
if [ -z "$KEYFILE" ]
ft@1
    44
then
ft@7
    45
	message="$message\n$($tc_cmd --non-interactive --filesystem=none -p "$PASSWORD" "$DEVICE")"
ft@7
    46
	result="$?"
ft@1
    47
else
ft@7
    48
	message="$message\n$($tc_cmd --non-interactive --filesystem=none -p "$PASSWORD" -k "$KEYFILE" "$DEVICE")"
ft@7
    49
	result="$?"
ft@1
    50
fi
ft@1
    51
	
ft@7
    52
if [ "$result" != "0" ]
ft@7
    53
then
ft@7
    54
	exit 1
ft@7
    55
fi
ft@7
    56
ft@7
    57
ft@7
    58
ft@7
    59
ft@7
    60
ft@7
    61
TC_DEVICE=$(truecrypt -l | awk '{print $3}')
ft@7
    62
ft@7
    63
message="$message\n$(mkfs.ntfs --quick "$TC_DEVICE")"
ft@1
    64
result="$?"
ft@1
    65
ft@1
    66
if [ "$result" != "0" ]
ft@1
    67
then
ft@1
    68
	exit 1
ft@1
    69
fi
ft@1
    70
ft@7
    71
mount "$TC_DEVICE" "$MOUNTPOINT" 
ft@7
    72
ft@1
    73
echo "$message"
ft@1
    74
exit 0