summaryrefslogtreecommitdiff
path: root/linux/bin/uiae
blob: ae9792a2c1dc6a9ae14af9a7a1a2fa93d207fc51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/sh
# Copyright 2008 Bernd Steinhauser <berniyh@exherbo.org>
# Copyright 2008 Benjamin Kellermann
# Copyright 2008 Pascal Hauck
# Copyright 2008 Erik Streb del Toro
# Distributed under the terms of the GNU General Public License v3


# colours in the Bash
normal="\033[0m"
red="\033[31m"
orange="\033[33m"
green="\033[32m"

if [ -f "${NEO_CONFIG}" ]; then
	. "${NEO_CONFIG}" || die "Failed to source ${NEO_CONFIG}"
elif [ -f "${HOME}"/.neorc ]; then
	. "${HOME}"/.neorc || die "Failed to source ${HOME}/.neorc"
elif [ -f /etc/neo.conf ]; then
	. /etc/neo.conf || die "Failed to source /etc/neo.conf"
else
	echo "No configuration file found. Using default values, this might fail!"
fi


# Default values
STD_X_VARIANTE=${STD_X_VARIANTE:-xkbmap}
STD_XKBMAP=${STD_XKBMAP:-de}
STD_XKBVARIANT=${STD_XKBVARIANT:-nodeadkeys}
STD_CONSOLE_KEYMAP="${STD_CONSOLE_KEYMAP:-de-latin1-nodeadkeys}"
NUM_LOCK_STATUS=${NUM_LOCK_STATUS:-on}

help() {
cat <<HELP
Aufruf: $0 [-q]
Aktiviert die Standard-Tastaturbelegung.

  -q, --quiet		gibt – abgesehen von Fehlern – keine Meldungen aus

NEO-Tastaturbelegung
Homepage: http://neo-layout.org/

HELP
exit 0
}

die() {
	echo -e "${red}$@${normal}" >&2
	echo -e "${red}Die Belegung konnte nicht geändert werden.${normal}"
	exit 1
}

set_xmodmap() {
	if [ -f "$@" ]; then
		xmodmap "$@" || die "Failed to set xmodmap $@."
	else
		die "Cannot use $@ for xmodmap."
	fi
}

set_xkbmap() {
	setxkbmap "$@" || die "Failed to select xkbmap $@."
}

set_keymap() {
	if [ "${EUID}" = 0 ]; then
		loadkeys "$@" || die "Fehler beim Laden der Keymap ${orange}$@${red}."
	else
		sudo loadkeys "$@" || die "Fehler bei der Verwendung von ${orange}sudo${red}, um die Belegung zu ändern."
	fi
}

if [ -n "$SSH_CONNECTION" ]; then
	die "In einer ssh-session kann die Belegung nicht geändert werden."
fi

if [ -z ${DISPLAY} ]; then
	set_keymap "${STD_CONSOLE_KEYMAP}"

	if [ "${NUM_LOCK_STATUS}" = "on" ]; then
		setleds -num || echo -e "${orange}Fehler beim setzen des Status von NumLock.${normal}" >&2
	else
		setleds +num || echo "${orange}Fehler beim setzen des Status von NumLock.${normal}" >&2
	fi

else
	for modifier in 51 94; do
		xset r ${modifier} || echo "Failed to set repeat for modifier ${modifier}." >&2
	done
	for deadkey in 21 35 49; do
		xset r ${deadkey} || echo "Failed to set repeat for deadkey ${deakey}." >&2
	done


	case "${STD_X_VARIANTE}" in
		xkbmap)
			set_xkbmap "${STD_XKBMAP}" "${STD_XKBVARIANT}"
			;;
		xmodmap)
			set_xkbmap de
			set_xmodmap "${STD_XMODMAP}"
			;;
		*)
			die "Unknown standard X variant ${STD_X_VARIANTE}."
			;;
	esac

	if [ "${NUM_LOCK_STATUS}" = "on" ]; then
		numlockx on || die "Failed to set num lock status to on."
	else
		numlockx off || die "Failed to set num lock status to off."
	fi
fi