From 2a925904e447001e8eabfe096e5a3f197879a7e3 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 1 Sep 2023 15:42:29 -0400 Subject: [PATCH] Alter format of Debian version in MOTD --- roles/base/tasks/main.yml | 6 ++++++ roles/base/templates/usr/local/sbin/update-motd.sh.j2 | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/roles/base/tasks/main.yml b/roles/base/tasks/main.yml index 79333ee..de6e330 100644 --- a/roles/base/tasks/main.yml +++ b/roles/base/tasks/main.yml @@ -579,6 +579,7 @@ - { src: "usr/local/sbin/update-motd.sh.j2", dest: "/usr/local/sbin/update-motd.sh" } - { src: "etc/profile.d/w.sh.j2", dest: "/etc/profile.d/w.sh" } - { src: "etc/profile.d/pvc.sh.j2", dest: "/etc/profile.d/zzz_pvc.sh" } + register: profile_scripts tags: base-shell - name: install update-motd crontab @@ -596,6 +597,11 @@ state: absent tags: base-shell +- name: run update-motd on change + command: /usr/local/sbin/update-motd.sh + when: profile_scripts.changed + tags: base-shell + # htop - name: install htop configuration template: diff --git a/roles/base/templates/usr/local/sbin/update-motd.sh.j2 b/roles/base/templates/usr/local/sbin/update-motd.sh.j2 index 040c255..fc20285 100755 --- a/roles/base/templates/usr/local/sbin/update-motd.sh.j2 +++ b/roles/base/templates/usr/local/sbin/update-motd.sh.j2 @@ -5,9 +5,16 @@ set -o errexit +# Title-case generator +tc() { set ${*,,} ; echo ${*^} ; } + TMPFILE=$(mktemp) TGTFILE=/run/pvc-motd.dynamic -DEBVER="$( grep 'PRETTY_NAME=' /etc/os-release | awk -F'"' '{ print $2 }' )" + +NAME="$( grep '^NAME=' /etc/os-release | awk -F'"' '{ print $2 }' )" +VERSION_ID="$( grep '^VERSION_ID=' /etc/os-release | awk -F'"' '{ print $2 }' )" +VERSION_CODENAME="$( grep '^VERSION_CODENAME=' /etc/os-release | awk -F'=' '{ print $2 }' )" +DEBVER="${NAME} ${VERSION_ID} \"$(tc ${VERSION_CODENAME} )\"" echo >> $TMPFILE echo -e "\033[01;34mParallel Virtual Cluster \033[01;36m(${DEBVER})\033[0m" >> $TMPFILE