From 0f1df0db903ba576fd17b08197d3066af7a61e5f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 18 Nov 2023 23:23:40 +0100 Subject: A lot of changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- element-desktop/bash-aliases | 46 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'element-desktop/bash-aliases') 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 ' } -- cgit v1.2.3-70-g09d2