-
Notifications
You must be signed in to change notification settings - Fork 2
/
script_zfs_private.sh
executable file
·80 lines (72 loc) · 1.75 KB
/
script_zfs_private.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/sh
# Mount a local ZFS encrypted dataset
DATASET='zroot/data/private'
DIR='/mnt/private'
GONOTIFY=$(command -v go-notify-me)
function close_if_needed() {
if $(systemctl --user is-active --quiet mpd.service); then
# we run MPD and MPDScribble always together so it makes
# sense to stop them together too
systemctl --user stop mpd.service;
systemctl --user stop mpdscribble.service;
systemctl --user stop mpDris2.service;
fi
# Check also if we need to kill go-notify-me
pidof go-notify-me >/dev/null && pkill go-notify-me;
}
function start_if_available() {
if $(systemctl --user start mpd.service --quiet >/dev/null 2>&1); then
if $(systemctl --user start mpdscribble.service --quiet >/dev/null 2>&1); then
if $(systemctl --user start mpDris2.service --quiet >/dev/null 2>&1); then
# Both MPD, MPDScribble and mpDris2 started successfully. Happy times
return 0
else
# mpDris2 didn't start
return 1
fi
else
# MPDScribble didn't start
return 1
fi
else
# MPD didn't start
return 1
fi
}
case $1 in
umount) close_if_needed
sudo zfs unmount $DATASET
sudo zfs unload-key $DATASET
;;
*) if [ ! -d $DIR ]; then
sudo mkdir -p $DIR
fi
if [[ $DISPLAY != '' ]];
then
sudo zfs load-key $DATASET
sudo zfs mount $DATASET
if [ $? -eq 0 ]; then
start_if_available
if start_if_available; then
$GONOTIFY &>> ~/.xsession-errors &
fi
echo -e "\nPrivate partition mounted and ready!"
else
exit 1
fi
else
sudo zfs load-key $DATASET
sudo zfs mount $DATASET
if [ $? -eq 0 ]; then
start_if_available
if start_if_available; then
$GONOTIFY &>> ~/.xsession-errors &
fi
notify-send "Private partition mounted and ready!"
else
exit 1
fi
fi
;;
esac
exit 0