Skip to content

Commit

Permalink
Move decryption check into mount_filesystems() and add some more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rake5k committed Sep 24, 2024
1 parent 1a56070 commit 069ede1
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions lib/apps/nixos-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 069ede1

Please sign in to comment.