aboutsummaryrefslogtreecommitdiffstats
path: root/element-desktop/bash-aliases
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-11-18 23:23:40 +0100
committerMattias Andrée <maandree@kth.se>2023-11-18 23:23:40 +0100
commit0f1df0db903ba576fd17b08197d3066af7a61e5f (patch)
treea59c04307b1382257afa3c3512ec3abadf7e0e47 /element-desktop/bash-aliases
parentUse losetup -d instead of --detach and add clean up (diff)
downloaddotfiles-0f1df0db903ba576fd17b08197d3066af7a61e5f.tar.gz
dotfiles-0f1df0db903ba576fd17b08197d3066af7a61e5f.tar.bz2
dotfiles-0f1df0db903ba576fd17b08197d3066af7a61e5f.tar.xz
A lot of changes
Signed-off-by: Mattias Andrée <maandree@kth.se>
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
'
}