From 069ede1a5ba796065a30355884decebac90538af Mon Sep 17 00:00:00 2001 From: Christian Harke Date: Tue, 24 Sep 2024 15:57:51 +0200 Subject: [PATCH] Move decryption check into mount_filesystems() and add some more logging --- lib/apps/nixos-install.sh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/apps/nixos-install.sh b/lib/apps/nixos-install.sh index a9c9e390..5c1d4629 100644 --- a/lib/apps/nixos-install.sh +++ b/lib/apps/nixos-install.sh @@ -103,6 +103,22 @@ decrypt_volumes() { } mount_filesystems() { + _log "[mount_filesystems] Checking if we need to decrypt any disk..." + ROOT_PARTITION_TYPE=$(blkid -s "TYPE" -o "value" "${ROOT_PARTITION}") + readonly ROOT_PARTITION_TYPE + _log "[mount_filesystems] Root partition type is: ${ROOT_PARTITION_TYPE}" + if [[ "${ROOT_PARTITION_TYPE}" == "crypto_LUKS" ]]; then + CRYPT_VOL_STATUS="$(cryptsetup -q status "${ROOT_CRYPT}" || true)" + readonly CRYPT_VOL_STATUS + _log "[mount_filesystems] Volume encryption status is: ${CRYPT_VOL_STATUS}" + CRYPT_VOL_NUM_ACTIVE=$(echo "${CRYPT_VOL_STATUS}" | grep "^/dev/mapper/${ROOT_CRYPT} is active.$" -c || echo 0) + readonly CRYPT_VOL_NUM_ACTIVE + if [[ ${CRYPT_VOL_NUM_ACTIVE} -lt 1 ]]; then + _log "[mount_filesystems] Volume is not active yet, we need to decrypt it." + decrypt_volumes + fi + fi + _log "[mount_filesystems] Mounting file systems..." grep "${ROOT_PARTITION} ${MOUNT_ROOT} btrfs" "/proc/mounts" \ @@ -151,18 +167,6 @@ if _read_boolean "Do you want to DELETE ALL PARTITIONS?" N; then fi -ROOT_PARTITION_TYPE=$(blkid -s "TYPE" -o "value" "${ROOT_PARTITION}") -readonly ROOT_PARTITION_TYPE -if [[ "${ROOT_PARTITION_TYPE}" == "crypto_LUKS" ]]; then - CRYPT_VOL_STATUS="$(cryptsetup -q status "${ROOT_CRYPT}" || true)" - readonly CRYPT_VOL_STATUS - CRYPT_VOL_NUM_ACTIVE=$(echo "${CRYPT_VOL_STATUS}" | grep "^/dev/mapper/${ROOT_CRYPT} is active.$" -c || echo 0) - readonly CRYPT_VOL_NUM_ACTIVE - if [[ ${CRYPT_VOL_NUM_ACTIVE} -lt 1 ]]; then - decrypt_volumes - fi -fi - # shellcheck disable=SC2310 if _read_boolean "Do you want to INSTALL NixOS now?" N; then mount_filesystems