Skip to content

Commit 45803a2

Browse files
authored
Update README.md
Documentation reorganized
1 parent 0116f4b commit 45803a2

File tree

1 file changed

+47
-68
lines changed

1 file changed

+47
-68
lines changed

README.md

Lines changed: 47 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -17,110 +17,93 @@ Customized dynamic Message of the Day (MOTD) for Raspberry Pi
1717
</div>
1818

1919
---
20+
<div align="justify">
21+
2022
### Intro
21-
Many folks use Raspberry Pi as headless (without display) system. If you use SSH to connect to your Raspberry Pi more often and interested in changing the MOTD (message of the day), this might be the one you were looking for. There are many options available for customized motd on the web with and without ascii art. **The goal was to create simple, attractive, swift and useful motd**.
23+
Many folks use Raspberry Pi as headless. If you use SSH more often to connect Raspberry Pi and interested in changing the MOTD (message of the day), keep on reading. There are many customized motds available on the web with and without ascii art. **The goal is to create simple, attractive, swift and useful motd**.
2224
<br/>
2325

24-
I prefer updating my OS manually. After the transition from Ubuntu to Raspberry Pi OS, lack of number of available updates on motd was the triggering point to develop this motd. Few custom motd on the web for Raspberry Pi OS shows the number of available updates. They used `apt-check` utility which was part of update-notifier-common package. It is no longer available from RaspiOS buster onward. They merged the features of update-notifier-common package into unattended-upgrades add-on package. Ubuntu uses the same utility to show package count on motd. I used `apt-get` to parse the required information.
26+
Lack of available update count in RaspiOS motd is the triggering point to develop this motd. Few custom motds on the web for RaspiOS shows the available update count using `apt-check` utility which was part of update-notifier-common package. This package is no longer available from RaspiOS buster onwards, its functionality is merged into unattended-upgrades add-on package. Ubuntu uses the same utility to show package count on motd. I used `apt-get` to parse the required information.
2527
<br/>
2628

27-
The process I used for the motd is the same as Raspberry Pi OS OR Ubuntu uses to show the motd dynamically. There is no third party package or tool used. It is written in bash and executes using the same mechanism as the default motd. There are multiple commands for retrieving the same information. I tested various commands for each info and used the ones that took least amount of time. This dynamic motd takes approximately 1 sec or less after entering password. This is the fastest you can get with all the information it is displaying.
29+
The process used for the motd is the same as RaspiOS or Ubuntu uses to show the motd dynamically. There is no additional package or third party tool used. It is written in bash and executes using the same mechanism as the default motd. There are multiple commands for retrieving the same information. I tested various commands for each info and used the ones that took least amount of time. This dynamic motd takes approximately 1 sec after authentication. This is the fastest you can get with all the information it is displaying.
2830
<br/>
2931

3032
#### Specs:
31-
> Raspberry Pi 4 Model B &nbsp;&nbsp; raspios-bullseye-arm64-lite
32-
> System & Distro used for motd. It should work on other specs as well.
33+
> |HW |OS |
34+
> |:-----------------------|:----------------------------|
35+
> |`Raspberry Pi 4 Model B`|`raspios-bullseye-arm64-lite`|
3336
#
3437
### Steps
3538
#### ⮞ Remove Default MOTD
3639

37-
* Delete `/etc/motd` file. This file contains the static text about Debian GNU/Linux liability. You can check the contents of the file with command `sudo nano /etc/motd`. Alternatively you can keep a backup of this file at some place.
40+
* Delete `/etc/motd`. This file contains the static text about Debian GNU/Linux liability. Alternatively you can keep a backup of this file at some place.
3841
> **Delete motd file:**
3942
> `sudo rm /etc/motd`
4043
41-
* Delete `/etc/update-motd.d/10-uname` file. This file prints the OS version dynamically to the default message. We will print a trimmed down version of OS through our new customized motd.
44+
* Delete `/etc/update-motd.d/10-uname`. This file prints the OS version dynamically to the default message. New motd will print a trimmed down version of OS.
4245
> **Delete 10-uname file:**
4346
> `sudo rm /etc/update-motd.d/10-uname`
4447
45-
* Modify `/etc/ssh/sshd_config` file. This file prints last login timestamp and location. We will print last login timestamp and location through our new customized motd.
48+
* Modify `/etc/ssh/sshd_config`. This file prints last login timestamp and location. New motd will print last login timestamp and location.
4649
> **Edit sshd_config file:**
4750
> `sudo nano /etc/ssh/sshd_config`
48-
> Find the line `#PrintLastLog yes` Replace it with `PrintLastLog no`
49-
> Save sshd_config file [Ctrl+O] & Exit nano [Ctrl+X]
51+
> Add line `PrintLastLog no`. Default is yes.
52+
> Save `Ctrl+O` and Exit `Ctrl+X`
5053
> Restart sshd process `sudo systemctl restart sshd`
5154
5255
#
5356
> **_NOTE:_**
54-
> At this point we completely removed the default motd. You can reconnect using ssh and if you followed the steps correctly you will not see any motd.
57+
> Default motd is completely removed. Reconnect ssh session and if you followed the steps correctly you will not see any motd.
5558
#
5659

5760
#### ⮞ Implement New MOTD
61+
* Copy `10-welcome`, `15-system` and `20-update` scripts from the latest release under `update-motd.d` dir to `/etc/update-motd.d` dir.
62+
Make sure scripts are under the ownership of root and are executable.
63+
> **Change ownership [If needed]:**
64+
> `sudo chown root:root /etc/update-motd.d/<script-name>`
5865
59-
* Copy `10-welcome` & `15-system` files from this repo folder `update-motd.d` to Raspberry Pi OS folder `/etc/update-motd.d` Make sure these files are under the user:group of root and they are executable. You can **either** use WinSCP or wget to copy/download these files to tmp folder and then move them to `/etc/update-motd.d` **or** create empty files in `/etc/update-motd.d` using touch and copy/paste the contents of corresponding file in it.
60-
61-
> **Change ownership of files [If needed]:**
62-
> `sudo chown root:root /etc/update-motd.d/10-welcome`
63-
> `sudo chown root:root /etc/update-motd.d/15-system`
64-
65-
> **Create empty files to copy/paste contents [If needed]:**
66-
> `sudo touch /etc/update-motd.d/10-welcome`
67-
> `sudo touch /etc/update-motd.d/15-system`
68-
69-
> **Make files executable:**
70-
> `chmod +x /etc/update-motd.d/10-welcome`
71-
> `chmod +x /etc/update-motd.d/15-system`
72-
73-
> If everything is done properly it will look something like this. Ignore `20-update` file for now we will create it in next step:
74-
> ![update-motd_files](https://user-images.githubusercontent.com/11185794/132084515-5b41d9fb-5e84-4c1d-8a2f-7d7cd9c5e671.png)
66+
> **Make scripts executable [If needed]:**
67+
> `sudo chmod +x /etc/update-motd.d/<script-name>`
7568
76-
* Create third file `/etc/update-motd.d/20-update` as empty file using touch
77-
> **Create file and make it executable:**
78-
> `sudo touch /etc/update-motd.d/20-update`
79-
> `chmod +x /etc/update-motd.d/20-update`
69+
> ![update-motd_files](https://user-images.githubusercontent.com/11185794/202982786-76711b90-6cc9-4680-afb5-de07fa1da446.png)
8070
8171
#
8272
> **_NOTE:_**
83-
> If you noticed all the files we have created/copied so far have filenames starting with a number. Dynamic contents of the motd are created by PAM (Pluggable Authentication Module) running bash files from /etc/update-motd.d folder. The files are read in number order and do not need a file extension. In the default motd it was executing 10-uname file to show the OS version which we deleted earlier.
73+
> If you noticed all the scripts have names starting with a number. Dynamic contents of the motd are created by PAM (Pluggable Authentication Module) running bash scripts from /etc/update-motd.d dir. Scripts are read in numeric order and do not need a file extension. In the default motd it was executing 10-uname script to show the OS version which we deleted earlier.
8474
#
8575

86-
* In this step we will create static contents of our new motd. This is not entirely static, PAM will execute this information from bash file that has static contents. Static file is created from dynamic file using cronjob once a day. It is done this way to minimize startup delay. If I keep it completely dynamic (how I initially did and it was easier), the startup delay between entering the password and seeing the prompt is approximately 3-4 seconds.
87-
* Create a folder `/etc/update-motd-static.d` Even though this folder contains the dynamic file that will generate the static file `/etc/update-motd.d/20-update` I am calling it `update-motd-static.d` for easier distinction (You can name it whatever you prefer and use the same name in automation tasks)
88-
> **Create folder:**
76+
* Create static contents of new motd. This is not entirely static, PAM will execute static script. Static script is created from dynamic script once a day with systemd timer. It minimizes startup delay. Keeping it completely dynamic increases startup delay to 3-4 seconds after authentication.
77+
* Create dir /etc/update-motd-static.d
8978
> `sudo mkdir /etc/update-motd-static.d/`
9079
91-
* Copy `20-update` file from this repo folder `update-motd-static.d` to this newly created folder `/etc/update-motd-static.d` Make sure file is under the user:group of root and it is executable. You can **either** use WinSCP or wget to copy/download this file to tmp folder and then move it to `/etc/update-motd-static.d` **or** create empty file in `/etc/update-motd-static.d` using touch and copy/paste the contents of corresponding file in it.
92-
93-
> **Change ownership of file [If needed]:**
80+
* Copy `20-update` script from the latest release under `update-motd-static.d` dir to this newly created dir `/etc/update-motd-static.d`. Make sure script is under the ownership of root and it is executable.
81+
> **Change ownership [If needed]:**
9482
> `sudo chown root:root /etc/update-motd-static.d/20-update`
9583
96-
> **Create empty file to copy/paste contents [If needed]:**
97-
> `sudo touch /etc/update-motd-static.d/20-update`
84+
> **Make script executable [If needed]:**
85+
> `sudo chmod +x /etc/update-motd-static.d/20-update`
9886
99-
> **Make file executable:**
100-
> `chmod +x /etc/update-motd-static.d/20-update`
101-
102-
> If everything is done properly it will look something like this:
103-
> ![update-motd-static_files](https://user-images.githubusercontent.com/11185794/132091200-e960ac30-4985-447a-9c26-5878f2514c6e.png)
87+
> ![update-motd-static_files](https://user-images.githubusercontent.com/11185794/202983089-6b303358-9b27-4005-bf27-170c16141cc8.png)
10488
105-
106-
* Execute this file. This process will update the static file `/etc/update-motd.d/20-update` with the number of pending updates (if any). We will automate this process through cronjob later.
107-
> **Execute file:**
89+
* Run dynamic script to update the static script `/etc/update-motd.d/20-update` with pending update count (if any). We will automate this process through systemd timer.
90+
> **Run script:**
10891
> `sudo run-parts /etc/update-motd-static.d`
10992
11093
#
11194
> **_NOTE:_**
112-
> At this point we implemented our new motd, pending few automations. Let's test our new motd. It will verify that everything we did so far is working properly. There are multiple ways to test **either** you can reconnect using ssh **or** run the new motd from the same shell. If you followed the steps correctly you will see new motd something similar to the initial preview of this guide.
113-
> > **Execute motd from the same shell:**
95+
> New motd is implemented, pending few automations. Let's test new motd to verify that everything is working properly. **Either** reconnect ssh session **or** run the new motd from the same shell. If steps were followed correctly you will see new motd, something similar to the preview.
96+
> > **Run motd from the same shell:**
11497
> > `sudo run-parts /etc/update-motd.d`
11598
#
11699

117100
#### ⮞ Automation
118101

119-
* We are almost done. We need to automate the process of finding pending OS updates count. There are 2 options **either** systemd timer (recommended) **or** cronjob. They are scheduled to run once a day at 8:00pm for pending OS updates count. You can change the time and frequency based on your requirements, once a day serves my purpose very well.
102+
* We need to automate the process of finding pending OS update count. There are 2 options **either** systemd timer (recommended) **or** cronjob. It is scheduled to run once a day at 8:00pm. You can change the time and frequency based on your preference.
120103

121104
* **Systemd Timer**
122-
Copy `motd-update.timer` & `motd-update.service` files from this repo folder `systemd-timer` to `/etc/systemd/system`. Make sure files are under root ownership. Enable and start timer.
123-
> **Change files ownership [If needed]:**
105+
Copy `motd-update.timer` and `motd-update.service` from the latest release under `systemd-timer` dir to `/etc/systemd/system`. Make sure files are under the ownership of root. Enable and start timer.
106+
> **Change ownership [If needed]:**
124107
> `sudo chown root:root /etc/systemd/system/motd-update.timer`
125108
> `sudo chown root:root /etc/systemd/system/motd-update.service`
126109
> **Enable timer:**
@@ -131,43 +114,39 @@ The process I used for the motd is the same as Raspberry Pi OS OR Ubuntu uses to
131114
> `systemctl list-timers`
132115

133116
* **Cronjob**
134-
Open crontab for root and add cronjob to it.
117+
Add cronjob for root crontab. If this is the first time you are creating a cronjob, it will ask for preferred editor.
135118
> **Open crontab:**
136119
> `sudo crontab -e`
137120
> **Add cronjob:**
138-
> Add below 2 lines at the end of the crontab file, **save** & close the editor
121+
> Add below lines at the end of the crontab. Save and close the editor.
139122
> ```
140123
> # MOTD - Update '20-update' file - Once A Day At 8:00PM
141124
> 0 20 * * * run-parts /etc/update-motd-static.d
142125
> ```
143126

144-
#
145-
> **_NOTE:_**
146-
> If this is the first time you are creating a cronjob. It will ask for your preferred editor, I use nano, you can choose your preferred one.
147-
#
148-
149-
* Last step. We need to update the pending updates count in motd as soon as we update the OS. With this new motd mechanism it will be updated at the next execution of cronjob. Let's assume you update your system manually by running commands `sudo apt update` & `sudo apt full-upgrade`. **We need to run another command after this** `sudo run-parts /etc/update-motd-static.d` It will reset the update count in motd as soon as we are done with OS update. Whatever your preferred way to update the OS, run this command at the very end.
150-
* I update OS manually using a bash script `update.sh` after seeing pending updates in motd. This script takes care of everything that includes **update OS, cleanup and update motd count**. `update.sh` is available in the repo under folder `update-os` along with a screenshot of what it will do upon execution. It is well documented. **Open and check the commands first before execution, if you need all of them**. Feel free to modify it according to your requirement.
151-
You can add switch -y to `sudo apt full-upgrade` command if you want to bypass the yes/no prompt. I prefer not to have it as a last chance to review if I want to update or not. I do cleanup as well in this script using `sudo apt --purge autoremove` & `sudo apt clean`, you can remove them if you prefer not to run these after OS update.
127+
* Last step. We need to reset the pending update count in motd as soon as we update the OS, otherwise count will be updated at the next run of systemd timer. Suppose you update system with commands `sudo apt update` & `sudo apt full-upgrade`. **You need to run command `sudo run-parts /etc/update-motd-static.d` at the end.** It will reset the update count in motd after OS update. Whatever your preferred way to update the OS, run this command at the very end.
128+
* I update OS with a bash script `update.sh` after seeing pending updates in motd. It takes care of everything that includes **update OS, cleanup and update motd count**. `update.sh` is available in the latest release under `update-os` dir. Execution screenshot is shown in the repo under `update-os` dir. Script is well documented. **Open and check the commands once before execution.**
129+
You can add switch -y to `sudo apt full-upgrade` command to bypass the yes/no prompt. I prefer not to have it as a last chance to review if I want to update or not. Script does cleanup as well using `sudo apt --purge autoremove` & `sudo apt clean`, you can remove them if you prefer not to run these after OS update.
152130

153131
#
154132
> **_NOTE:_**
155-
> We are done. If you are not seeing the exact colors in your motd as shown in the preview, check the Putty section below for color scheme.
133+
> If you are not seeing the exact colors in your motd as in the preview, check the Putty section below for color scheme.
156134
#
157135

158136
### Scripts Info
159137
#### ⮞ /etc/update-motd.d/10-welcome
160-
> Bash script displays the welcome user message along with current timestamp and OS version.
138+
> Displays the raspberry model, welcome user message, current timestamp and kernel version.
161139
162140
#### ⮞ /etc/update-motd.d/15-system
163-
> Script shows various details of the system. It includes system temperature, memory, running processes and few more. I trimmed down on some of the labels, like I used `Procs` for `Processes`, `Temp` for `Temperature`, `Last` for `Last Login`. You can use full labels according to your liking and arrange them accordingly.
141+
> Shows various details of the system. It includes temperature, memory, running processes and others. Few labels are trimmed down, like `Procs` for `Processes`, `Temp` for `Temperature`, `Last` for `Last Login`. You can use full labels according to your preference and arrange them accordingly.
164142
165143
#### ⮞ /etc/update-motd.d/20-update
166-
> This is the static script. It is generated by `/etc/update-motd-static.d/20-update` to show the number of available updates.
144+
> This static script displays available update count. It is generated by `/etc/update-motd-static.d/20-update`.
167145
168146
#### ⮞ /etc/update-motd-static.d/20-update
169-
> Script calculates the number of available updates and generates the static file for motd display. It can be expanded to show the number of security updates separately like Ubuntu. My requirement was to see the total number only.
147+
> Calculates available update count and generates the static script for motd display. It can be expanded to show the security update count separately like Ubuntu.
170148
171149
#
172150
### PuTTY
173151
I use slight modification of `Liquid Carbon` PuTTY theme from [AlexAkulov](https://github.com/AlexAkulov/putty-color-themes/blob/master/23.%20Liquid%20Carbon.reg). Modified theme `Liquid Carbon Mod.reg` is available under this repo folder `putty` along with screenshots of PuTTY settings.
152+
</div>

0 commit comments

Comments
 (0)