aboutsummaryrefslogtreecommitdiffstats
path: root/signal-desktop/bash-aliases
blob: a50c8f6f91383b034ad98d3978c721fae8d51750 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- shell-script -*-

mount-signal () {
	if mountpoint -q -- ~/.var/opt/signal/SignalCrypt.d; then
		printf '%s\n' 'mount-signal: already mounted' >&2
	elif test -e /dev/mapper/SignalCrypt; then
		asroot env SIGNAL_DIR=~/.var/opt/signal sh -ec \
			'mount -- /dev/mapper/SignalCrypt "${SIGNAL_DIR}/SignalCrypt.d"'
	else
		gpg --decrypt ~/.var/opt/signal/SignalCrypt.key | \
		key2root -k SignalCrypt env \
			SIGNAL_IMG=~/.var/opt/signal/SignalCrypt.img \
			SIGNAL_DIR=~/.var/opt/signal \
			SIGNAL_DEV="$(losetup | sed 's/\s\+/ /g' | cut -d ' ' -f 1,6 | \
			              sed -n 's#\(/[^ ]*\) '"$(realpath -- ~/.var/opt/signal/SignalCrypt.img)"'$#\1#p' | sed 1q)" \
			sh -ec '
				if test -z "${SIGNAL_DEV}"; then
					SIGNAL_DEV="$(losetup --show -f -P "${SIGNAL_IMG}")"
				fi
				cryptsetup -d - open "${SIGNAL_DEV}" SignalCrypt
				mount -- /dev/mapper/SignalCrypt "${SIGNAL_DIR}/SignalCrypt.d"
			'
	fi
}

umount-signal () {
	asroot env \
		SIGNAL_DIR=~/.var/opt/signal \
		SIGNAL_DEV="$(losetup | sed 's/\s\+/ /g' | cut -d ' ' -f 1,6 | \
		              sed -n 's#\(/[^ ]*\) '"$(realpath -- ~/.var/opt/signal/SignalCrypt.img)"'$#\1#p' | sed 1q)" \
		sh -c '
			if mountpoint -q -- "${SIGNAL_DIR}/SignalCrypt.d"; then
				umount -- "${SIGNAL_DIR}/SignalCrypt.d"
			fi
			if test -e /dev/mapper/SignalCrypt; then
				cryptsetup close SignalCrypt
			fi
			if test -n "${SIGNAL_DEV}"; then
				losetup -d "${SIGNAL_DEV}"
			fi
		'
}