towheedm |
06-10-2012 02:07 PM |
Well, I finally got it working. I'll post the script here for those who may be interested and mark the thred as solved.
Here's the script I called mygetty.sh. In Debian, it's in /sbin but you can put it in the same directory as your getty program.
Code:
#!/bin/sh
# This script displays a custom pre-login banner message in a VT.
# Is uses the /etc/issue file to set the banner message. Each line
# can specify the attributes for the text on that line.
# The last line in the file can reset the attributes to their default,
# or set the attributes for the login prompt.
# $1 is the baud rate as set in /etc/inittab.
# $2 is the device designator for the VT as set in /etc/inittab.
# Version 1.0
# Copyright (C) 2012 Towheed Mohammed
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details at <http://www.gnu.org/licenses/>.
# The following are the command codes:
# [arch_name] Insert the architecture of the machine.
# [baud_rate] Insert the baud rate of the current line.
# [current_date] Insert the current date.
# [current_time] Insert the current time.
# [dns_name] Insert the DNS domain name of the machine.
# [host_name] Insert the nodename/hostname of the machine.
# [kernel_version] Insert the version of the OS.
# [kernel_release] Insert the release number of the OS.
# [nis_name] Insert the NIS domain name of the machine.
# [system_name] Insert the system name.
# [total_users] Insert the number of current users logged in.
# [tty_name] Insert the name of the current tty line.
# These are the codes for the text attributes.
# [color_normal] Set the color attributes to normal.
# [bold_on] Set the bold attribute.
# [bold_off] Reset the bold attribute (normal intensity).
# [reverse_on] Set reverse video.
# [reverse_off] Reset reverse video.
# [black] Set text color to black.
# [red] Set text color to red.
# [green] Set text color to green.
# [brown] Set the text color to brown.
# [blue] Set the text color to blue.
# [magenta] Set the text color to magenta.
# [cyan] Set the text color to cyan.
# [white] Set the text color to white.
# [black_bkg] Set the background color to black.
# [red_bkg] Set the background color to red.
# [green_bkg] Set the background color to green.
# [brown_bkg] Set the background color to brown.
# [blue_bkg] Set the background color to blue.
# [magenta_bkg] Set the background color to magenta.
# [cyan_bkg] Set the background color to cyan.
# [white_bkg] Set the background color to white.
# Color attributes variable assignment.
normal='\\033[0m'
bold_on='\\033[1m'
bold_off='\\033[22m'
reverse_on='\\033[7m'
reverse_off='\\033[27m'
# Foreground colors.
black='\\033[30m'
red='\\033[31m'
green='\\033[32m'
brown='\\033[33m'
blue='\\033[34m'
magenta='\\033[35m'
cyan='\\033[36m'
white='\\033[37m'
# Background colors
black_bkg='\\033[40m'
red_bkg='\\033[41m'
green_bkg='\\033[42m'
brown_bkg='\\033[43m'
blue_bkg='\\033[44m'
magenta_bkg='\\033[45m'
cyan_bkg='\\033[46m'
white_bkg='\\033[47m'
# Assign variables
tdate="`date -d now +\"%a %b %d %Y\"`"
ltime="`date -d now +\"%I:%M:%S %p\"`"
ttyname="$2"
osname="`uname -s`"
arch="`arch`"
host_name="`hostname`"
kernel_version="`uname -v`"
kernel_release="`uname -r`"
nusers="`who -u | wc -l`"
nisname="`hostname -y`"
dnsname="`hostname -d`"
baudrate="`stty -F /dev/$2 speed`"
#cclist="arch_name \
# baud_rate \
# current_date \
# current_time \
# dns_name \
# host_name \
# kernel_version \
# kernel_release \
# nis_name \
# system_name \
# total_users \
# tty_name \
# color_normal \
# bold_on \
# bold_off \
# reverse_on \
# reverse_off \
# black \
# red \
# green \
# brown \
# blue \
# magenta \
# cyan \
# white \
# black_bkg \
# red_bkg \
# green_bkg \
# brown_bkg \
# blue_bkg \
# magenta_bkg \
# cyan_bkg \
# white_bkg"
#declare -A cmdlist
#cmdlist=( ["arch_name"]="`arch`" \
# ["baud_rate"]="`stty -F /dev/$2 speed`" \
# ["current_date"]="`date -d now +\"%a %b %d %Y\"`" \
# ["current_time"]="`date -d now +\"%I:%M:%S %p\"`" \
# ["dns_name"]="`hostname -d`" \
# ["host_name"]="`hostname`" \
# ["kernel_version"]="`uname -v`" \
# ["kernel_release"]="`uname -r`" \
# ["nis_name"]="`hostname -y`" \
# ["system_name"]="`uname -s`" \
# ["total_users"]="`who -u | wc -l`" \
# ["tty_name"]="`tty | sed 's,.*/,,'`" \
# ["color_normal"]='\\033[0m' \
# ["bold_on"]='\\033[1m' \
# ["bold_off"]='\\033[22m' \
# ["reverse_on"]='\\033[7m' \
# ["reverse_off"]='\\033[27m' \
# ["black"]='\\033[30m' \
# ["red"]='\\033[31m' \
# ["green"]='\\033[32m' \
# ["brown"]='\\033[33m' \
# ["blue"]='\\033[34m' \
# ["magenta"]='\\033[35m' \
# ["cyan"]='\\033[36m' \
# ["white"]='\\033[37m' \
# ["black_bkg"]='\\033[40m' \
# ["red_bkg"]='\\033[41m' \
# ["green_bkg"]='\\033[42m' \
# ["brown_bkg"]='\\033[43m' \
# ["blue_bkg"]='\\033[44m' \
# ["magenta_bkg"]='\\033[45m' \
# ["cyan_bkg"]='\\033[46m' \
# ["white_bkg"]='\\033[47m' )
# Reset the VT.
echo -e "\033c" >/dev/$2
# Read /etc/issue and echo each line to the specified VT.
# The while loop is much slower at processing /etc/issue
# and printing the text on the VT. On my machine it took
# approx 880mS to display the sample file. What appears to
# be the convulated sed statement took just 94mS.
# I've left the while loop for those who would prefer it.
#while read -r line; do
# for code in $cclist; do
#line=`echo $line | sed 's,\['"$code"'],'"${cmdlist[$code]}"',g'`
# done
# echo -e "$line" >/dev/$2
#done < /etc/issue
#unset $cmdlist
# This is much faster than the while loop. If you use the
# while loop, delete this.
echo -e "`sed -e 's,\[arch_name],'"$arch"',g' \
-e 's,\[baud_rate],'"$baudrate"',g' \
-e 's,\[current_date],'"$tdate"',g' \
-e 's,\[current_time],'"$ltime"',g' \
-e 's,\[dns_name],'"$dnsname"',g' \
-e 's,\[host_name],'"$host_name"',g' \
-e 's,\[kernel_version],'"$kernel_version"',g' \
-e 's,\[kernel_release],'"$kernel_release"',g' \
-e 's,\[nis_name],'"$nisname"',g' \
-e 's,\[system_name],'"$osname"',g' \
-e 's,\[total_users],'"$nusers"',g' \
-e 's,\[tty_name],'"$ttyname"',g' \
-e 's,\[color_normal],'"$normal"',g' \
-e 's,\[bold_on],'"$bold_on"',g' \
-e 's,\[bold_off],'"$bold_off"',g' \
-e 's,\[reverse_on],'"$reverse_on"',g' \
-e 's,\[reverse_off],'"$reverse_off"',g' \
-e 's,\[black],'"$black"',g' \
-e 's,\[red],'"$red"',g' \
-e 's,\[green],'"$green"',g' \
-e 's,\[brown],'"$brown"',g' \
-e 's,\[blue],'"$blue"',g' \
-e 's,\[magenta],'"$magenta"',g' \
-e 's,\[cyan],'"$cyan"',g' \
-e 's,\[white],'"$white"',g' \
-e 's,\[black_bkg],'"$black_bkg"',g' \
-e 's,\[red_bkg],'"$red_bkg"',g' \
-e 's,\[green_bkg],'"$green_bkg"',g' \
-e 's,\[brown_bkg],'"$brown_bkg"',g' \
-e 's,\[blue_bkg],'"$blue_bkg"',g' \
-e 's,\[magenta_bkg],'"$magenta_bkg"',g' \
-e 's,\[cyan_bkg],'"$cyan_bkg"',g' \
-e 's,\[white_bkg],'"$white_bkg"',g' </etc/issue`" >/dev/$2
# Change this line to the correct path and name of your getty.
exec /sbin/getty -i $1 $2
exit 0
This is a test /etc/issue file I used for testing the control code:
Code:
You are connected on [bold_on][red][tty_name] [color_normal]at [bold_on][magenta][baud_rate][white] bauds.
[bold_on][blue]Today is [red][current_date] [blue]and the local time is [red][current_time].
[green]My DNS name is [red][dns_name].
[cyan]This machine is an [arch_name] running [brown][system_name] [kernel_release] [kernel_version].
[white]There are [blue][total_users] [white]users logged on.
Normal text:
[bold_off][black]This text is black [red]This text is red [green]This text is green [brown]This text is brown
[blue]This text is blue [magenta]This text is magenta [cyan]This text is cyan [white]This text is white
Bold text:
[bold_on][black]This text is black [red]This text is red [green]This text is green [brown]This text is brown
[blue]This text is blue [magenta]This text is magenta [cyan]This text is cyan [white]This text is white[bold_off]
Reverse text:
[red_bkg][black]Black on red[black_bkg] [red_bkg][green]Green on red[black_bkg] [red_bkg][brown]Brown on red[black_bkg] [red_bkg][blue]Blue on red[black_bkg] [red_bkg][magenta]Magenta on red[black_bkg] [red_bkg][cyan]Cyan on red[black_bkg] [red_bkg][white]White on red
[green_bkg][black]Black on green[black_bkg] [green_bkg][red]Red on green[black_bkg] [green_bkg][brown]Brown on green[black_bkg] [green_bkg][blue]Blue on green[black_bkg] [green_bkg][magenta]Magenta on green[black_bkg] [green_bkg][cyan]Cyan on green[black_bkg] [green_bkg][white]White on green
[brown_bkg][black]Black on brown[black_bkg] [brown_bkg][red]Red on brown[black_bkg] [brown_bkg][green]Green on brown[black_bkg] [brown_bkg][blue]Blue on brown[black_bkg] [brown_bkg][magenta]Magenta on brown[black_bkg] [brown_bkg][cyan]Cyan on brown[black_bkg] [brown_bkg][white]White on brown
[blue_bkg][black]Black on blue[black_bkg] [blue_bkg][red]Red on blue[black_bkg] [blue_bkg][brown]Brown on blue[black_bkg] [blue_bkg][magenta]Magenta on blue[black_bkg] [blue_bkg][cyan]Cyan on blue[black_bkg] [blue_bkg][white]White on blue
[magenta_bkg][black]Black on magenta[black_bkg] [magenta_bkg][red]Red on magenta[black_bkg] [magenta_bkg][green]Green on magenta[black_bkg] [magenta_bkg][brown]Brown on magenta[black_bkg] [magenta_bkg][blue]Blue on magenta[black_bkg] [magenta_bkg][cyan]Cyan on magenta[black_bkg] [magenta_bkg][white]White on magenta
[cyan_bkg][black]Black on cyan[black_bkg] [cyan_bkg][red]Red on cyan[black_bkg] [cyan_bkg][green]Green on cyan[black_bkg] [cyan_bkg][brown]Brown on cyan[black_bkg] [cyan_bkg][blue]Blue on cyan[black_bkg] [cyan_bkg][magenta]Magenta on cyan[black_bkg] [cyan_bkg][white]White on cyan
[white_bkg][black]Black on white[black_bkg] [white_bkg][red]Red on white[black_bkg] [white_bkg][green]Green on white[black_bkg] [white_bkg][brown]Brown on white[black_bkg] [white_bkg][blue]Blue on white[black_bkg] [white_bkg][magenta]Magenta on white[black_bkg] [white_bkg][cyan]Cyan on white
[black]This line shows that whitespace are drawn in the last background color.
[bold_on][green]If attributes are not reset, the last attributes will be applied to the login prompt
You must now modify you /etc/inittab. I would suggest you test it on one VT first. to test on TTY2, change this line of your /etc/inittab:
Code:
2:23:respawn:/sbin/getty.sh 38400 tty2
to:
Code:
2:23:respawn:/sbin/mygetty.sh 38400 tty2
Now have init re-examine the /etc/inittab file:
Now kill all getty processes. This will respawn all getty's except for the one that was used for TTY2:
Switching to TTY2 will now show your colorized pre-login banner.
|