neo/linux/bin/asdf
2009-01-04 23:09:59 +00:00

139 lines
3.7 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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
NEO_X_VARIANTE=${NEO_X_VARIANTE:-xkbmap}
NEO_X_VARIANTE=${1-$NEO_X_VARIANTE}
NEO_XKBMAP=${NEO_XKBMAP:-de}
NEO_XKBVARIANT=${NEO_XKBVARIANT:-neo}
NEO_XMODMAP=${NEO_XMODMAP:-$HOME/neo/neo_de.xmodmap}
NEO_XMODMAP_XPROG=${NEO_XMODMAP_XPROG:-$HOME/neo/neo_de_x-prog.xmodmap}
NEO_XMODMAP_ALTERNATIVE=${NEO_XMODMAP_ALTERNATIVE:-$HOME/neo/neo_de_alternative.xmodmap}
NEO_XMODMAP_EVDEV=${NEO_XMODMAP_EVDEV:-$HOME/neo/neo_de_evdev.xmodmap}
NEO_CONSOLE_KEYMAP=${NEO_CONSOLE_KEYMAP:-$HOME/neo/neo.map}
die() {
echo "$@" >&2
exit 1
}
numlock_manually() {
echo "$1" >&2
echo "Please turn Numlock $2 and press Enter to continue." >&2
read
}
set_xmodmap() {
if [ -e "${PATH_XMODMAP}" ]; then
if [ -f "$@" ]; then
set_xkbmap lv
"${PATH_XMODMAP}" "$@" || ( set_xkbmap de ; 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
"${PATH_SETLEDS}" +num || numlock_manually "Failed to set NUM status." on
else
numlock_manually "setleds does not exist, cannot set NUM status." on
fi
else
if [ -e "${PATH_NUMLOCKX}" ]; then
"${PATH_NUMLOCKX}" off || numlock_manually "Failed to turn off Numlock." off
else
numlock_manually "numlockx not found, cannot turn off Numlock." off
fi
if [ -e "${PATH_XSET}" ]; then
for modifier in 51 94; do
"${PATH_XSET}" -r ${modifier} || echo "Failed to unset repeat for modifier ${modifier}." >&2
done
for deadkey in 21 35 49; do
"${PATH_XSET}" -r ${deadkey} || echo "Failed to unset repeat for deadkey ${deakey}." >&2
done
else
echo "xset not found, cannot set modifiers and dead keys." >&2
fi
case "${NEO_X_VARIANTE}" in
xkbmap)
set_xkbmap "${NEO_XKBMAP}" "${NEO_XKBVARIANT}"
;;
xmodmap)
set_xmodmap "${NEO_XMODMAP}"
;;
xprog)
set_xmodmap "${NEO_XMODMAP_XPROG}"
;;
alternative)
set_xmodmap "${NEO_XMODMAP_ALTERNATIVE}"
;;
evdev)
set_xmodmap "${NEO_XMODMAP_EVDEV}"
;;
*)
die "Unknown Neo X variant ${NEO_X_VARIANTE}."
;;
esac
fi