4

rust-motd Setup

 3 years ago
source link: https://ttys3.dev/post/rust-motd-setup/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

rust-motd Setup

2022-01-05

:: 荒野無燈

:: Mod 2022-03-04(025b313)

#rust  #motd  #systemd-timer 

2022-03-04 update:

gdm 用户最好不要启用 motd. 否则在登录界面会卡很久才进去.

有办法可以禁用这一行为, see https://bbs.archlinux.org/viewtopic.php?pid=1684018#p1684018

moving the following line:

session    optional   pam_motd.so          motd=/etc/motd

from /etc/pam.d/system-login to /etc/pam.d/sshd.

The result is that the motd is no longer displayed in gdm, but it’s still displayed when logging in through ssh.

-——————————————————————————-

https://github.com/rust-motd/rust-motd

Beautiful, useful, configurable MOTD generation with zero runtime dependencies

如果显示 hostname 时想使用 figlet 的话需要安装一下:

paru -S figlet

the oneshot service

cat <<EOF > /etc/systemd/system/rust-motd.service

[Unit]
Description=run rust-motd
Wants=network-online.target
After=network-online.target

[Service]
Restart=on-failure
TimeoutStopSec=5
StandardOutput=file:/etc/motd
ExecStart=rust-motd /root/.config/rust-motd/config.toml
Type=oneshot

[Install]
WantedBy=default.target

EOF

the timer:

cat <<EOF > /etc/systemd/system/rust-motd.timer

[Unit]
Description=Run rust-motd every 5 minutes and on boot

[Timer]
OnBootSec=30s
OnUnitActiveSec=5min 

[Install]
WantedBy=timers.target

EOF

the config:

注意替换配置中的 Your-Location-Here 为你的实际城市名(英文).

替换 user001 为你自己的用户名.

cat <<EOF > /root/.config/rust-motd/config.toml
[global]
 progress_full_character = "="
 progress_empty_character = "="
 progress_prefix = "["
 progress_suffix = "]"
 time_format = "%Y-%m-%d %H:%M:%S"

 [banner]
color = "red"
 command = "hostname | figlet -f slant"
# if you don't want a dependency on figlet, you can generate your
# banner however you want, put it in a file, and then use something like:
# command = "cat banner.txt"

 [weather]
 url = "https://wttr.in/Your-Location-Here?0"
 proxy = "http://127.0.0.1:7890"

# [service_status]
# Accounts = "accounts-daemon"
# Cron = "cron"

[docker_status]
# Local containers MUST start with a slash
# https://github.com/moby/moby/issues/6705
#"/nextcloud-nextcloud-mariadb-1" = "Nextcloud Database"

 [uptime]
 prefix = "Up"

 [user_service_status]
 clash = "clash"
 systemd-resolved = "systemd-resolved"
 gpg-agent = "gpg-agent"

# [ssl_certificates]
# sort_method = "manual"
#
#    [ssl_certificates.certs]
#    CertName1 = "/path/to/cert1.pem"
#    CertName2 = "/path/to/cert2.pem"

 [filesystems]
 root = "/"
 home = "/home"

 [memory]
 swap_pos = "beside" # or "below" or "none"

# [fail_2_ban]
# jails = ["sshd", "anotherjail"]

 [last_login]
 root = 2
 user001 = 1

[last_run]


EOF

enable:

sudo systemctl enable --now rust-motd.timer

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK