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()
[ "$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()