/
encdrive-create.sh
executable file
·41 lines (31 loc) · 1.04 KB
/
encdrive-create.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $DIR/.encdrive-default
echo -e "Creating encrypted container in $enc_file\n"
test -f $enc_file && {
echo "$enc_file exists, aborting."
exit 1
}
echo "Creating disk of size $block_count (number of blocks, each block 512 byte)"
dd if=/dev/urandom of=$enc_file count=$block_count || {
echo "Operation failed, aborting"
exit 1
}
chown $user_group $enc_file
device=$(losetup -f)
echo "##########################################"
echo " Now preparing an encrypted device."
echo " Choose a secure password for your drive!"
echo "##########################################"
losetup -e aes $device $enc_file || {
echo "Could not create encrypted loopback device in $enc_file. Aborting"
exit 1
}
echo "Creating ext3 filesystem in loopback device $device"
/sbin/mkfs -t ext3 -q $device || {
echo "Failed to create filesystem. Aborting."
exit 1
}
echo "Cleaning up, removing loopback device"
losetup -d $device
echo "Success. To mount the new drive, call ./encdrive-mount.sh"