-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyc.sh
executable file
·67 lines (58 loc) · 1.54 KB
/
myc.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# MyCrypt setup and daily running script for easy luks work
# 20180124
#
MOUNTDIRPREFIX=mnt-
# Help
if [ "$1" == "" ]
then
echo "Usage:"
echo " setup {name} {size} - create a file system with name and size"
echo " mount {name} - mount luks filesystem as name"
echo " umount {name} - unmount luks filesystem with name"
echo ""
echo "Note: Requires sudo access for mounting/unmounting purposes"
echo ""
fi
# Setup
if [ "$1" == "setup" ]
then
echo "Setup starting..."
echo "Creating blank file"
dd if=/dev/zero of=$2 bs=1M count=$3
echo "Creating LUKS file system"
sudo cryptsetup -y -v luksFormat $2
if [ "$?" -ne 0 ]; then
echo "Failed to format filesystem, did you type YES in ALL CAPS?"
exit
fi
echo "Opening new file system"
sudo cryptsetup luksOpen $2 $2
echo "Zeroing CRYPT file sytem"
sudo dd if=/dev/zero bs=1M count=$3 of=/dev/mapper/$2 status=progress
echo "Making ext4 system"
sudo mkfs.ext4 /dev/mapper/$2
echo "Mounting LUKS file system"
mkdir ${MOUNTDIRPREFIX}$2
sudo mount /dev/mapper/$2 ${MOUNTDIRPREFIX}$2
sudo chmod ug+rwx ${MOUNTDIRPREFIX}$2
sudo chown $USER ${MOUNTDIRPREFIX}$2
fi
# Mount file system
if [ "$1" == "mount" ]
then
echo "Mounting LUKS file system"
sudo cryptsetup luksOpen $2 $2
mkdir ${MOUNTDIRPREFIX}$2
sudo mount /dev/mapper/$2 ${MOUNTDIRPREFIX}$2
sudo chmod ug+rwx ${MOUNTDIRPREFIX}$2
sudo chown $USER ${MOUNTDIRPREFIX}$2
fi
# Unmount file system
if [ "$1" == "umount" ]
then
echo "Unmounting LUKS file system"
sudo umount ${MOUNTDIRPREFIX}$2
rmdir ${MOUNTDIRPREFIX}$2
sudo cryptsetup luksClose $2
fi