aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2024-11-28 22:54:29 +0100
committerMattias Andrée <m@maandree.se>2024-11-28 22:54:29 +0100
commitd9513087a1a0702325bef126ebfcaf6755602f76 (patch)
tree5122cf30674a2adce4aa0f9e29e05a0a45319291
parentm (diff)
downloaddotfiles-d9513087a1a0702325bef126ebfcaf6755602f76.tar.gz
dotfiles-d9513087a1a0702325bef126ebfcaf6755602f76.tar.bz2
dotfiles-d9513087a1a0702325bef126ebfcaf6755602f76.tar.xz
Add mount-devices script under cryptsetupHEADmaster
Signed-off-by: Mattias Andrée <m@maandree.se>
-rw-r--r--cryptsetup/Makefile15
-rwxr-xr-xcryptsetup/mount-devices35
2 files changed, 50 insertions, 0 deletions
diff --git a/cryptsetup/Makefile b/cryptsetup/Makefile
new file mode 100644
index 0000000..0666bc6
--- /dev/null
+++ b/cryptsetup/Makefile
@@ -0,0 +1,15 @@
+.POSIX:
+
+install:
+ ../check-installed-shebang mount-devices
+ ../check-in-path test
+ ../check-in-path mountpoint
+ ../check-in-path cryptsetup
+ ../check-in-path mount
+ mkdir -p -- ~/.local/bin
+ test ! -e ~/.local/bin/mount-devices || test -L ~/.local/bin/mount-devices
+ ln -sf -- ~/.dotfiles/cryptsetup/mount-devices ~/.local/bin/mount-devices
+
+uninstall:
+ +! ../check-installed cryptsetup
+ -unlink -- ~/.local/bin/mount-devices
diff --git a/cryptsetup/mount-devices b/cryptsetup/mount-devices
new file mode 100755
index 0000000..a26fd1c
--- /dev/null
+++ b/cryptsetup/mount-devices
@@ -0,0 +1,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