From 5c8e152837058ce9ffd65864972ef4e7e03f7b9a Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 25 May 2025 08:46:15 +0200 Subject: [PATCH] add mount logic --- backupmount | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/backupmount b/backupmount index a175437..8b0b7bf 100755 --- a/backupmount +++ b/backupmount @@ -21,10 +21,33 @@ infolog() device_mount() { - local device="$1" + local media="$1" + local device="$2" + [ -b "$device" ] \ || infolog "block device $device not found" \ || return $? + + infolog "media $media with device $device found" + + local key=$(cat "config.yaml" \ + | yq --raw-output ".media.\"$media\".key") + [ "$key" != "null" ] \ + || errlog "config.yaml key for $media missing" \ + || return $? + infolog "use key $key" + local volume=$(cat "config.yaml" \ + | yq --raw-output ".media.\"$media\".volume") + [ "$volume" != "null" ] \ + || errlog "config.yaml volume for $media missing" \ + || return $? + infolog "volume mount $volume" + + cryptsetup open --key-file "$key" \ + "$device" \ + "$volume" \ + || errlog "could not open $device with $key" + || return $? } mount() @@ -44,10 +67,10 @@ mount() [ "$device" != "null" ] \ || errlog "missing path for $media" \ || return $? - device_mount "$device" && return 0 + device_mount "$media" "$device" && return 0 done - errlog "no device found" + errlog "no device was mounted" } main() -- 2.47.3