Add Color to Proxmox Logon
Add Color to Proxmox Logon Do you want to rice the logon screen of Proxmox? The idea is to show clearly the login as IP and FQDN and also all the colors and positions of the patch cables - this is not in stead of tagging cables its on top. #color #login #proxmox
Do you want to rice the logon screen of Proxmox? This is easy, just edit one file. This is how I set up the PVE nodes for easy trouble shooting. The idea is to show clearly the login as IP and FQDN and also all the colors and positions of the patch cables - this is not in stead of tagging cables its on top.
If you need to wisit the rack in a data senter you need to act fast. The error is usually a bad one and it has already been on for some time. To help in this we use color coded patch cables: iLo are Blue, MGMT are red VLAns are Green. For PVE we use Corosync on Purple and Migration on Yellow.
Table of Contents
How to make the Debian logon banner
Using figlet writing in bash scripts
Bash with Color
References
How to make the Debian logon banner
If you have changed the IP address of a Proxmox host, or happen to use DHCP for it you will need this. Originally the banner shows the login screen with the IP used at initial setup.
The getty/ agetty program is responsible for displaying the login banner (technically the PRE-login banner) on many distros, including Debian and Ubuntu. Proxmox is based on Debian.
At startup getty reads /etc/issue for the banner text.
In the man getty/agetty, in the ISSUE FILES section, we see that getty supports escape codes for displaying system data. We are interested in using \4 or \4{interface} \n the hostname and \O the domain name.
By default, Proxmox creates a bridge (vmbr0), and connects a NIC to it. You can check this by running ip a
and seeing what interfaces and addresses your system has. Note what bridge has the address you want to show.
All we need to do is replace the hard coded ip with \4{interface}, {vmbr0}
by default on a Proxmox node. The /etc/issue
file is just plain text, and gets created for you when installing Proxmox.
Here is an example of the default file with the 192.0.2.49 ip address.
------------------------------------------------------------------------------
Welcome to the Proxmox Virtual Environment. Please use your web browser to
configure this server - connect to:
https://192.0.2.49:8006/
------------------------------------------------------------------------------
Now that's not pretty. Lets create a figlet logo and edit the /etc/issues
file.
Adding color and more info
figlet -f thin CasaUrsus
If you do not have figlet installed please install it by apt update && apt install figlet
. Avoid fonts with /
they do not work well in figlet.
We will now create something like the first picture.
nano /etc/issue
------------------------------------------------------------------------------
Welcome to the Proxmox Virtual Environment. Please use your web browser to
configure this server - connect to:
,---. . .
| ,---.,---.,---.| |,---.,---.. .,---.
| ,---|`---.,---|| || `---.| |`---.
`---'`---^`---'`---^`---'` `---'`---'`---'
\e{bold}\e{cyan}https://\4{vmbr0}:8006/\e{reset}
\e{bold}\e{yellow}https://\n.\O:8006/\e{reset}
VLAN Switch/port - panel/jack - cable to NIC
MGMT LAN \e{red} 2/01 <===> 4/01 \e{reset}\e{white}<===> enp5s0\e{reset}
VM LAN \e{green} 2/02 <===> 4/02 \e{reset}\e{red}<===> enp9s0\e{reset}
CoroSync \e{bold}\e{magenta} 1/31 <===> 1/03 \e{reset}\e{magenta}<===> enp14s0\e{reset}
Migration \e{bold}\e{yellow} 1/41 <===> 1/04 \e{reset}\e{yellow}<===> enp14s0\e{reset}
------------------------------------------------------------------------------
e or e{name}
Translate the human-readable name to an escape sequence and insert it (for example: \e{red}Alert text.\e{reset}). If the name argument is not specified, then insert \033. The supported names are: black, blink, blue, bold, brown, cyan, darkgray, gray, green, halfbright, lightblue lightcyan, lightgray, lightgreen, lightmagenta, lightred, magenta, red, reset, reverse, yellow and white. All unknown names are silently ignored.
Documentation Address Blocks
The blocks 192.0.2.0/24 (TEST-NET-1), 198.51.100.0/24 (TEST-NET-2) and 203.0.113.0/24 (TEST-NET-3) are provided for use in documentation.
Using figlet writing in bash scripts
If you don't have it installed just install and add some fonts
#!/bin/bash
# Copyright (c) 2023 CasaUrsus
# ____ _ _
# / ___|__ _ ___ __ _| | | |_ __ ___ _ _ ___
#| | / _` / __|/ _` | | | | '__/ __| | | / __|
#| |__| (_| \__ \ (_| | |_| | | \__ \ |_| \__ \
# \____\__,_|___/\__,_|\___/|_| |___/\__,_|___/
#
# Copyright (c) 2023 CasaUrsus
# Author: NalleJ
# License: MIT
# https://github.com/nallej/raw/main/LICENSE
## Functions ===================================================
function header
{
cat <<"EOF"
____ _ _
/ ___|__ _ ___ __ _| | | |_ __ ___ _ _ ___
| | / _` / __|/ _` | | | | '__/ __| | | / __|
| |__| (_| \__ \ (_| | |_| | | \__ \ |_| \__ \
\____\__,_|___/\__,_|\___/|_| |___/\__,_|___/
EOF
}
See the part 2 - use pvebanner
Bash with Color
You can make your BASH script better, by colorizing it's output. Use ANSI escape codes to set text properties like foreground and background colors.
This is a walk down memory lane back to DOS times when codes had to be frequently used for output to terminals, databases and printers.
Use the following template for writing colored text:
echo -e "\e[COLORmSample Text\e[0m"
Option | Description |
---|---|
-e | Enable interpretation of backslash escapes |
\e[ | Begin the color modifications |
COLORm | Color Code + ‘m’ at the end |
\e[0m or \e[m | End the color modifications |
Use in bash scripts as variables
## Variables ===================================================
YW=$(echo "\e[33m") # Yellow
BL=$(echo "\e[36m") # Cyan
RD=$(echo "\e[1;31m") # Bold Red
GN=$(echo "\e[1;92m") # Bold Brite Light Green
PE=$(echo "\e[1;95m") # Purple
BGN=$(echo "\e[4;92m") # Underline Brite Light Green
DGN=$(echo "\e[32m") # Green
BPE=$(echo "\e[95m") # Bright Purple
BYW=$(echo "\e[93m") # Bright Yellow
WGN=$(echo "\e[1;37;1;42m") # Bold White in Light Green Box
WYW=$(echo "\e[1;37;1;43m") # Bold White in Light Green Box
WRD=$(echo "\e[1;37;1;41m") # Bold White in Light Red Box
More ANSI - Color Escape Codes (Bright)
Color |
Foreground Code |
Background Code |
Sample |
---|---|---|---|
Black (Grey) |
30 (90) |
40 (100) |
|
Red |
31 (91) |
41 (101) |
|
Green |
32 (92) |
42 (102) |
|
Brown (Yellow) |
33 (93) |
43 (103) |
|
Blue |
34 (94) |
44 (104) |
|
Magenta/Purple |
35 (95) |
45 (105) |
|
Cyan |
36 (96) |
46 (106) |
|
Light Gray |
37 (97) |
47 (107) |
History
The original specification only had 8 colors, and just gave them names. The SGR parameters 30–37 selected the foreground color, while 40–47 selected the background. Quite a few terminals implemented "bold" (SGR code 1) as a brighter color rather than a different font, thus providing 8 additional foreground colors. Usually you could not get these as background colors, though sometimes inverse video (SGR code 7) would allow that.
Examples: to get black letters on white background use ESC[30;47m
, to get red use ESC[31m
, to get bright red use ESC[1;31m
. To reset colors to their defaults, use ESC[39;49m
(not supported on some terminals), or reset all attributes with ESC[0m
. Later terminals added the ability to directly specify the "bright" colors with 90–97 and 100–107.
37/47 is actually called White.
Bright versions are for forground 90-97 and background 100-107
Bright Black is Grey and Bright White is white
Escape sequence also control the manner in which characters are displayed on the screen:
ANSI Code |
Description |
---|---|
0 |
Normal Characters |
1 |
Bold Characters |
4 |
Underlined Characters |
5 |
Blinking Characters |
7 |
Reverse video Characters |
Combining all these escape sequences
By combining all these escape sequences, we can get more fancy effect.
echo -e "\e[COLOR1;COLOR2mSample Text\e[0m"
There are some differences when combining colors with bold text attribute:
Color |
Foreground Code |
Background Code |
Sample |
---|---|---|---|
Dark Gray |
1;30 |
1;40 |
|
Light Red |
1;31 |
1;41 |
|
Light Green |
1;32 |
1;42 |
|
Yellow |
1;33 |
1;43 |
|
Light Blue |
1;34 |
1;44 |
|
Light Purple |
1;35 |
1;45 |
|
Light Cyan |
1;36 |
1;46 |
|
White |
1;37 |
1;47 |
See the notes for more info on what you may use
Examples:
echo -e "\e[31mRed Text\e[0m"
Red Text
echo -e "\e[42mGreen Background\e[0m"
Green Background
echo -e "\e[1mBold Text\e[0m"
Bold Text
echo -e "\e[3mUnderlined Text\e[0m"
Underlined Text
echo -e "\e[1;33;4;44mYellow Underlined Text on Blue Background\e[0m"
Yellow Underlined Text on Blue Background
References
See agetty man page [1] Figlet fonts [2] Private Network Addresses [3] ANSI escabe codes. Te color will depend on what terminal is used. [4] Updates [5]
Private network addresses on wikipedia. See the main page and Reserved IP addresses page ↩︎
To understand the ANSI escape codes read this wiki page Ther is many implementations, just Windows uses 4 different sets where as Ubuntu one. ↩︎
See my updates: Add Color to Proxmox Logon - 2 and New tools ↩︎