From 98857949b34132eac12eb200fbd6d55a1a5895d3 Mon Sep 17 00:00:00 2001 From: Mayank Chhabra Date: Sun, 16 Aug 2020 17:00:16 +0530 Subject: [PATCH] Retry searching for block devices 20 times before failing (#151) --- scripts/umbrel-os/external-storage/mount | 25 ++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/scripts/umbrel-os/external-storage/mount b/scripts/umbrel-os/external-storage/mount index d753750..914d971 100755 --- a/scripts/umbrel-os/external-storage/mount +++ b/scripts/umbrel-os/external-storage/mount @@ -109,14 +109,27 @@ main () { check_root check_dependencies sed wipefs parted mount sync umount - block_devices=$(list_block_devices) no_of_block_devices=$(list_block_devices | wc -l) - if [[ $no_of_block_devices -lt 1 ]]; then + retry_for_block_devices=1 + + while [[ $no_of_block_devices -lt 1 ]]; do + echo "No block devices found" - echo "Exiting mount script without doing anything" - exit 1 - fi + echo "Waiting for 5 seconds before checking again..." + + sleep 5 + + no_of_block_devices=$(list_block_devices | wc -l) + retry_for_block_devices=$(( $retry_for_block_devices + 1 )) + + if [[ $retry_for_block_devices -gt 20 ]]; then + echo "No block devices found in 20 tries..." + echo "Exiting mount script without doing anything" + exit 1 + fi + + done if [[ $no_of_block_devices -gt 1 ]]; then echo "Multiple block devices found, only one drive is supported" @@ -125,7 +138,7 @@ main () { fi # At this point we know there is only one block device attached - block_device=$block_devices + block_device=$(list_block_devices) partition_path="/dev/${block_device}1" block_device_model=$(get_block_device_model $block_device) echo "Found device \"${block_device_model}\""