diff options
author | Mattias Andrée <maandree@kth.se> | 2023-11-18 23:23:40 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-11-18 23:23:40 +0100 |
commit | 0f1df0db903ba576fd17b08197d3066af7a61e5f (patch) | |
tree | a59c04307b1382257afa3c3512ec3abadf7e0e47 /element-desktop | |
parent | Use losetup -d instead of --detach and add clean up (diff) | |
download | dotfiles-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')
-rw-r--r-- | element-desktop/Makefile | 14 | ||||
-rw-r--r-- | element-desktop/bash-aliases | 46 |
2 files changed, 41 insertions, 19 deletions
diff --git a/element-desktop/Makefile b/element-desktop/Makefile index 60a7a78..ce7b6d2 100644 --- a/element-desktop/Makefile +++ b/element-desktop/Makefile @@ -1,20 +1,20 @@ .POSIX: -include ../common.mk install: test -f ~/.var/opt/element/ElementCrypt.img test -f ~/.var/opt/element/ElementCrypt.key mkdir -p -- ~/.var/opt/element/ElementCrypt.d test -e ~/.config/Element || ln -sf -- ../.var/opt/element/ElementCrypt.d/Element ~/.config/Element - $(CHECK_INSTALLED) asroot - $(CHECK_INSTALLED) gnupg - $(CHECK_INSTALLED) cryptsetup + ../check-any-installed asroot asroot-libpassphrase + ../check-installed gnupg + ../check-installed cryptsetup + ../check-installed key2root mkdir -p -- ~/.config/bash/aliases.d - test ! -d ~/.config/bash/aliases.d/element-desktop + test ! -e ~/.config/bash/aliases.d/element-desktop || \ + test -L ~/.config/bash/aliases.d/element-desktop ln -sf -- ~/.dotfiles/element-desktop/bash-aliases ~/.config/bash/aliases.d/element-desktop uninstall: + +! ../check-installed element-desktop -unlink -- ~/.config/bash/aliases.d/element-desktop -rmdir -- ~/.config/bash/aliases.d - -.PHONY: install uninstall 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 ' } |