|| return $?
}
+exists_block_device()
+{
+ local media="$1"
+ local device="$2"
+
+ [ -b "$device" ] \
+ || errlog "block device $device for $media not found" \
+ || return $?
+}
+
+mount_device()
+{
+ local config="$1"
+ local media="$2"
+
+ device=$(echo "$config" \
+ | jq --raw-output ".media.\"$one_media\".device")
+ [ "$device" != "null" ] \
+ || errlog "missing device for media $one_media in $CONFIG_FILE" \
+ || return $?
+ exists_block_device "$media" "$device" || return $?
+}
+
mount_backup()
{
local config="$1"
local media=
mapfile -t media < <(echo "$config" \
- | jq --raw-output ".media | keys[]" 2> /dev/null)
+ | jq --raw-output ".media | keys_unsorted[]" 2> /dev/null)
[ "${#media[@]}" -gt 0 ] \
|| errlog "missing media in $CONFIG_FILE" \
|| return $?
- local device=
local one_media=
for one_media in "${media[@]}"; do
- device=$(echo "$config" \
- | jq --raw-output ".media.\"$one_media\".device")
- [ "$device" != "null" ] \
- || errlog "missing device for media $one_media in $CONFIG_FILE" \
- || return $?
+ mount_device "$config" "$one_media" && return 0
done
+
+ errlog "no device found"
}
umount_backup()
backup_volume: luks-crypt-volume
media:
day:
- device: /dev/path/to/disk
- key: /path/to/luks-key-file
- partition: /dev/path/to/partition
+ device: /dev/path/to/day
+ key: /path/to/luks-key-file-day
+ partition: /dev/path/to/partday
week:
- device: /dev/path/to/disk
- key: /path/to/luks-key-file
- partition: /dev/path/to/partition
+ device: /dev/path/to/week
+ key: /path/to/luks-key-file-week
+ partition: /dev/path/to/partweek
month:
- device: /dev/path/to/disk
- key: /path/to/luks-key-file
- partition: /dev/path/to/partition
\ No newline at end of file
+ device: /dev/path/to/month
+ key: /path/to/luks-key-file-month
+ partition: /dev/path/to/partmonth
\ No newline at end of file
assert_failure
assert_line --index 0 "⭐ START: backupmount"
assert_line --index 1 "❌ ERROR: missing device for media day in src/config-example.yaml"
+}
+
+# bats test_tags=backupmount:mount
+@test "failure no block device found" {
+ run main "mount"
+
+ assert_failure
+ assert_line --index 0 "⭐ START: backupmount"
+ assert_line --index 1 "❌ ERROR: block device /dev/path/to/day for day not found"
+ assert_line --index 2 "❌ ERROR: block device /dev/path/to/week for week not found"
+ assert_line --index 3 "❌ ERROR: block device /dev/path/to/month for month not found"
+ assert_line --index 4 "❌ ERROR: no device found"
}
\ No newline at end of file