#!/bin/bash
# Enable unofficial strict mode
set -e # Exit immediately if any command exits with non-zero status;
       # use `cmd || cmd2` if `cmd` must fail, `cmd || true` if it may fail
set -u # Reading a variable not previously defined raises an error
set -o pipefail # if a cmd in the pipeline fails, its return status is the whole pipeline return status
IFS=$'\n\t' # internal field separator
# remember to use `trap (cleanup_function) EXIT` for cleanup. To remove trap, use `-` as cleanup_function
# use `local` for local variables
# use `readonly` for constants, `local -r` for scoped constants

if [[ $# -eq 0 ]];
then
    echo "usage: $0 <lang>" >&2
    echo "    supported languages: fr, it, us, ansi"
    exit 1
fi

readonly lang="$1"
layout=""
case "${lang}" in
    it|IT|It)
        layout="it"
        ;;
    fr|FR|Fr)
        layout="fr"
        ;;
    us|US|Us|ansi|ANSI|Ansi)
        layout="us"
        ;;
    *)
        echo "unsupported language '${lang}'"
        exit 1
        ;;
esac
sudo raspi-config nonint do_configure_keyboard "${layout}"
