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). --- .config/cs.conf | 14 -------------- .config/cs/config | 14 ++++++++++++++ bin/cs | 25 ++++++++++++++----------- 3 files changed, 28 insertions(+), 25 deletions(-) delete mode 100644 .config/cs.conf create mode 100644 .config/cs/config diff --git a/.config/cs.conf b/.config/cs.conf deleted file mode 100644 index 6542ade..0000000 --- a/.config/cs.conf +++ /dev/null @@ -1,14 +0,0 @@ -# associative array consisting of device name and uuid - -devices=( - ["storage"]="3f781aab-24b5-4de0-8632-b9df922d6433" - ["music"]="e0b19c7d-9e90-4117-aea1-7e4b321d9d5a" - ["photos"]="b3c5a842-474b-4c2f-a246-abebe1da3450" - ["backup"]="e003337a-33e9-4691-bc57-e77243e55de5" - ["video"]="5ac700be-e168-495b-b133-42064fa101e4" - ["media"]="e5adbc14-732e-43e8-b6e1-febdfe6d1d3c" - ["mediabackup"]="4467b7af-ab65-4fb7-9798-00d0ee9b4002" - ["videobackup"]="80d50a4c-a04e-432e-8265-9a11a4386612" - ["audiobackup"]="c1d8cea9-aa95-4063-a44d-63e0a702477b" - ["middleman"]="0f3425b2-a736-4565-b512-6ed20fe02153" -) diff --git a/.config/cs/config b/.config/cs/config new file mode 100644 index 0000000..6542ade --- /dev/null +++ b/.config/cs/config @@ -0,0 +1,14 @@ +# associative array consisting of device name and uuid + +devices=( + ["storage"]="3f781aab-24b5-4de0-8632-b9df922d6433" + ["music"]="e0b19c7d-9e90-4117-aea1-7e4b321d9d5a" + ["photos"]="b3c5a842-474b-4c2f-a246-abebe1da3450" + ["backup"]="e003337a-33e9-4691-bc57-e77243e55de5" + ["video"]="5ac700be-e168-495b-b133-42064fa101e4" + ["media"]="e5adbc14-732e-43e8-b6e1-febdfe6d1d3c" + ["mediabackup"]="4467b7af-ab65-4fb7-9798-00d0ee9b4002" + ["videobackup"]="80d50a4c-a04e-432e-8265-9a11a4386612" + ["audiobackup"]="c1d8cea9-aa95-4063-a44d-63e0a702477b" + ["middleman"]="0f3425b2-a736-4565-b512-6ed20fe02153" +) 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