#!/bin/bash

Info () {
title="Info"
author="Peter Starfinger"
mail="E-Mail: info@die-starfingers.de"
year="2021"
app="$(basename $0)"
msgid="The Starbuntu application
<i>\$app</i>
was written by"
info="$(gettext "$msgid" | (export PATH `envsubst --variables "$msgid"`; envsubst "$msgid"))"

yad --center --fixed --title="$title" --window-icon="info" --image="info" --borders=20 --text="$info"$'\n'$'\n'"$author"$'\n'"$mail"$'\n'$'\n'"$year"$'\n' --text-align=center --selectable-labels --button="OK" &
wunwa "$title" > /dev/null; xdotool key Home key Down
}

user=$(whoami)
sh -c 'xseticon -id $(wunwa "configure-keyboard") /usr/share/icons/gnome/48x48/devices/keyboard.png' &
if [[ "$user" != "root" ]]; then gsu "xterm -e $0"; exit 0; fi
param="$1"
[ "$param" = "info" ] && Info && exit 0

title=$"Configure Keyboard"
text="$(echo $"	<b>In the following dialogues choose with the cursor keys,
	proceed with TAB and confirm with Return.</b>")"

yad --center --fixed --window-icon="/usr/share/icons/gnome/48x48/devices/keyboard.png" --title="$title" --image="info" --borders=20 --text="$text" --button="Info":"$0 info" --button="OK":0

dpkg-reconfigure keyboard-configuration 2>/dev/null

if [ $? -eq 0 ]; then
    loc=$(cat /etc/default/keyboard | grep XKBLAYOUT=)
    loc=${loc#*=}
    setxkbmap $loc
fi

