blob: 73e2ff01451e523874744173f7c77b37f1aff737 (
plain)
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
|
#!/bin/bash
if [ $UID -ne 0 ]; then
echo "This script must be run as root."
exit 1
fi
encrypted_datasets=("zfsroot/encrypted")
function __mount() {
for i in "${encrypted_datasets[@]}"; do
zfs list -o mounted "$i" | grep --quiet yes
if [ $? -eq 0 ]; then
echo "Dataset $i is already mounted. Skipping."
continue
fi
zfs load-key "$i";
if [ $? -ne 0 ]; then
echo "Error importing the key! Aborting dataset ${i}"
continue
fi
zfs mount "$i";
if [ $? -eq 0 ]; then
echo "Successfully mounted dataset ${i}"
else
echo "Error mounting ${i}."
fi
done
}
function __umount() {
for i in "${encrypted_datasets[@]}"; do
zfs unmount "$i"
if [ $? -ne 0 ]; then
echo "Could not unmount partition ${i}"
exit 1
fi
zfs unload-key "$i"
done
}
function __help() {
echo "Mount and unmount all encrypted zfs partitions"
echo "ALL PARTITIONS must be specified in array encrypted_datasets directly in source"
echo "Usage: "
echo " encrypted [mount|umount]"
echo "If volumes are protected with a password, you will be prompted"
}
if [ $1 = mount ]; then
echo "mounting ${encrypted_datasets[@]}"
__mount
elif [ $1 = umount ]; then
echo "unmounting ${encrypted_datasets[@]}"
__umount
else
echo "Help:"
__help
fi
|