aboutsummaryrefslogtreecommitdiffstats
path: root/element-desktop/umount-element
blob: ddfc602fc810fb7f97c3f0ddc246a2ecf9ec01c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/dash

asroot=asroot
if ! isfg; then
	asroot=gasroot
fi

$asroot env \
	ELEMENT_DIR="${HOME}/.var/opt/element" \
	ELEMENT_DEV="$(losetup | sed 's/\s\+/ /g' | cut -d ' ' -f 1,6 | \
	              sed -n 's#\(/[^ ]*\) '"$(realpath -- "${HOME}/.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
	'