diff --git a/scripts/functions.sh b/scripts/functions.sh index 0622bf6..19d1321 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -411,6 +411,11 @@ print_summary_tree() { } apply_disk_actions() { + # Clean old resolved ids + rm -rf "$RESOLVABLE_MAP_DIR" &>/dev/null + unset DISK_ID_TO_RESOLVABLE; declare -A -g DISK_ID_TO_RESOLVABLE + unset DISK_UUID_TO_DEVICE; declare -A -g DISK_UUID_TO_DEVICE + local param local current_params=() for param in "${DISK_ACTIONS[@]}"; do diff --git a/scripts/internal_config.sh b/scripts/internal_config.sh index 96e5837..8cb59a9 100644 --- a/scripts/internal_config.sh +++ b/scripts/internal_config.sh @@ -27,14 +27,14 @@ USED_LUKS=false DISK_ACTIONS=() # An associative array from disk id to a resolvable string declare -A DISK_ID_TO_RESOLVABLE +# An associative from uuid to device +declare -A DISK_UUID_TO_DEVICE # An associative array from disk id to parent gpt disk id (only for partitions) declare -A DISK_ID_PART_TO_GPT_ID # An associative array to check for existing ids (maps to uuids) declare -A DISK_ID_TO_UUID # An associative set to check for correct usage of size=remaining in gpt tables declare -A DISK_GPT_HAD_SIZE_REMAINING -# An associative from uuid to device -declare -A DISK_UUID_TO_DEVICE only_one_of() { local previous="" diff --git a/scripts/utils.sh b/scripts/utils.sh index 5d24de0..330f571 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -158,29 +158,39 @@ create_resolve_entry() { case "$type" in 'partuuid') ;; - 'ptuuid') DISK_UUID_TO_DEVICE[$arg]="$device" ;; 'uuid') ;; - 'mdadm') DISK_UUID_TO_DEVICE[$arg]="$device" ;; 'luks') ;; + 'ptuuid') ;& # fallthrough + 'mdadm') + DISK_UUID_TO_DEVICE[$arg]="$device" + mkdir -p "$RESOLVABLE_MAP_DIR/DISK_UUID_TO_DEVICE" \ + || die "Could not create resolveable map dir '$RESOLVABLE_MAP_DIR'" + echo -n "$device" > "$RESOLVABLE_MAP_DIR/DISK_UUID_TO_DEVICE/$(base64 -w 0 <<< "$id")" + ;; *) die "Cannot add resolvable entry for '$type:$arg' (unknown type)" esac DISK_ID_TO_RESOLVABLE[$id]="$type:$arg" - mkdir -p "$RESOLVABLE_MAP_DIR" \ + mkdir -p "$RESOLVABLE_MAP_DIR/DISK_ID_TO_RESOLVABLE" \ || die "Could not create resolveable map dir '$RESOLVABLE_MAP_DIR'" - echo -n "$type:$arg" > "$RESOLVABLE_MAP_DIR/$(base64 -w 0 <<< "$id")" + echo -n "$type:$arg" > "$RESOLVABLE_MAP_DIR/DISK_ID_TO_RESOLVABLE/$(base64 -w 0 <<< "$id")" } load_resolvable_entries() { [[ -d $RESOLVABLE_MAP_DIR ]] \ || return 0 - local base_id - local id - local saved - for base_id in "$RESOLVABLE_MAP_DIR/"*; do - id="$(base64 -d <<< "$(basename "$base_id")")" - saved="$(cat "$base_id")" - DISK_ID_TO_RESOLVABLE[$id]="$saved" + local base64_key + local key + local value + for base64_key in "$RESOLVABLE_MAP_DIR/DISK_ID_TO_RESOLVABLE/"*; do + key="$(base64 -d <<< "$(basename "$base64_key")")" + value="$(cat "$base64_key")" + DISK_ID_TO_RESOLVABLE[$key]="$value" + done + for base64_key in "$RESOLVABLE_MAP_DIR/DISK_UUID_TO_DEVICE/"*; do + key="$(base64 -d <<< "$(basename "$base64_key")")" + value="$(cat "$base64_key")" + DISK_UUID_TO_DEVICE[$key]="$value" done }