From 4559e62189530d1113f8bde46cc82c9b3dcfec1e Mon Sep 17 00:00:00 2001 From: Dryusdan Date: Tue, 30 Jun 2020 16:08:20 +0200 Subject: [PATCH] Add cache into updatemotd --- README.md | 13 ++++----- cron-scripts/50-services-need-restart | 11 ++++++++ cron-scripts/motd-need-reboot | 8 ++++++ cron-scripts/motd-need-upgrade | 6 +++++ init.sls | 37 -------------------------- update-motd.d/30-need-upgrade | 4 +-- update-motd.d/40-need-reboot | 2 +- update-motd.d/50-services-need-restart | 4 +-- 8 files changed, 35 insertions(+), 50 deletions(-) create mode 100755 cron-scripts/50-services-need-restart create mode 100755 cron-scripts/motd-need-reboot create mode 100755 cron-scripts/motd-need-upgrade delete mode 100644 init.sls diff --git a/README.md b/README.md index a9595f6..93f378e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cron-scripts/50-services-need-restart b/cron-scripts/50-services-need-restart new file mode 100755 index 0000000..3b95372 --- /dev/null +++ b/cron-scripts/50-services-need-restart @@ -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 diff --git a/cron-scripts/motd-need-reboot b/cron-scripts/motd-need-reboot new file mode 100755 index 0000000..167cb3c --- /dev/null +++ b/cron-scripts/motd-need-reboot @@ -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 diff --git a/cron-scripts/motd-need-upgrade b/cron-scripts/motd-need-upgrade new file mode 100755 index 0000000..15a8b48 --- /dev/null +++ b/cron-scripts/motd-need-upgrade @@ -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 diff --git a/init.sls b/init.sls deleted file mode 100644 index 81597f5..0000000 --- a/init.sls +++ /dev/null @@ -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 diff --git a/update-motd.d/30-need-upgrade b/update-motd.d/30-need-upgrade index eab61bd..110a5a0 100755 --- a/update-motd.d/30-need-upgrade +++ b/update-motd.d/30-need-upgrade @@ -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" diff --git a/update-motd.d/40-need-reboot b/update-motd.d/40-need-reboot index 524e5db..5930c70 100755 --- a/update-motd.d/40-need-reboot +++ b/update-motd.d/40-need-reboot @@ -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! " diff --git a/update-motd.d/50-services-need-restart b/update-motd.d/50-services-need-restart index d70dc2f..31c4b80 100755 --- a/update-motd.d/50-services-need-restart +++ b/update-motd.d/50-services-need-restart @@ -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