aboutsummaryrefslogtreecommitdiffstats
path: root/element-desktop/bash-aliases
diff options
context:
space:
mode:
Diffstat (limited to 'element-desktop/bash-aliases')
-rw-r--r--element-desktop/bash-aliases46
1 files changed, 34 insertions, 12 deletions
diff --git a/element-desktop/bash-aliases b/element-desktop/bash-aliases
index fa8afea..1a5362b 100644
--- a/element-desktop/bash-aliases
+++ b/element-desktop/bash-aliases
@@ -1,20 +1,42 @@
# -*- shell-script -*-
mount-element () {
- gpg --decrypt ~/.var/opt/element/ElementCrypt.key | \
- asroot env XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR}" ELEMENT_DIR=~/.var/opt/element sh -ec '
- device="$(losetup --show -f -P "${ELEMENT_DIR}/ElementCrypt.img")"
- printf "%s\n" "${device}" > "${XDG_RUNTIME_DIR}/ElementCrypt"
- cryptsetup -d - open "${device}" ElementCrypt
- mount /dev/mapper/ElementCrypt "${ELEMENT_DIR}/ElementCrypt.d"
- '
+ if mountpoint -q -- ~/.var/opt/element/ElementCrypt.d; then
+ printf '%s\n' 'mount-element: already mounted' >&2
+ elif test -e /dev/mapper/ElementCrypt; then
+ asroot env ELEMENT_DIR=~/.var/opt/element sh -ec \
+ 'mount -- /dev/mapper/ElementCrypt "${ELEMENT_DIR}/ElementCrypt.d"'
+ else
+ gpg --decrypt ~/.var/opt/element/ElementCrypt.key | \
+ key2root -k ElementCrypt env \
+ ELEMENT_IMG=~/.var/opt/element/ElementCrypt.img \
+ ELEMENT_DIR=~/.var/opt/element \
+ ELEMENT_DEV="$(losetup | sed 's/\s\+/ /g' | cut -d ' ' -f 1,6 | \
+ sed -n 's#\(/[^ ]*\) '"$(realpath -- ~/.var/opt/element/ElementCrypt.img)"'$#\1#p' | sed 1q)" \
+ sh -ec '
+ if test -z "${ELEMENT_DEV}"; then
+ ELEMENT_DEV="$(losetup --show -f -P "${ELEMENT_IMG}")"
+ fi
+ cryptsetup -d - open "${ELEMENT_DEV}" ElementCrypt
+ mount -- /dev/mapper/ElementCrypt "${ELEMENT_DIR}/ElementCrypt.d"
+ '
+ fi
}
umount-element () {
- asroot env XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR}" ELEMENT_DIR=~/.var/opt/element sh -c '
- umount "${ELEMENT_DIR}/ElementCrypt.d"
- cryptsetup close ElementCrypt
- losetup -d "$(cat -- "${XDG_RUNTIME_DIR}/ElementCrypt")"
- rm -f -- "${XDG_RUNTIME_DIR}/ElementCrypt"
+ asroot env \
+ ELEMENT_DIR=~/.var/opt/element \
+ ELEMENT_DEV="$(losetup | sed 's/\s\+/ /g' | cut -d ' ' -f 1,6 | \
+ sed -n 's#\(/[^ ]*\) '"$(realpath -- ~/.var/opt/element/ElementCrypt.img)"'$#\1#p' | sed 1q)" \
+ sh -c '
+ if mountpoint -q -- "${ELEMENT_DIR}/ElementCrypt.d"; then
+ umount -- "${ELEMENT_DIR}/ElementCrypt.d"
+ fi
+ if test -e /dev/mapper/ElementCrypt; then
+ cryptsetup close ElementCrypt
+ fi
+ if test -n "${ELEMENT_DEV}"; then
+ losetup -d "${ELEMENT_DEV}"
+ fi
'
}