numlock at boot
Paul Morgan
paul.morgan at jumanjihouse.com
Fri Oct 3 03:59:28 UTC 2003
On Thu, 2003-10-02 at 14:10, Martin Stricker wrote:
> I consider Paul Morgan's proposal as being The Right Way To Do It(TM).
> ;-))) This should be bugzilla'ed as RFE! And if you look in the file
> manager of your choice, you'll find a directory /etc/sysconfig with some
> really useful files in all more recent versions of Red Hat Linux.
Thanks for the comments. I've implemented my suggestion, and it works
"mostly". More specifically, it works for the logon greeter, for xterms
and tty's, and when su'ing from one user to another or from one user to
root. It only doesn't work when su'ing from root to a regular user.
It's a crude first effort that needs improving, but here goes:
in /etc/sysconfig/keyboard add an optional line
NUMLOCK=on|off|bios
at logon, su, etc, the system will read ~/.keyboard and override the
global /etc/sysconfig/keyboard value if different. This allows the user
to specify their own preference.
Here are the changes:
compile numlockx and put it in /usr/bin/
cat > /etc/profile.d/keyboard.sh << EOF
# set numlock according to user pref
function set_numlock {
/usr/bin/tty | /bin/grep -q /dev/tty
if [ $? -eq 0 ]; then
if [ $1 = "on" ]; then
/usr/bin/setleds +num
else
/usr/bin/setleds -num
fi
else
/usr/bin/numlockx $1 > /dev/null 2>&1
fi
}
. /etc/sysconfig/keyboard
test -f ~/.keyboard && . ~/.keyboard
case ${NUMLOCK} in
"on" )
set_numlock on ;;
"bios" )
# implement later
set_numlock off
;;
* )
set_numlock off ;;
esac
EOF
I started to port the bash script to csh/tcsh but need to research how
to efficiently source the variables, so I'll look at that part later.
There needs to be a keyboard.csh version for csh users. It doesn't apply
to bash users.
Now vi /etc/X11/xdm/Xsetup_0 and add a line immediately below this one:
/usr/X11R6/bin/xsetroot -solid "#5477A0"
. /etc/profile.d/keyboard.sh
Xsetup_0 is called to set up the logon greeter, so the numlock setting
will apply here, too.
Next add the following lines to /etc/rc.sysinit right below the loadkeys
section but before #set the hostname:
# set numlock
function set_numlock {
TTY=`grep mingetty /etc/inittab | cut -d: -f1`
for tty in $TTY; do
if [ $1 == "on" ]; then
setleds -D +num < /dev/tty${tty}
else
setleds -D -num < /dev/tty${tty}
fi
done
}
case ${NUMLOCK} in
"on" )
set_numlock on ;;
"bios" )
# implement later
set_numlock off
;;
* )
set_numlock off ;;
esac
This part handles the virtual consoles.
Note that I don't have a clue how to read the bios settings, so somebody
is welcome to fill in the "implement later" portion. For now it's the
same as "off". I thought about adding a "last" option, but it looks more
involved than it's worth at the moment. The tty's and X would have to
trap the key events and save to a dot file.
Hope this helps.
-paul
More information about the test
mailing list