#!/bin/bash

## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

set -o errexit
set -o nounset
set -o errtrace
set -o pipefail

readarray -t new_kb_lines < /dev/shm/fixkb-layout || true
if [ "${#new_kb_lines[@]}" != '3' ]; then
  printf '%s\n' "$0: ERROR: Absent or corrupt keyboard layout information in '/dev/shm/fixkb-layout'!"
  exit 1
fi

## Use '--no-live-changes' because regenerating the GRUB configuration file is done after this.
## Use '--force' to avoid a confirmation prompt on encrypted systems.
set-system-keymap --no-live-changes --force -- "${new_kb_lines[0]}" "${new_kb_lines[1]}" "${new_kb_lines[2]}"

## Not needed here, we regenerate the Dracut configuration after this.
#dracut --regenerate-all --force
