aboutsummaryrefslogtreecommitdiffstats
path: root/cryptsetup/mount-devices
blob: a26fd1cea9979f61efd9f47a0bf20ad70f631211 (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
#!/bin/sh

# Although the name doesn't indicate it, this is only for encrypted
# partitions, and it exists only because systemd is absolutely
# terrible at mounting encrypted filesystems. Thanks you, Lennart
# and all the idiots that thought your craps smelled good.

cd /devices

for f in *; do
	# Make sure the symlink points to an available device
	if ! test -e "$f"; then
		continue
	fi

	# Make sure that the device should be mounted in /media/
	if ! test -d "/media/$f"; then
		continue;
	fi

	# Make sure the device is not already mounted
	if mountpoint -q "/media/$f"; then
		continue;
	fi

	# If the device has not been decrypted already, attempt to decrypt it
	if ! test -e "/dev/mapper/$f"; then
		if ! cryptsetup open "/devices/$f" "$f"; then
			continue
		fi
	fi

	# And of course, mount the decrypted device
	mount "/dev/mapper/$f" "/media/$f"
done