aboutsummaryrefslogtreecommitdiffstats
path: root/bin/cs
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2017-01-09 15:58:37 +0100
committerDavid Runge <dave@sleepmap.de>2017-01-09 15:58:37 +0100
commit7d9f6d979a2a88bc5d811ef1c7359196148de2b0 (patch)
tree84e386a883fe48d831eb6db32dac0f4fc9dcc50c /bin/cs
parent1dd555c3f4ff3a49e45c16c11c2461a3a82e96ff (diff)
downloaddotfiles-7d9f6d979a2a88bc5d811ef1c7359196148de2b0.tar.gz
dotfiles-7d9f6d979a2a88bc5d811ef1c7359196148de2b0.tar.bz2
dotfiles-7d9f6d979a2a88bc5d811ef1c7359196148de2b0.tar.xz
dotfiles-7d9f6d979a2a88bc5d811ef1c7359196148de2b0.zip
bin/cs: Script to open and mount cryptsetup capable devices by name to locations under /mnt.
Diffstat (limited to 'bin/cs')
-rwxr-xr-xbin/cs78
1 files changed, 78 insertions, 0 deletions
diff --git a/bin/cs b/bin/cs
new file mode 100755
index 0000000..4596192
--- /dev/null
+++ b/bin/cs
@@ -0,0 +1,78 @@
+#! /usr/bin/env bash
+
+set -euo pipefail
+
+storage="/dev/disk/by-uuid/3f781aab-24b5-4de0-8632-b9df922d6433"
+music="/dev/disk/by-uuid/e0b19c7d-9e90-4117-aea1-7e4b321d9d5a"
+photos="/dev/disk/by-uuid/b3c5a842-474b-4c2f-a246-abebe1da3450"
+backup="/dev/disk/by-uuid/e003337a-33e9-4691-bc57-e77243e55de5"
+video="/dev/disk/by-uuid/5ac700be-e168-495b-b133-42064fa101e4"
+media="/dev/disk/by-uuid/e5adbc14-732e-43e8-b6e1-febdfe6d1d3c"
+
+
+function open_cryptdevice() {
+ if [ -L "$1" ]; then
+ /usr/bin/sudo /usr/bin/cryptsetup luksOpen $1 $2
+ else
+ echo "Error: Device $2 ($1) is not available."
+ return 1
+ fi
+}
+
+function close_cryptdevice() {
+ /usr/bin/sudo /usr/bin/cryptsetup luksClose $1
+}
+
+function mount_cryptdevice() {
+ if [[ -e "/dev/mapper/$1" ]]; then
+ sudo mount /dev/mapper/$1 /mnt/$1
+ if [ $1 = "media" ]; then
+ sudo mount --bind /mnt/media/music /mnt/music
+ sudo mount --bind /mnt/media/photos /mnt/photos
+ if [ ! -h ~/.cache/shotwell ]; then
+ ln -s /mnt/photos/shotwell/ ~/.cache/shotwell
+ fi
+ fi
+ else
+ echo "Error: Device /dev/mapper/$1 is not available."
+ return 1
+ fi
+}
+
+function unmount_cryptdevice() {
+ if [ $1 = "media" ]; then
+ /usr/bin/sudo /usr/bin/umount /mnt/{music,photos}
+ fi
+ /usr/bin/sudo /usr/bin/umount /mnt/$1
+}
+
+case $1 in
+ "open")
+ case $2 in
+ "storage")
+ open_cryptdevice $storage $2
+ ;;
+ "music")
+ open_cryptdevice $music $2
+ ;;
+ "photos")
+ open_cryptdevice $photos $2
+ ;;
+ "backup")
+ open_cryptdevice $backup $2
+ ;;
+ "video")
+ open_cryptdevice $video $2
+ ;;
+ "media")
+ open_cryptdevice $media $2
+ ;;
+ esac
+ mount_cryptdevice $2
+ ;;
+ "close")
+ unmount_cryptdevice $2
+ close_cryptdevice $2
+ ;;
+esac
+