From 7d9f6d979a2a88bc5d811ef1c7359196148de2b0 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 9 Jan 2017 15:58:37 +0100 Subject: bin/cs: Script to open and mount cryptsetup capable devices by name to locations under /mnt. --- bin/cs | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 bin/cs (limited to 'bin/cs') 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 + -- cgit v1.2.3-70-g09d2