]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add mount logic
authorBastian Dehn <hhaalo@arcor.de>
Sun, 25 May 2025 06:46:15 +0000 (08:46 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 25 May 2025 06:46:15 +0000 (08:46 +0200)
backupmount

index a175437fa880b3182ac842c948f66f3938ca9096..8b0b7bfc76554ba495702819ad205f84f323ba25 100755 (executable)
@@ -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()