From 0e2d2425b3ccc1dd75c03c6922627bf709e165ba Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 12 Mar 2018 16:39:12 +0100 Subject: bin/cs: Introducing named scripts for post_mount and pre_umount to deal with device specific tasks. Moving configuration according to new folder structure (all below ~/.config/cs now). --- bin/cs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'bin') diff --git a/bin/cs b/bin/cs index 0eb3693..363ba12 100755 --- a/bin/cs +++ b/bin/cs @@ -7,13 +7,20 @@ valid_name=0 command_name=${1:-} device_name=${2:-} -. ~/.config/cs.conf +if [ -r "$HOME/.config/cs/config" ]; then + . "$HOME/.config/cs/config" +fi #TODO: do sanity checks on mountpoints and (dm) devices #TODO: display list of devices available, if no argument given function open_cryptdevice() { if [ -L "/dev/disk/by-uuid/$1" ]; then - /usr/bin/sudo /usr/bin/cryptsetup luksOpen "/dev/disk/by-uuid/$1" $2 + if [ -L "/dev/mapper/$2" ]; then + echo "Crypt device has already been opened: /dev/mapper/$2" + echo "Continuing..." + else + /usr/bin/sudo /usr/bin/cryptsetup luksOpen "/dev/disk/by-uuid/$1" $2 + fi else echo "Error: Device $2 (UUID=$1) is not available." return 1 @@ -27,15 +34,11 @@ function close_cryptdevice() { function mount_cryptdevice() { if [[ -e "/dev/mapper/$1" ]]; then if [[ ! -d "/mnt/$1" ]]; then - sudo mkdir "/mnt/$1" + sudo mkdir -p "/mnt/$1" fi 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 + if [ -x "$HOME/.config/cs/post_mount/$1" ]; then + "$HOME/.config/cs/post_mount/$1" fi else echo "Error: Device /dev/mapper/$1 is not available." @@ -44,8 +47,8 @@ function mount_cryptdevice() { } function unmount_cryptdevice() { - if [ $1 = "media" ]; then - /usr/bin/sudo /usr/bin/umount /mnt/{music,photos} + if [ -x "$HOME/.config/cs/pre_umount/$1" ]; then + "$HOME/.config/cs/pre_umount/$1" fi /usr/bin/sudo /usr/bin/umount /mnt/$1 } -- cgit v1.2.3-70-g09d2