Firefly-RK3288 Ubuntu18.04 修改终端登录显示信息

Platform: Firefly-RK3288
OS: Ubuntu 18.04
Module: motd


起因

最近在调试一块Firefly-RK3288 的板子,烧录的是Firefly官方提供的Ubuntu 根文件系统(我用的镜像是rk3288_ubuntu_18.04_armhf_ext4_v2.04_20201125-1538_DESKTOP.img),发现串口终端显示的系统登录信息有点意思,如下所示:
请添加图片描述
可以看出他们的登录信息是定制过的,显示了firefly的彩色艺术字,还有他们的网址。这引起了我的好奇,想探究下这是如何实现的。

探究

查找了一些资料12,了解到这个功能在系统中是通过motd文件来实现的。motd是message of the day的缩写,意为当日消息或问候报文,作用就是在用户登录终端时输出一些提示信息,这些信息包括3

  • 欢迎信息
  • 提示使用系统的注意事项
  • 系统运行的概要信息
  • 其他希望用户看到的信息(譬如广告)等

通常linux系统可以通过配置/etc/motd文件来实现该功能,但是在Ubuntu系统中该方法无效,而是通过/var/run/motd.dynamic 动态生成。

root@firefly:/etc/ssh# cat /var/run/motd.dynamic 
 _____ _           __ _       
|  ___(_)_ __ ___ / _| |_   _ 
| |_  | | '__/ _ \ |_| | | | |
|  _| | | | |  __/  _| | |_| |
|_|   |_|_|  \___|_| |_|\__, |
                        |___/ 
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.4.194 armv7l)

 * Documentation:  http://wiki.t-firefly.com
 * Management:     http://www.t-firefly.com

System information as of Sun Jan 28 23:58:20 CST 2018

System load:   0.45 0.10 0.03  	Up time:       0 min		
Memory usage:  3 % of 1996MB 	IP:            
Usage of /:    1% of 12G    

试了下直接修改该文件也是无效,又了解了下它实际是通过/etc/update-motd.d/目录下的一系列脚本在开机后根据前缀数字顺序来执行生成的45,我的设备中该目录下有3个脚本:

root@firefly:/etc/update-motd.d# ls
00-header  10-help-text  30-sysinfo

先看看00-header这个脚本:

#!/bin/sh

[ -r /etc/lsb-release ] && . /etc/lsb-release
TERM=linux toilet -f standard -F gay Firefly
if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
# Fall back to using the very slow lsb_release utility
DISTRIB_DESCRIPTION=$(lsb_release -s -d)
fi
printf "Welcome to %s (%s %s %s)\n" "$DISTRIB_DESCRIPTION" "$(uname -o)" "$(uname -r)" "$(uname -m)"	

关键就是这句 TERM=linux toilet -f standard -F gay Firefly,其中:TERM=linux设置终端类型为linux,然后使用toilet工具将普通的文本转换为艺术字,这是个有趣的小工具,用法如下:

root@firefly:/# toilet -h
  -f, --font <name>        select the font
  -d, --directory <dir>    specify font directory
  -s, -S, -k, -W, -o       render mode (default, force smushing,
                           kerning, full width, overlap)
  -w, --width <width>      set output width
  -t, --termwidth          adapt to terminal's width
  -F, --filter <filters>   apply one or several filters to the text
  -F, --filter list        list available filters
      --gay                rainbow filter (same as -F gay)
      --metal              metal filter (same as -F metal)
  -E, --export <format>    select export format
  -E, --export list        list available export formats
      --irc                output IRC colour codes (same as -E irc)
      --html               output an HTML document (same as -E html)
  -h, --help               display this help and exit
  -I, --infocode <code>    print FIGlet-compatible infocode
  -v, --version            output version information and exit
Usage: toilet [ -hkostvSW ] [ -d fontdirectory ]
              [ -f fontfile ] [ -F filter ] [ -w outputwidth ]
              [ -I infocode ] [ -E format ] [ message ]

然后10-help-text 就是定义了他们的网址,30-sysinfo 用于显示系统信息,没有太多特殊就不列出了。因此只要修改增删这些脚本就能定制出自己想要的motd。

结果

既然找到了位置,我也尝试修改一下相关脚本,制作一个motd练练手:
请添加图片描述


欢迎留言讨论,感谢阅读~

参考资料


  1. Linux中创建自己的MOTD ↩︎

  2. 聊聊 Linux 登陆提示信息 motd 文件 ↩︎

  3. Linux MOTD ↩︎

  4. SSH 改变登录显示信息 ↩︎

  5. [记录]Linux登录前后提⽰语 ↩︎

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值