From 50ec67397411f4741bbb7fce7aa4ff1912109f61 Mon Sep 17 00:00:00 2001 From: oddlama Date: Fri, 13 May 2022 22:43:58 +0200 Subject: [PATCH] feat: canonicalize devices before use to /dev/disk/by-id/ if possible. This is beneficial for ZFS pools and for humans to see whether the correct disk was selected. --- configure | 5 ++--- install | 2 +- scripts/main.sh | 2 -- scripts/utils.sh | 8 ++++++++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/configure b/configure index badbb78..1ea64f4 100755 --- a/configure +++ b/configure @@ -2,8 +2,6 @@ set -uo pipefail #todo "test ZFS compression really on" -#todo "disks by id also in resolve step" -#todo "the device you want to partitoin ---> to use?" ################################################ # Initialize script environment @@ -649,7 +647,8 @@ function menu_radiolist() { function menu_select_device() { local title="$1" local desc="$2" - local prev_selected=$(canonicalize_device "$3") + local prev_selected + prev_selected=$(canonicalize_device "$3") while true; do local all_devices=() diff --git a/install b/install index 2998564..637039e 100755 --- a/install +++ b/install @@ -96,7 +96,7 @@ while [[ $# -gt 0 ]]; do done # Check configuration location -[[ -z "${CONFIG%%$GENTOO_INSTALL_REPO_DIR*}" ]] \ +[[ -z "${CONFIG%%"$GENTOO_INSTALL_REPO_DIR"*}" ]] \ || die "Configuration file must be inside the installation directory. This is needed so it is accessible from within the chroot environment." if [[ -z "$ACTION" ]]; then diff --git a/scripts/main.sh b/scripts/main.sh index 1997310..5458ec4 100644 --- a/scripts/main.sh +++ b/scripts/main.sh @@ -6,8 +6,6 @@ source "$GENTOO_INSTALL_REPO_DIR/scripts/protection.sh" || exit 1 # Functions function install_stage3() { - [[ $# == 0 ]] || die "Too many arguments" - prepare_installation_environment apply_disk_configuration download_stage3 diff --git a/scripts/utils.sh b/scripts/utils.sh index f116ffc..39e23c5 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -242,6 +242,14 @@ function create_resolve_entry_device() { # Return matching device from /dev/disk/by-id/ if possible, # otherwise return the parameter unchanged. function canonicalize_device() { + given_dev="$(realpath "$1")" + for dev in /dev/disk/by-id/*; do + if [[ "$(realpath "$dev")" == "$given_dev" ]]; then + echo -n "$dev" + return 0 + fi + done + echo -n "$1" }