From 9b9aeda40ec78b7194ae8d5e9e235c37c567371e Mon Sep 17 00:00:00 2001 From: AA Date: Fri, 5 Jan 2024 12:46:57 -0500 Subject: [PATCH 1/8] Update os script screenshot --- update-os/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/update-os/README.md b/update-os/README.md index 6f3191f..7ff22f0 100644 --- a/update-os/README.md +++ b/update-os/README.md @@ -1,3 +1,2 @@ ## OS Update Script Preview -![UpdateScript](https://user-images.githubusercontent.com/11185794/132078145-c45cef75-6a3f-49f6-bee6-2415674f8820.png) - +![UpdateScript](https://github.com/ar51an/raspberrypi-motd/assets/11185794/a8e44e0f-a4ab-4206-8626-93be42774d10) From a8a31308b25caa219c29f812eda623168e8c06c8 Mon Sep 17 00:00:00 2001 From: AA Date: Fri, 5 Jan 2024 13:27:36 -0500 Subject: [PATCH 2/8] Update README.md --- README.md | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index ea5b225..8216126 100644 --- a/README.md +++ b/README.md @@ -13,53 +13,50 @@ Customized dynamic message of the day (motd) for Raspberry Pi ### Preview
-![WithCount](https://user-images.githubusercontent.com/11185794/204075510-ac39d1c1-59b6-4972-872c-8ee5edb256a8.png) +![WithCount](https://github.com/ar51an/raspberrypi-motd/assets/11185794/fbf346a2-6978-427b-b042-8fd5a5af3e8e) -![WithoutCount](https://user-images.githubusercontent.com/11185794/204075513-10c08bab-8bac-429b-9a5a-9a1356c57af4.png) +![WithoutCount](https://github.com/ar51an/raspberrypi-motd/assets/11185794/f5f6c3ca-915e-439e-9dbb-8c376c156633)
---
### Intro -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**. +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. **The goal is to create simple, swift and useful motd**.
-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. +Lack of available update count in RaspiOS motd is the triggering point to develop this motd. Traditionally `apt-check` utility in `update-notifier-common` package was used to fetch the available update count. This package is no longer available from `buster` onwards, its functionality is merged into `unattended-upgrades` add-on package. I used `apt-get` to parse the required information.
-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. +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 that took the 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.
#### Specs: > |HW |OS | > |:-----------------------|:----------------------------| -> |`Raspberry Pi 4 Model B`|`raspios-bullseye-arm64-lite`| +> |`Raspberry Pi 4 Model B`|`raspios-bookworm-arm64-lite`| # ### Steps -#### ⮞ Remove Default MOTD +#### ❯ Remove Default MOTD * 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. - > **Delete motd file:** > `sudo rm /etc/motd` * 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. - > **Delete 10-uname file:** > `sudo rm /etc/update-motd.d/10-uname` * Modify `/etc/ssh/sshd_config`. This file prints last login timestamp and location. New motd will print last login timestamp and location. - > **Edit sshd_config file:** > `sudo nano /etc/ssh/sshd_config` - > Add line `PrintLastLog no`. Default is yes. - > Save `Ctrl+O` and Exit `Ctrl+X` - > Restart sshd process `sudo systemctl restart sshd` + > Add: `PrintLastLog no` + > Save & Exit + > Restart sshd: `sudo systemctl restart sshd` # > **_NOTE:_** > Default motd is completely removed. Reconnect ssh session and if you followed the steps correctly you will not see any motd. # -#### ⮞ Implement New MOTD +#### ❯ Implement New MOTD * Copy `10-welcome`, `15-system` and `20-update` scripts from the latest release under `update-motd.d` dir to `/etc/update-motd.d` dir. Make sure scripts are under the ownership of root and are executable. > **Change ownership [If needed]:** @@ -99,7 +96,7 @@ Make sure scripts are under the ownership of root and are executable. > > `sudo run-parts /etc/update-motd.d` # -#### ⮞ Automation +#### ❯ Automation * 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. @@ -136,16 +133,16 @@ You can add switch -y to `sudo apt full-upgrade` command to bypass the yes/no pr # ### Scripts Info -#### ⮞ /etc/update-motd.d/10-welcome +#### ❯ /etc/update-motd.d/10-welcome > Displays the raspberry model, welcome user message, current timestamp and kernel version. -#### ⮞ /etc/update-motd.d/15-system +#### ❯ /etc/update-motd.d/15-system > 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. -#### ⮞ /etc/update-motd.d/20-update +#### ❯ /etc/update-motd.d/20-update > This static script displays available update count. It is generated by `/etc/update-motd-static.d/20-update`. -#### ⮞ /etc/update-motd-static.d/20-update +#### ❯ /etc/update-motd-static.d/20-update > 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. # From d6dd0605fec62e5ad69004e789dfe2c52c819f3c Mon Sep 17 00:00:00 2001 From: AA Date: Fri, 5 Jan 2024 13:40:19 -0500 Subject: [PATCH 3/8] Update README.md --- README.md | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/README.md b/README.md index 8216126..e09a2c9 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ Make sure scripts are under the ownership of root and are executable. #### ❯ Automation -* 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. +* We need to automate the process of finding pending OS update count. It is scheduled to run once a day at 8:00pm. You can change the time and frequency based on your preference. * **Systemd Timer** 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. @@ -112,17 +112,6 @@ Make sure scripts are under the ownership of root and are executable. > **List all timers [If needed]:** > `systemctl list-timers` - * **Cronjob** - Add cronjob for root crontab. If this is the first time you are creating a cronjob, it will ask for preferred editor. - > **Open crontab:** - > `sudo crontab -e` - > **Add cronjob:** - > Add below lines at the end of the crontab. Save and close the editor. - > ``` - > # MOTD - Update '20-update' file - Once A Day At 8:00PM - > 0 20 * * * run-parts /etc/update-motd-static.d - > ``` - * 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. * 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.** 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. 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. From a6a312ff54c01417d4330e7b5b569d1ce1209429 Mon Sep 17 00:00:00 2001 From: AA Date: Fri, 5 Jan 2024 13:44:47 -0500 Subject: [PATCH 4/8] Update README.md --- putty/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/putty/README.md b/putty/README.md index c7f0e34..9dff224 100644 --- a/putty/README.md +++ b/putty/README.md @@ -6,7 +6,7 @@ # ### Font * Fira Code Fixed Medium - 8 -![putty_font](https://user-images.githubusercontent.com/11185794/204076125-c5d28d71-f0ac-49de-9de9-7c549fd2aca3.png) +![putty_font](https://github.com/ar51an/raspberrypi-motd/assets/11185794/9d96aa33-605a-4dde-bd97-a7fd7da9a05c) # ### Character Set * UTF-8 should be enabled. From 3b929243b3cb734349f5c1e903eaa3807ba37775 Mon Sep 17 00:00:00 2001 From: AA Date: Fri, 5 Jan 2024 14:06:43 -0500 Subject: [PATCH 5/8] Update update.sh From 72d07d63c3e4a119d83c64e840b3df3ddc3a2f64 Mon Sep 17 00:00:00 2001 From: AA Date: Fri, 5 Jan 2024 14:07:52 -0500 Subject: [PATCH 6/8] Update 15-system --- update-motd.d/15-system | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/update-motd.d/15-system b/update-motd.d/15-system index 23c24e8..198fcd1 100644 --- a/update-motd.d/15-system +++ b/update-motd.d/15-system @@ -37,7 +37,7 @@ me=$(logname) # Last Login read loginIP loginDate <<< $(last $me --time-format iso -2 | awk 'NR==1 { print $3,$4 }') if [[ $loginDate == *T* ]]; then - login="$(date -d $loginDate +"%a %b %d %Y, %I:%M %p") $(color $dimInfoColor "» $loginIP")" + login="$(date -d $loginDate +"%a %b %d %Y, %I:%M %p") $(color $dimInfoColor "* $loginIP")" else # First Login login="None" @@ -45,31 +45,31 @@ fi # Stats label1="$login" -label1="$(color $statsLabelColor "Last") $(color $bulletColor "····")$(color $statsLabelColor "›") $(color $infoColor "$label1")" +label1="$(color $statsLabelColor "Last") $(color $bulletColor "....")$(color $statsLabelColor ".") $(color $infoColor "$label1")" label2="$(vcgencmd measure_temp | cut -c "6-9")°C" -label2="$(color $statsLabelColor "Temp") $(color $bulletColor "···")$(color $statsLabelColor "›") $(color $infoColor $label2)" +label2="$(color $statsLabelColor "Temp") $(color $bulletColor "...")$(color $statsLabelColor ".") $(color $infoColor $label2)" uptime="$(sec2time $(cut -d "." -f 1 /proc/uptime))" -uptime="$uptime $(color $dimInfoColor "» $(date -d "@"$(grep btime /proc/stat | cut -d " " -f 2) +"%m-%d-%y %H:%M")")" +uptime="$uptime $(color $dimInfoColor "* $(date -d "@"$(grep btime /proc/stat | cut -d " " -f 2) +"%m-%d-%y %H:%M")")" label3="$uptime" -label3="$(color $statsLabelColor "Uptime") $(color $bulletColor "··")$(color $statsLabelColor "›") $(color $infoColor "$label3")" +label3="$(color $statsLabelColor "Uptime") $(color $bulletColor "..")$(color $statsLabelColor ".") $(color $infoColor "$label3")" label4="$(awk -v a="$(awk '/cpu /{print $2+$3+$4+$5+$6+$7+$8+$9+$10,$5}' /proc/stat; sleep 0.3)" '/cpu /{split(a,b," "); printf "%.1f%%", 100*(($2+$3+$4+$5+$6+$7+$8+$9+$10-b[1])-($5-b[2]))/($2+$3+$4+$5+$6+$7+$8+$9+$10-b[1])}' /proc/stat)" -label4="$(color $statsLabelColor "Cpu") $(color $bulletColor "····")$(color $statsLabelColor "›") $(color $infoColor $label4)" +label4="$(color $statsLabelColor "Cpu") $(color $bulletColor "....")$(color $statsLabelColor ".") $(color $infoColor $label4)" -label5="$(df -h ~ | awk 'NR==2 { printf "%sB / %sB \\e[38;5;144m» Free: %sB\\e[0m",$3,$2,$4; }')" -label5="$(color $statsLabelColor "Disk") $(color $bulletColor "····")$(color $statsLabelColor "›") $(color $infoColor "$label5")" +label5="$(df -h ~ | awk 'NR==2 { printf "%sB / %sB \\e[38;5;144m* Free: %sB\\e[0m",$3,$2,$4; }')" +label5="$(color $statsLabelColor "Disk") $(color $bulletColor "....")$(color $statsLabelColor ".") $(color $infoColor "$label5")" label6="$(/bin/ls -d /proc/[0-9]* | wc -l)" -label6="$(color $statsLabelColor "Procs") $(color $bulletColor "··")$(color $statsLabelColor "›") $(color $infoColor $label6)" +label6="$(color $statsLabelColor "Procs") $(color $bulletColor "..")$(color $statsLabelColor ".") $(color $infoColor $label6)" -label7="$(free -h --si | awk 'NR==2 { printf "%sB / %sB \\e[38;5;144m» Free: %sB\\e[0m",$3,$2,$4; }')" -label7="$(color $statsLabelColor "Memory") $(color $bulletColor "··")$(color $statsLabelColor "›") $(color $infoColor "$label7")" +label7="$(free -h --si | awk 'NR==2 { printf "%sB / %sB \\e[38;5;144m* Free: %sB\\e[0m",$3,$2,$4; }')" +label7="$(color $statsLabelColor "Memory") $(color $bulletColor "..")$(color $statsLabelColor ".") $(color $infoColor "$label7")" label8="$(hostname -I)" -label8="$(color $statsLabelColor "IP") $(color $bulletColor "·····")$(color $statsLabelColor "›") $(color $infoColor $label8)" +label8="$(color $statsLabelColor "IP") $(color $bulletColor ".....")$(color $statsLabelColor ".") $(color $infoColor $label8)" # Print echo From df826c5b016f3d85b8df1ac1b5549135667e80fd Mon Sep 17 00:00:00 2001 From: AA Date: Fri, 5 Jan 2024 14:08:12 -0500 Subject: [PATCH 7/8] Update 10-welcome --- update-motd.d/10-welcome | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/update-motd.d/10-welcome b/update-motd.d/10-welcome index 2e00873..f69962a 100644 --- a/update-motd.d/10-welcome +++ b/update-motd.d/10-welcome @@ -29,11 +29,11 @@ deviceLabel=" $(color $deviceColor " $deviceName ")" # Greetings me="$(color $userColor " $me ")" codename="$(grep 'VERSION_CODENAME' /etc/os-release | cut -d '=' -f 2)" -greetings="$(color $greetingsColor " ⮞ Welcome »") $me $(color $greetingsColor To) $(color $codenameColor $codename)\n" -greetings="$greetings$(color $greetingsColor " ⮞ $(date +"%a %b %d %Y, %I:%M:%S %p")")\n" +greetings="$(color $greetingsColor " * Welcome") $me $(color $greetingsColor To) $(color $codenameColor $codename)\n" +greetings="$greetings$(color $greetingsColor " * $(date +"%a %b %d %Y, %I:%M:%S %p")")\n" # OS -greetings="$greetings$(color $greetingsColor " ⮞ $(uname -srm)")" +greetings="$greetings$(color $greetingsColor " * $(uname -srm)")" # Print echo -e "\n$deviceLabel" From 0e8794e7c7ca8585da5d1aa59e7f83abb589c7b6 Mon Sep 17 00:00:00 2001 From: AA Date: Fri, 5 Jan 2024 14:08:39 -0500 Subject: [PATCH 8/8] Update 20-update --- update-motd-static.d/20-update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update-motd-static.d/20-update b/update-motd-static.d/20-update index 73cb1c4..f7bd1cb 100644 --- a/update-motd-static.d/20-update +++ b/update-motd-static.d/20-update @@ -33,7 +33,7 @@ pkgCount="$(apt-get -s dist-upgrade | grep -Po '^\d+(?= upgraded)')" setCountColor "$pkgCount" # Message -msgHeader="$(color $msgColor ⮞)" +msgHeader="$(color $msgColor \*)" msgCount="$(color $countColor " $pkgCount ")" msgLabel="$(color $msgColor "$(msgFormat $pkgCount) can be upgraded")"