[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

tk script to reboot etc from xdm login screen

I've had several requests for this, so a post to the list seemed
appropriate.  My scripts are based on those posted to this list by
Philippe Troin <phil@fifi.org> on Monday 7th October 1996
(subject: " Re: Ctrl-Alt-Del doesn't work under X?").  I've modified
them considerably for use at our site, where one of the requirements
for our linux machines is to be able to emulate an X terminal on an
HP-UX server machine.

It (almost) goes without saying that you need tcl and tk packages
installed - only the runtime parts are needed, and I am not aware
of a need for any particular version.

Assuming you have xdm running, you need to do the following:

Modify /etc/X11/xdm/Xsetup_0 - this script is run when xdm is
(re)initialising the login screen.  Mine is now:

# $XConsortium: Xsetup_0,v 1.3 93/09/28 14:30:31 gildea Exp $

if grep -q ^run-xconsole /etc/X11/config
  xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed \
    -exitOnFail -file /dev/xconsole
xsetroot -solid grey50

# Start the rebooter etc...
/usr/local/bin/tkmgr &
echo $! > /var/run/tkmgr-pid

Modify /etc/X11/xdm/Xstartup_0 - this script is run after a user has
successfully logged in at the xdm login prompt.  Mine is now:
#! /bin/sh
# This script is run as root after a user starts a session on :0.

# Call the global Xstartup script, if it exists
if [ -x /etc/X11/xdm/Xstartup ] ; then

# :0 specific startup commands go here

# Kill the mgr
if [ -f /var/run/tkmgr-pid ]
  kill `cat /var/run/tkmgr-pid`
  rm /var/run/tkmgr-pid

exit 0

The Tk script is /usr/local/bin/tkmgr.  Mine is modified to give three
choices.  The first is to connect to one of our server machines acting
as an xterm, the second to reboot the system and the third to halt it.

The script determines the location of the xdm login window and places
itself centrally below it.  It will obviously need customising, to either
remove the xterm reference or make it applicable to a particular site.

/usr/local/bin/tkmgr contains:

# Init stuff
wm title . Chooser
wm protocol . WM_DELETE_WINDOW Quit

# Place this below bottom LH corner of login window
set info [split [exec xwininfo -name xlogin] "\n"]
set LoginGeom [split [lindex [split [lindex $info 21] " "] 3] +]
set LoginH [lindex [split [lindex $LoginGeom 0] x] 1]
set NewX [expr [lindex $LoginGeom 1] + 1]
set NewY [expr [lindex $LoginGeom 2] + $LoginH + 6]
wm geometry . +$NewX+$NewY

# The buttons
frame .buttons
button .buttons.xterm \
        -text "Start xterm on ..." \
        -width 19 \
        -relief raised \
        -command Xterm
button .buttons.reboot \
        -text "Reboot the system" \
        -width 19 \
        -command Reboot
button .buttons.halt \
        -text "Halt the system" \
        -width 19 \
        -command Halt
pack append .buttons \
        .buttons.xterm  {left expand fill} \
        .buttons.halt   {left expand fill} \
        .buttons.reboot {left expand fill}

menu .buttons.xterm.menu
    .buttons.xterm.menu add command -label "sleepy"  -command {Xterm "sleepy"}
    .buttons.xterm.menu add command -label "sneezy"  -command {Xterm "sneezy"}
    .buttons.xterm.menu add command -label "bashful" -command {Xterm "bashful"}
    .buttons.xterm.menu add command -label "dopey"   -command {Xterm "dopey"}
    .buttons.xterm.menu add command -label "grumpy"  -command {Xterm "grumpy"}
    .buttons.xterm.menu add command -label "happy"   -command {Xterm "happy"}

pack .buttons -side top -fill x -expand true

# The Functions
proc Quit {} {
    exit 0

proc Reboot {} {
    exec /sbin/shutdown -rt 15 now < /dev/tty1 > /dev/tty1 2> /dev/tty1 &

proc Halt {} {
    exec /sbin/shutdown -ht 15 now < /dev/tty1 > /dev/tty1 2> /dev/tty1 &

proc Xterm {} {
    catch "destroy .xtlist"
    toplevel .xtlist

    # Place this below chooser window
    set MainGeom [split [ wm geometry . ] +]
    set MainH [lindex [split [lindex $MainGeom 0] x] 1]
    set NewX [lindex $MainGeom 1]
    set NewY [expr [lindex $MainGeom 2] + $MainH]
    wm geometry .xtlist +$NewX+$NewY

    frame .xtlist.list
    button .xtlist.list.sleepy \
            -text "sleepy" \
            -padx 10 \
            -width 7 \
            -command {exec /usr/local/bin/tkxterm sleepy &}
    button .xtlist.list.sneezy \
            -text "sneezy" \
            -padx 11 \
            -width 7 \
            -command {exec /usr/local/bin/tkxterm sneezy &}
    button .xtlist.list.bashful \
            -text "bashful" \
            -padx 11 \
            -width 7 \
            -command {exec /usr/local/bin/tkxterm bashful &}
    button .xtlist.list.dopey \
            -text "dopey" \
            -padx 11 \
            -width 7 \
            -command {exec /usr/local/bin/tkxterm dopey &}
    button .xtlist.list.grumpy \
            -text "grumpy" \
            -padx 11 \
            -width 7 \
            -command {exec /usr/local/bin/tkxterm grumpy &}
    button .xtlist.list.happy \
            -text "happy" \
            -padx 10 \
            -width 7 \
            -command {exec /usr/local/bin/tkxterm happy &}
    pack append .xtlist.list \
            .xtlist.list.sleepy  {left expand fill} \
            .xtlist.list.sneezy  {left expand fill} \
            .xtlist.list.bashful {left expand fill} \
            .xtlist.list.dopey   {left expand fill} \
            .xtlist.list.grumpy  {left expand fill} \
            .xtlist.list.happy   {left expand fill}
    pack .xtlist.list -side top -fill x -expand true

It references a script /usr/local/bin/tkxterm, which does the following:

1. Stops xdm, and waits for the X server to die
2. Starts up as an xterm connected to the required machine (using XDMCP)
3. Restarts xdm when the xterm session finishes.

This script should be quite general.  It contains:
# Script called from tkmgr.  It kills xdm and runs a remote X session
# on a given machine.  When this terminates, xdm is restarted.
if [ $# != 1 ]
  echo "Usage: $0 machine"
  /etc/init.d/xdm stop
  while [ -f /tmp/.X0-lock ]
    sleep 1
  /usr/bin/X11/X -query $1 -once
  /etc/init.d/xdm start

Hope this is all useful!


Dr Kevin Scott
Cordless Communications Group
Philips Research Laboratories            Tel: +44 1293 815281
Cross Oak Lane, Redhill                  Fax: +44 1293 815500
Surrey  RH1 5HA, UK                   E-mail: scottkj@prl.research.philips.com

Reply to: