-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluks-create
executable file
·50 lines (41 loc) · 1.2 KB
/
luks-create
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
#!/bin/bash
set -ueo pipefail
shopt -s inherit_errexit
APP=${0##*/}
if [ $# -lt 1 ]; then
echo "$APP"
echo
echo "Syntax: $APP <file> <size in MB>"
echo
exit 1
fi >&2
CONTAINER=$1
CONTAINER_BACKUP="$CONTAINER.header-backup"
SIZE=$2
checkBinarys() {
local i
for i in "$@"; do
hash "$i" 2>/dev/null || {
echo "Binary missing: $i"
echo
exit 1
} >&2
done
}
checkBinarys dd cryptsetup luksformat
if [[ -f "$CONTAINER" || -f "$CONTAINER_BACKUP" ]]; then
echo "Error: File '$CONTAINER' or '$CONTAINER_BACKUP' already exists."
echo
exit 1
fi >&2
# create empty file
echo "Creating ${SIZE}M file.."
dd if=/dev/zero of="$CONTAINER" bs=1M count="$SIZE" status=progress
echo
# -m Specify the percentage of the FS blocks reserved for the super-user.
# This allows root-owned daemons, such as syslogd(8), to continue to function correctly
# after non-privileged processes are prevented from writing to the file system.
luksformat -t ext4 "$CONTAINER" -m 0
echo "Creating luks header backup.."
exe "cryptsetup luksHeaderBackup '$CONTAINER' --header-backup-file '$CONTAINER_BACKUP'"
echo