[Tutorial] Editing DitePi Terminal Banner

Guides and tutorials for various stuff. Posted by DietPi users.
Post Reply
bromeara
Posts: 2
Joined: Wed Nov 21, 2018 1:52 am

[Tutorial] Editing DitePi Terminal Banner

Post by bromeara » Wed Nov 21, 2018 10:32 am

Introduction

Some notes on editing or removing the banner / motd that appears when you login over ssh. There are two main files to edit to change the banner's behavior.
  • /DietPi/dietpi/func/dietpi-banner : Script for displaying the banner
  • /DietPi/dietpi/login : Script Called on login, calls dietpi-banner
Removing Banner

In the login file find the entry for the type of login you want to change the banner for in the Main Loop of the script. The one I changed was Normal Login.

Code: Select all

#----------------------------------------------------------------
    #Normal Login
    if (( $G_DIETPI_INSTALL_STAGE == 1 )); then

            /DietPi/dietpi/func/dietpi-banner 1

            (( $AUTO_START_INDEX > 0 )) && Run_AutoStart

#----------------------------------------------------------------
To remove the menu completely just make the line that calls the banner script a comment.

Code: Select all

#/DietPi/dietpi/func/dietpi-banner 1
To remove only the credits, you can change the banner script argument to 0. Using 0 as the argument will not clear the screen before printing meaning it is useful if you just want to append the dietpi banner to your own message of the day through /etc/update-motd.d

Code: Select all

/DietPi/dietpi/func/dietpi-banner 0
If you would like to clear the system MOTD when using the 0 banner argument you have to edit the banner script's Banner_Dietpi function, see "Editing Banner" for more instructions on editing the banner file directly.

Code: Select all

Banner_Dietpi(){
       if (( $INPUT == 1 )); then  #"if(( $INPUT < 1)); then" will clear the MOTD when argument is 0
               printf '\ec' # clear current terminal screen
       fi
...
Editing Banner

The banner actually is a nice base if you add don't want to make a motd script from scratch. The following is an example to display the $SHELL environment variable in the banner. If you would like to edit the DietPi banner first follow the instructions for removing it and then make a copy of dietpi-banner in /etc/update-motd.d or replace /etc/motd if you do not want the default motd to be shown with it. This will allow your changes to persist through an update but you might have to remove the default banner again after an update. The copy can be made with the following commands

Code: Select all

sudo cp /DietPi/dietpi/func/dietpi-banner /etc/update-motd.d/

or

sudo mv /etc/motd /etc/motd.old && sudo cp /DietPi/dietpi/func/dietpi-banner /etc/motd
Create a function in dietpi-banner to echo out the information you want to display, I used a copy of the Hardware_Model_Print function and appended it to the Globals section.

Code: Select all

ShellEnv_Print(){

                echo -e " \e[1m"Shell Path"\e[0m \e[90m| $SHELL\e[0m\n \e[38;5;154m────────────────────────────────────────────────\e[0m"
                
        }
        
#/////////////////////////////////////////////////////////////////////////////////////
# Banner Print
#/////////////////////////////////////////////////////////////////////////////////////
In order to add your message to the banner edit the Banner_Dietpi function in the Banner Print section to include your function, this is also where you can remove any unwanted banner sections by commenting out or deleting their print function.

Code: Select all

        Banner_Dietpi(){
                ... # Terminal Clearing Code
                echo -e " \e[38;5;154m────────────────────────────────────────────────\e[0m\n \e[1mDietPi\e[0m $TEXT_TOP\n \e[38;5;154m────────────────────────────────────────────────\e[0m"
                #Hardware_Model_Print
                IPAddress_Print
                ShellEnv_Print
        }
This should allow you to add any entry you need to the banner, the rest of the dietpi-banner script is also a good example however hopefully this gave you an idea where to start.
Last edited by bromeara on Sat Nov 24, 2018 11:17 pm, edited 1 time in total.

User avatar
MichaIng
Legend
Posts: 1626
Joined: Sat Nov 18, 2017 5:21 pm

Re: [Tutorial] Editing DitePi Terminal Banner

Post by MichaIng » Thu Nov 22, 2018 10:06 pm

Great tutorial :D.
Note that on update, the script(s) will be overwritten, so take care to backup (the essential custom parts). On update we might improve some methods the banner uses or changed global variables/functions, so restoring the whole script might break things. So you would need to restore the custom entries only.

Perhaps we can by times add a customization GUI that allows to add/remove columns/lines of the banner and fill the cells with custom and predefined entries.

The dietpi-* command hints could be turned into optional. Makes sense, since users will know them after using 1-2 times and can easily recheck via dietpi- <press TAB> ;).

Personally I would keep the credits fixed, simply fair for the contributors/tions :roll:.

bromeara
Posts: 2
Joined: Wed Nov 21, 2018 1:52 am

Re: [Tutorial] Editing DitePi Terminal Banner

Post by bromeara » Sat Nov 24, 2018 11:42 pm

Thanks for the feedback, I changed the "Editing Banner" section a little to hopefully work around the update issue.
MichaIng wrote:
Thu Nov 22, 2018 10:06 pm
Perhaps we can by times add a customization GUI that allows to add/remove columns/lines of the banner and fill the cells with custom and predefined entries.
This would be interesting, what would be the most DietPi like way to do this? add an option to the dietpi-config command? or something entirely seperate? Hopefully a solution like this would allow configurations to persist through updates as well.

User avatar
mrmajik45
Posts: 2
Joined: Tue Sep 25, 2018 9:39 pm
Location: Indiana
Contact:

Re: [Tutorial] Editing DitePi Terminal Banner

Post by mrmajik45 » Mon Nov 26, 2018 2:58 pm

Maybe if someone wanted a small ASCII art on startup that represents the logo.
ReactOS Donator ~ $5.00 | Linux Mint Donator ~ $1.00 in BTC

User avatar
MichaIng
Legend
Posts: 1626
Joined: Sat Nov 18, 2017 5:21 pm

Re: [Tutorial] Editing DitePi Terminal Banner

Post by MichaIng » Sun Mar 10, 2019 1:32 pm

Finally an issue is opened for this request on GitHub: https://github.com/MichaIng/DietPi/issues/2627

Post Reply