aboutsummaryrefslogtreecommitdiffstats
path: root/bash/aliases-Zenith
blob: 73db8852e229368b7ad1c4925fa2a5d38b40de38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# -*- shell-script -*-

mount-crypt () {
	gpg --decrypt /media/Secondary/.crypt/crypt.key | \
	asroot env XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR}" CRYPT_DIR=~/Crypt sh -ec '
		device="$(losetup --show -f -P /media/Secondary/.crypt/crypt.img)"
		printf "%s\n" "${device}" > "${XDG_RUNTIME_DIR}/CryptCrypt"
		cryptsetup -d - open "${device}" CryptCrypt
		mkdir -p "${CRYPT_DIR}"
		mount /dev/mapper/CryptCrypt "${CRYPT_DIR}"
		'
}

umount-crypt () {
	asroot env XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR}" CRYPT_DIR=~/Crypt sh -c '
		umount "${CRYPT_DIR}"
		rmdir "${CRYPT_DIR}"
		cryptsetup close CryptCrypt
		losetup --detach "$(cat -- "${XDG_RUNTIME_DIR}/CryptCrypt")"
		'
}