summaryrefslogtreecommitdiff
path: root/scripts/zfs-open-documents.sh
blob: 2188c5971697e8b2ea06152eb1af7443f513f5dc (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
#!/bin/bash

DATASET="iron-wolf/media/documents"
MOUNTPOINT=$(zfs get -H -o value mountpoint "$DATASET")

if [ "$KEYSTATUS" = "available" ]; then
  if ! mountpoint -q "$MOUNTPOINT"; then
    sudo zfs mount "$DATASET" || { zenity --error --text="Failed to mount dataset."; exit 1; }
  fi
else
  # Key is unavailable. Prompt for it.
  PASS=$(zenity --password --title="Unlock ZFS Volume" --window-icon="lock")

  # If user hits cancel or leaves it empty, exit quietly
  if [ -z "$PASS" ]; then
    exit 0
  fi

  # Try to load key and mount
  if echo "$PASS" | sudo zfs load-key "$DATASET"; then
    sudo zfs mount "$DATASET" || { zenity --error --text="Key loaded, but mount failed."; exit 1; }
  else
    zenity --error --text="Incorrect passphrase."
    exit 1
  fi
fi

if command -v kioclient &> /dev/null; then
  kioclient exec "$MOUNTPOINT"
else
  xdg-open "$MOUNTPOINT"
fi;