Sample Header Ad - 728x90

What is the equivalent of `localectl set-keymap` command on Debian?

1 vote
1 answer
810 views
I am porting a shell script written for Arch to Debian. The relevant part:
keymaps=$(localectl list-keymaps)

if test -n "${1}" && localectl list-keymaps | grep -q "${1}"
then
    keymap="${1}"
else
    exec 3>&1
    keymap=$(/sbin/dialog --title "Keyboard layout" --menu "Choose a keyboard layout" 25 50 20 $(for item in ${keymaps[@]}; do echo ${item} "-" ; done) 2>&1 1>&3) || exit 1
    exec 3>&-
fi

localectl set-keymap ${keymap}

if [[ $DISPLAY ]] && [[ -r /etc/X11/xorg.conf.d/00-keyboard.conf ]]; then
    # X11 is already running
    x11keymap=$(awk '/^\s*Option "XkbLayout"/ { print $3 }' /etc/X11/xorg.conf.d/00-keyboard.conf)
    setxkbmap -layout ${x11keymap}
fi
The problem is, localectl list-keymaps and localectl set-keymap ${keymap} do not seem to work on Debian systems. I did some research and figured out that that is because instead of using a pure systemd solution to control the keyboard layout in the console like Fedora and Arch, Debian uses a mix of systemd and sysvinit solutions. However, I was unable to find a way to set a keymap like with localectl set-keymap ${keymap}—running this command doesn't throw an error, but the layout doesn't change. I was able to make localectl list-keymaps list keymaps by manually adding them following this solution https://unix.stackexchange.com/a/763320/610025 , but I'm afraid it will not work with the actual layout changing command. Is there a Debian-working solution?
Asked by carbon-starlight (15 rep)
May 8, 2024, 01:19 AM
Last activity: May 9, 2024, 12:25 PM