-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlukshdr.sh
executable file
·61 lines (48 loc) · 855 Bytes
/
lukshdr.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
#!/bin/sh
set -e
make_temp()
{
G_tmpf="$(mktemp -u)"
trap "rm -f $G_tmpf" EXIT
}
print_usage()
{
echo "Usage: $0 backup|restore DRIVE BACKUP"
}
do_backup()
{
make_temp
# Backup to a temporary file
cryptsetup luksHeaderBackup "$1" --header-backup-file "$G_tmpf"
# Encrypt the backup and prevent other users from writin the file
(umask 077 && gpg -o "$2" --no-symkey-cache --symmetric "$G_tmpf")
exit 0
}
do_restore()
{
make_temp
# Decrypt the backup
gpg -o "$G_tmpf" --decrypt "$2"
# Backup to a temporary file
cryptsetup luksHeaderRestore "$1" --header-backup-file "$G_tmpf"
exit 0
}
# Check number of arguments
if [ "$#" -ne 3 ]
then
print_usage
exit 1
fi
case "$1" in
backup )
do_backup "$2" "$3"
;;
restore )
do_restore "$2" "$3"
;;
* )
print_usage
exit 1
;;
esac
exit 0