#!/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

true "$0: START"

print_usage() {
  printf '%s\n' "$0: Set system-wide keyboard layout for next boot" >&2
  printf '%s\n' "Usage: $0 [--help|-h] [--no-live-changes] [--interactive] -- [layout [variant [option]]]" >&2
  printf '%s\n' 'Options:' >&2
  printf '%s\n' '--help, -h         Print this help message.' >&2
  printf '%s\n' '--no-live-changes  Do not change the keyboard layout in the active running session or update grub.cfg.' >&2
  printf '%s\n' '--interactive      Show an interactive user interface.' >&2
  printf '\n' >&2
  printf '%s\n' 'Examples:' >&2
  printf '%s\n' '  set-system-keymap de' >&2
  printf '%s\n' '  set-system-keymap us colemak' >&2
  printf '%s\n' '  set-system-keymap us,cz,de "" grp:alt_shift_toggle' >&2
}

if [ "$(id -u)" != "0" ]; then
  printf '%s\n' "$0: ERROR: This must be run as root (sudo)!" >&2
  exit 1
fi

scriptname=$(basename -- "$0")
function_name="$(printf '%s\n' "$scriptname" | str_replace "-" "_")"

source /usr/libexec/helper-scripts/set-keyboard-layout.sh

true "$0: END"
