summaryrefslogtreecommitdiffstats
path: root/linux/bin/uiae
blob: fa492fc78662408028dba6397d38fc036fa8d723 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/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

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 paths
PATH_XMODMAP=${PATH_XMODMAP:-/usr/bin/xmodmap}
PATH_SETXKBMAP=${PATH_SETXKBMAP:-/usr/bin/setxkbmap}
PATH_LOADKEYS=${PATH_LOADKEYS:-/usr/bin/loadkeys}
PATH_SUDO=${PATH_SUDO:-/usr/bin/sudo}
PATH_SETLEDS=${PATH_SETLEDS:-/usr/bin/setleds}
PATH_NUMLOCKX=${PATH_NUMLOCKX:-/usr/bin/numlockx}
PATH_XSET=${PATH_XSET:-/usr/bin/xset}

# 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:-/usr/share/keymaps/i386/qwertz/de-latin1-nodeadkeys.map.gz}"
NUM_LOCK_STATUS=${NUM_LOCK_STATUS:-on}

die() {
	echo "$@" >&2
	exit 1
}

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

set_xkbmap() {
	if [ -e "${PATH_SETXKBMAP}" ]; then
		"${PATH_SETXKBMAP}" "$@" || die "Failed to select xkbmap $@."
	else
		die "setxkbmap not found, cannot set xkbmap."
	fi
}

set_keymap() {
	if [ -e "${PATH_LOADKEYS}" ]; then
		if [ -f "$@" ]; then
			if [ "${EUID}" = 0 ]; then
				"${PATH_LOADKEYS}" "$@" || die "Failed to set keymap $@."
			elif [ -e "${PATH_SUDO}" ]; then
				"${PATH_SUDO}" "${PATH_LOADKEYS}" "$@" || die "Failed to set keymap using sudo."
			else
				die "You need root priviliges to change the keymap."
			fi
		else
			die "keymap file $@ does not exist."
		fi
	else
		die "loadkeys not found, cannot set keymap."
	fi
}

if [ -n "$SSH_CONNECTION" ]; then
	die "Cannot set keybord layout in a ssh session."
fi

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

	if [ -e "${PATH_SETLEDS}" ]; then
		if [ "${NUM_LOCK_STATUS}" = "on" ]; then
			"${PATH_SETLEDS}" -num || die "Failed to set num lock status to on."
		else
			"${PATH_SETLEDS}" +num || die "Failed to set num lock status to off."
		fi
	else
		die "setleds does not exist, cannot set NUM status."
	fi
else
	if [ -e "${PATH_XSET}" ]; then
		for modifier in 51 94; do
			"${PATH_XSET}" r ${modifier} || die "Failed to set repeat for modifier ${modifier}."
		done
		for deadkey in 21 35 49; do
			"${PATH_XSET}" r ${deadkey} || die "Failed to set repeat for deadkey ${deakey}."
		done
	else
		die "xset not found, cannot set modifiers and dead keys."
	fi

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

	if [ -e "${PATH_NUMLOCKX}" ]; then
		if [ "${NUM_LOCK_STATUS}" = "on" ]; then
			"${PATH_NUMLOCKX}" on || die "Failed to set num lock status to on."
		else
			"${PATH_NUMLOCKX}" off || die "Failed to set num lock status to off."
		fi
	else
		die "numlockx not found, cannot turn off Numlock."
	fi
fi