Add cache into updatemotd

This commit is contained in:
Dryusdan 2020-06-30 16:08:20 +02:00
parent 1bab619392
commit 4559e62189
8 changed files with 35 additions and 50 deletions

View File

@ -1,5 +1,6 @@
# Dynamic motd
The aim of this project is to give some informations when you log into a server through SSH.
Example:
@ -60,15 +61,11 @@ rm /etc/motd
ln -s /var/run/motd /etc/motd
```
## Salt
This is the for of [ldidry/dynamic-motd](https://github.com/ldidry/dynamic-motd)
You will find a working salt formula in `init.sls`.
```
cd /srv/salt
git clone https://framagit.org/luc/dynamic-motd.git motd
salt your_server state.sls motd
```
## Diffrence :
- Remove salt
- Add some cache to avoid a connection stuck during 30 secondes
## License

View File

@ -0,0 +1,11 @@
#!/bin/bash
. /etc/update-motd.d/colors
if [[ -x /usr/sbin/checkrestart ]]; then
n=$(/usr/sbin/checkrestart -p | grep "Found .* processes using old versions of upgraded files")
cat ${n} > /var/cache/motd-service-using-old-lib
elif [[ -x /usr/sbin/needrestart ]]; then
n=$(/usr/sbin/needrestart -l -v -n -r l 2>/dev/null | grep -c "Skipping")
cat ${n} > /var/cache/motd-service-need-restart
i

8
cron-scripts/motd-need-reboot Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
. /etc/update-motd.d/colors
if [[ -x /usr/sbin/needrestart ]]; then
n=$(DEBIAN_FRONTEND=noninteractive echo "" | /usr/sbin/needrestart -k -v -n 2>/dev/null | grep -c "Pending kernel upgrade\!")
cat ${n} > /var/cache/motd-needrestart
fi

6
cron-scripts/motd-need-upgrade Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
n=$(apt-get -qq --just-print dist-upgrade | cut -f 2 -d " " | sort -u | wc -l)
cat ${n} > /var/cache/cron-needupgrade
n=$(apt-get -qq --just-print autoremove | cut -f 2 -d " " | sort -u | wc -l)
cat ${n} > /var/cache/cron-needautoremove

View File

@ -1,37 +0,0 @@
motd-packages:
pkg.installed:
- pkgs:
- figlet
- lsb-release
- python-utmp
- bc
- debian-goodies
needrestart:
pkg.installed:
- pkgs:
- needrestart
symbolic-motd:
file.symlink:
- name: /etc/motd
- target: /var/run/motd
- force: True
- backupname: bak
dynamic-motd:
file.recurse:
- name: /etc/update-motd.d/
- source: salt://motd/update-motd.d/
- file_mode: 755
# If you installed this motd prior to commit 7bae3d50,
# you may want to enable the clean option in order to
# remove the old files (01-*, 02-*, etc) since they have
# been renumbered. Be careful! If you added some files of
# yours, they will be deleted
#- clean: True
remove-exec-colors:
file.managed:
- name: /etc/update-motd.d/colors
- mode: 644
remove-exec-sysinfo:
file.managed:
- name: /etc/update-motd.d/sysinfo.py
- mode: 644

View File

@ -2,13 +2,13 @@
. /etc/update-motd.d/colors
n=$(apt-get -qq --just-print dist-upgrade | cut -f 2 -d " " | sort -u | wc -l)
n=$(cat /var/cache/cron-needupgrade)
if [[ $n -gt 0 ]]; then
printf $LIGHT_RED
printf " You have %s packages waiting for upgrades." "$n"
printf $NONE"\n\n"
fi
n=$(apt-get -qq --just-print autoremove | cut -f 2 -d " " | sort -u | wc -l)
n=$(cat /var/cache/cron-needautoremove)
if [[ $n -gt 0 ]]; then
printf $YELLOW
printf " You have %s packages that were automatically installed and are not needed anymore." "$n"

View File

@ -3,7 +3,7 @@
. /etc/update-motd.d/colors
if [[ -x /usr/sbin/needrestart ]]; then
n=$(DEBIAN_FRONTEND=noninteractive echo "" | /usr/sbin/needrestart -k -v -n 2>/dev/null | grep -c "Pending kernel upgrade\!")
n=$(cat /var/cache/motd-needrestart)
if [[ $n -gt 0 ]]; then
printf $LIGHT_RED
printf " Pending kernel upgrade! "

View File

@ -3,7 +3,7 @@
. /etc/update-motd.d/colors
if [[ -x /usr/sbin/checkrestart ]]; then
n=$(/usr/sbin/checkrestart -p | grep "Found .* processes using old versions of upgraded files")
n=$(cat /var/cache/motd-service-using-old-lib)
re='Found (.*) processes using old versions of upgraded files'
if [[ $n =~ $re ]]; then
if [[ ${BASH_REMATCH[1]} -gt 0 ]]; then
@ -14,7 +14,7 @@ if [[ -x /usr/sbin/checkrestart ]]; then
fi
fi
elif [[ -x /usr/sbin/needrestart ]]; then
n=$(/usr/sbin/needrestart -l -v -n -r l 2>/dev/null | grep -c "Skipping")
n=$(cat /var/cache/motd-service-need-restart)
if [[ $n -gt 0 ]]; then
printf $LIGHT_RED
printf " %s services need to be restarted.\n" $n